using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using XFramework.Objects; //正式操作开始前的步骤规划提示面板 //创建步骤元素 管理未规划和已规划的元素及相关数据 返回规划完成的数据 public class FixStepWindowCtrl : MonoBehaviour { public GameObject childPrefab;//节点预制件 //左侧父节点 public Transform unPlanningStepsParent; Dictionary unPlanningSteps = new Dictionary();//左侧物体节点 和对应的数据 //右侧父节点 public Transform PlannedStepsParent; Dictionary PlannedSteps = new Dictionary();//右侧物体节点 List rightSteps = new List();//完成规划的数据 按照进入存储 UnityAction> planningOverEvent;//规划完成事件 string currentStepName;//当前阶段的名称 public Button button_sure;//完成规划 private void Start() { button_sure.onClick.AddListener(ButtonSure); } //隐藏窗口 public void Hide() { this.gameObject.SetActive(false); } //显示窗口 注入数据 public void ActiveWindow(List steps,UnityAction> overEvent) { this.gameObject.SetActive(true); planningOverEvent = overEvent; for (int i = 0; i < steps.Count; i++) { GameObject newStepGO = ObjectPool.Instance.Instantiate(childPrefab, unPlanningStepsParent); newStepGO.transform.localScale = Vector3.one; newStepGO.GetComponent().InjectInitData(steps[i].describe, StepClickOn, StepType.unPlanning); unPlanningSteps.Add(newStepGO, steps[i]); } } //某个步骤按钮被点击时 移动位置 并记录相关数据 public void StepClickOn(StepButtonCtrl stepButton) { //左侧的按钮点击了 移动到右侧 标记为完成规划 if (stepButton.Type == StepType.unPlanning) { stepButton.transform.SetParent(PlannedStepsParent); stepButton.Type = StepType.Planned; PlannedSteps.Add(stepButton.gameObject, unPlanningSteps[stepButton.gameObject]); rightSteps.Add(unPlanningSteps[stepButton.gameObject]); unPlanningSteps.Remove(stepButton.gameObject); } else//右侧按钮点击了 移动到左侧 标记为未完成规划 { stepButton.transform.SetParent(unPlanningStepsParent); stepButton.Type = StepType.unPlanning; unPlanningSteps.Add(stepButton.gameObject, PlannedSteps[stepButton.gameObject]); rightSteps.Remove(PlannedSteps[stepButton.gameObject]); PlannedSteps.Remove(stepButton.gameObject); } } //按下提交按钮时评估是否正确 正确时结束规划 清空本界面 错误时不做处理 void ButtonSure() { EditorAppraiser editorAppraiser = new EditorAppraiser(); string error = editorAppraiser.AppraiseSteps(rightSteps); if (string.IsNullOrEmpty(error))//规划的步骤正确 { planningOverEvent?.Invoke(rightSteps); Clear(); this.gameObject.SetActive(false); } else { Debug.Log("提示规划步骤有误,不做其他处理"); } } //清空界面和相关数据 void Clear() { foreach (var item in unPlanningSteps) { ObjectPool.Instance.Destroy(item.Key); } unPlanningSteps.Clear(); foreach (var item in PlannedSteps) { ObjectPool.Instance.Destroy(item.Key); } PlannedSteps.Clear(); rightSteps.Clear(); } } public enum StepType { //未规划的 unPlanning, //规划完成的 Planned, }