using DataModel.Model; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ReceiveCommand : MonoBehaviour { public static ReceiveCommand instance; /// /// 步骤父物体 /// public Transform stepParent; private practicesubjectstep[] steps; public void Init() { instance = this; if (LoadManage.Instance.currentPracticeSubejct != null) InitStep(LoadManage.Instance.currentPracticeSubejct.Id); } public void DistroyItem() { for (int i = 0; i < stepParent.childCount; i++) { Destroy(stepParent.GetChild(i).gameObject); } } private void BubblrSort() { steps = LoadManage.Instance.psteps.ToArray(); practicesubjectstep temp = null; for (int i = 0; i < steps.Length - 1; i++) { for (int j = 0; j < steps.Length - 1 - i; j++) { if (steps[j].OrderIndex > steps[j + 1].OrderIndex) { temp = steps[j + 1]; steps[j + 1] = steps[j]; steps[j] = temp; } } } } /// /// 初始化步骤 /// /// public void InitStep(string subjectname) { DistroyItem(); BubblrSort(); foreach (var items in steps) { if (items.PracticeSubjectId.Equals(subjectname)) { switch (items.StepType) { case "环节": GameObject steplink = Instantiate(Resources.Load("Prefabs/ReceiveCommand/StepItem") as GameObject, stepParent); steplink.transform.Find("content").GetComponent().text = items.Name; steplink.GetComponent().currentStep = items; steplink.GetComponent().InitState(); foreach (var item in LoadManage.Instance.pseats) { if (item.SeatId.Equals(items.SeatId)) { steplink.transform.Find("frame/manipulator").GetComponent().text = item.SeatName; } } break; case "分组": GameObject stepGroup = Instantiate(Resources.Load("Prefabs/ReceiveCommand/GroupItem") as GameObject, stepParent); stepGroup.transform.Find("content").GetComponent().text = items.Name; stepGroup.GetComponent().currentStep = items; stepGroup.GetComponent().InitState(); foreach (var item in LoadManage.Instance.psteps) { if (item.GroupId.Equals(items.ID)) { GameObject step = Instantiate(Resources.Load("Prefabs/ReceiveCommand/LinkItem") as GameObject, stepParent); step.transform.Find("content").GetComponent().text = item.Name; foreach (var seatitem in LoadManage.Instance.pseats) { if (seatitem.SeatId.Equals(item.SeatId)) { step.transform.Find("frame/manipulator").GetComponent().text = seatitem.SeatName; } } } } break; default: break; } } } } public void ChangeState(practicesubjectstep step) { foreach (var items in stepParent.GetComponentsInChildren()) { if (items.currentStep.ID.Equals(step.ID)) { string spritename = items.transform.Find("state").GetComponent().sprite.name; switch (spritename) { case "未开始": items.transform.Find("state").GetComponent().sprite = items.sprites[1]; break; case "进行中": items.transform.Find("state").GetComponent().sprite = items.sprites[2]; break; default: break; } } } } }