1118OPSSNew/Assets/Zion/Scripts/指挥界面/ReceiveCommand.cs

125 lines
4.7 KiB
C#

using DataModel.Model;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ReceiveCommand : MonoBehaviour
{
public static ReceiveCommand instance;
/// <summary>
/// 步骤父物体
/// </summary>
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;
}
}
}
}
/// <summary>
/// 初始化步骤
/// </summary>
/// <param name="subjectname"></param>
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>().text = items.Name;
steplink.GetComponent<ReceiveStepObj>().currentStep = items;
steplink.GetComponent<ReceiveStepObj>().InitState();
foreach (var item in LoadManage.Instance.pseats)
{
if (item.SeatId.Equals(items.SeatId))
{
steplink.transform.Find("frame/manipulator").GetComponent<Text>().text = item.SeatName;
}
}
break;
case "分组":
GameObject stepGroup = Instantiate(Resources.Load("Prefabs/ReceiveCommand/GroupItem") as GameObject, stepParent);
stepGroup.transform.Find("content").GetComponent<Text>().text = items.Name;
stepGroup.GetComponent<ReceiveStepObj>().currentStep = items;
stepGroup.GetComponent<ReceiveStepObj>().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>().text = item.Name;
foreach (var seatitem in LoadManage.Instance.pseats)
{
if (seatitem.SeatId.Equals(item.SeatId))
{
step.transform.Find("frame/manipulator").GetComponent<Text>().text = seatitem.SeatName;
}
}
}
}
break;
default:
break;
}
}
}
}
public void ChangeState(practicesubjectstep step)
{
foreach (var items in stepParent.GetComponentsInChildren<ReceiveStepObj>())
{
if (items.currentStep.ID.Equals(step.ID))
{
string spritename = items.transform.Find("state").GetComponent<Image>().sprite.name;
switch (spritename)
{
case "未开始":
items.transform.Find("state").GetComponent<Image>().sprite = items.sprites[1];
break;
case "进行中":
items.transform.Find("state").GetComponent<Image>().sprite = items.sprites[2];
break;
default:
break;
}
}
}
}
}