using System.Collections; using System.Collections.Generic; using UnityEngine; using XNode; //维修场景预制件管理器 用于规划维修步骤 管理维修步骤 public class RepairPrefabManager : MonoBehaviour { [Tooltip("步骤规划编辑器")] public NodeGraph Procress; [Tooltip("拆卸时终步骤节点")] public StepNode tearDownLastNode; [Tooltip("安装时终步骤节点")] public StepNode installLastNode; Dictionary> keyValues = new Dictionary>(); List stepRelations = new List(); // Start is called before the first frame update void Start() { for (int i = 0; i < Procress.nodes.Count; i++) { foreach (NodePort item in Procress.nodes[i].Outputs) { if (item.IsConnected) { string nodeName = (string)item.node.GetValue(null); if (keyValues.ContainsKey(nodeName)) { Debug.LogError($"存在重复的步骤名称{nodeName},跳过重复节点"); continue; } keyValues.Add(nodeName, new List()); List Connections = item.GetConnections();//获取当前节点 后续的所有节点 for (int j = 0; j < Connections.Count; j++) { string postpositionNodeName = (string)Connections[j].node.GetValue(null); keyValues[nodeName].Add(postpositionNodeName); stepRelations.Add(new StepRelation(nodeName, postpositionNodeName)); } } } }//梳理流程关系 ProcessManager.Instance.InitStepRelationDic(stepRelations, (string)tearDownLastNode.GetValue(null), (string)installLastNode.GetValue(null));//注入流程管理器 } //测试代码 private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { List unFinishedStep = ProcessManager.Instance.GetUnFinishedtep(); if (unFinishedStep.Count == 0) { Debug.Log("所有步骤都完成了!"); } else { for (int i = 0; i < unFinishedStep.Count; i++) { Debug.Log($"当前未完成步骤:{unFinishedStep[i]}"); } } } //if (Input.GetKeyDown(KeyCode.S)) //{ // ProcessManager.Instance.SetProcess(ProcessEnum.teardown); // ProcessManager.Instance.StartProcess(ProcessOver); //} } #if UNITY_EDITOR private void ProcessOver(ProcessEnum process) { Debug.LogWarning($"{process}流程结束"); switch (process) { case ProcessEnum.teardown://拆卸流程结束时 反转流程继续开始安装流程 Invoke("ResetProcress", 10f); break; case ProcessEnum.assemble: Debug.LogWarning($"安装流程结束,训练完成"); break; default: break; } } private void ResetProcress() { Debug.Log($"开始安装流程"); ProcessManager.Instance.SetProcess(ProcessEnum.assemble); ProcessManager.Instance.StartProcess(ProcessOver); } #endif }