501 lines
17 KiB
C#
501 lines
17 KiB
C#
using DataModel.Model;
|
|
using LitJson;
|
|
using System;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 指挥面板
|
|
/// </summary>
|
|
public class CommandPanel : MonoBehaviour
|
|
{
|
|
public static CommandPanel Instance;
|
|
/// <summary>
|
|
/// 开始当前科目
|
|
/// </summary>
|
|
public bool startCurrentSubject = false;
|
|
/// <summary>
|
|
/// 完成当前科目
|
|
/// </summary>
|
|
public bool endCurrentSubject = false;
|
|
/// <summary>
|
|
/// 步骤父物体
|
|
/// </summary>
|
|
public Transform stepParent;
|
|
/// <summary>
|
|
/// 科目父物体
|
|
/// </summary>
|
|
public Transform subjectParent;
|
|
/// <summary>
|
|
/// 开始科目按钮
|
|
/// </summary>
|
|
public Button btn_Active;
|
|
/// <summary>
|
|
/// 结束科目按钮
|
|
/// </summary>
|
|
public Button btn_Completed;
|
|
|
|
|
|
/// <summary>
|
|
/// 当前选中科目
|
|
/// </summary>
|
|
public practicesubject currentPsubjects;
|
|
public practicesubject startPsubjects;
|
|
/// <summary>
|
|
/// 当前选中科目步骤
|
|
/// </summary>
|
|
public practicesubjectstep currentPstep;
|
|
/// <summary>
|
|
/// 当前选择步骤按钮
|
|
/// </summary>
|
|
private Button currentBtn;
|
|
private int clickCount = 0;
|
|
|
|
private practicesubjectstep[] steps;
|
|
private practicesubject[] subjects;
|
|
|
|
|
|
public FunctionSync_Active[] getOn;
|
|
public FunctionSync_Active[] getOff;
|
|
|
|
/// <summary>
|
|
/// 科目启停回调
|
|
/// </summary>
|
|
/// <param name="str1"></param>
|
|
/// <param name="str2"></param>
|
|
/// <param name="str3"></param>
|
|
/// <param name="ison"></param>
|
|
public void SetSubject(string practiceId, string praticeSubjectId, string subjectName, bool ison)
|
|
{
|
|
TipsManager.instance.ShowSubjectTip(subjectName, ison);
|
|
if (ison)
|
|
{
|
|
startCurrentSubject = true;
|
|
btn_Active.interactable = false;
|
|
ReceiveCommand.instance.InitStep(praticeSubjectId);
|
|
if (subjectName == "转载下车前准备")
|
|
{
|
|
SetThreshold.instance.DismantleWeiZhuangWang();
|
|
for (int i = 0; i < getOn.Length; i++)
|
|
{
|
|
getOn[i].DisShowObject();
|
|
}
|
|
for (int i = 0; i < getOff.Length; i++)
|
|
{
|
|
getOff[i].ShowObject();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
btn_Completed.interactable = false;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 步骤启停回调
|
|
/// </summary>
|
|
/// <param name="str1"></param>
|
|
/// <param name="str2"></param>
|
|
/// <param name="str3"></param>
|
|
/// <param name="str4"></param>
|
|
/// <param name="ison"></param>
|
|
public void SetStep(string practiceId, string praticeSubjectId, string subjectName, string pratciesubjectstepId, bool ison)
|
|
{
|
|
practiceseat seat = LoadManage.Instance.myPracticeSeat.Find(a => a.SeatNo == "0");
|
|
|
|
if (seat != null)
|
|
{
|
|
CurrentStepObj currentStepObj = currentBtn.GetComponentInParent<CurrentStepObj>();
|
|
string spritename = currentBtn.GetComponent<Image>().sprite.name;
|
|
switch (spritename)
|
|
{
|
|
case "未开始":
|
|
currentBtn.transform.GetComponent<Image>().sprite = currentStepObj.sprites[1];
|
|
break;
|
|
case "进行中":
|
|
currentBtn.transform.GetComponent<Image>().sprite = currentStepObj.sprites[2];
|
|
currentBtn.interactable = false;
|
|
clickCount++;
|
|
currentStepObj.isCheckButton = true;
|
|
break;
|
|
default:
|
|
|
|
break;
|
|
}
|
|
}
|
|
if (ison) TipsManager.instance.ShowStepsTip(pratciesubjectstepId);
|
|
foreach (var item in LoadManage.Instance.psteps)
|
|
{
|
|
if (item.ID.Equals(pratciesubjectstepId))
|
|
{
|
|
ReceiveCommand.instance.ChangeState(item);
|
|
}
|
|
}
|
|
|
|
practicesubjectstep p = LoadManage.Instance.psteps.Find(a => a.ID == pratciesubjectstepId);
|
|
if (p.Name.Equals("安装伪装网"))
|
|
{
|
|
SetThreshold.instance.InstallWeiZhaungWang();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动二维软件
|
|
/// </summary>
|
|
public void StartSoft()
|
|
{
|
|
SoftManage.Instance.StartSoft(currentPsubjects.Id, currentPsubjects.Name, SoftManage.Instance.softName, LoadManage.Instance.currentPracticeSeat.UserAccount, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取数据
|
|
/// </summary>
|
|
public void ChargeData()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
public void Init()
|
|
{
|
|
Instance = this;
|
|
GameManage.Instance.SetSubjectAction(SetSubject);
|
|
GameManage.Instance.SetStepAction(SetStep);
|
|
InitSubject();
|
|
if (subjectParent.childCount > 0)
|
|
{
|
|
subjectParent.GetChild(0).GetComponent<Button>().onClick.Invoke();
|
|
}
|
|
}
|
|
private void SubjectBubblrSort()
|
|
{
|
|
subjects = LoadManage.Instance.psubjects.ToArray();
|
|
practicesubject temp = null;
|
|
for (int i = 0; i < subjects.Length - 1; i++)
|
|
{
|
|
for (int j = 0; j < subjects.Length - 1 - i; j++)
|
|
{
|
|
if (subjects[j].OrderIndex > subjects[j + 1].OrderIndex)
|
|
{
|
|
temp = subjects[j + 1];
|
|
subjects[j + 1] = subjects[j];
|
|
subjects[j] = temp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化科目
|
|
/// </summary>
|
|
public void InitSubject()
|
|
{
|
|
GameObject itemprefab = Resources.Load("Prefabs/CommandPlane/SubjectItemPrefab") as GameObject;
|
|
|
|
for (int i = 0; i < subjectParent.childCount; i++)
|
|
{
|
|
if (subjectParent.childCount < 1) return;
|
|
Destroy(subjectParent.GetChild(i).gameObject);
|
|
}
|
|
|
|
SubjectBubblrSort();
|
|
|
|
|
|
foreach (var items in subjects)
|
|
{
|
|
for (int i = 0; i < LoadManage.Instance.myPracticeSeat.Count; i++)
|
|
{
|
|
if (LoadManage.Instance.myPracticeSeat[i].SeatNo.Equals("0"))
|
|
{
|
|
if (LoadManage.Instance.myPracticeSeat[i].Field_Char1.Equals(items.Id))
|
|
{
|
|
GameObject subject = Instantiate(itemprefab, subjectParent);
|
|
subject.name = items.Name;
|
|
subject.GetComponentInChildren<Text>().text = items.Name;
|
|
subject.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
currentPsubjects = items;
|
|
subject.GetComponent<CurrentSubjectObj>().Btn_State();
|
|
switch (items.State)
|
|
{
|
|
case -1:
|
|
startCurrentSubject = false;
|
|
endCurrentSubject = false;
|
|
btn_Active.interactable = true;
|
|
btn_Completed.interactable = true;
|
|
break;
|
|
case 0:
|
|
startCurrentSubject = true;
|
|
endCurrentSubject = false;
|
|
btn_Active.interactable = false;
|
|
btn_Completed.interactable = true;
|
|
break;
|
|
case 1:
|
|
startCurrentSubject = true;
|
|
btn_Active.interactable = false;
|
|
btn_Completed.interactable = false;
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
InitStep(items.Id);
|
|
|
|
//SoftManage.Instance.ChangeSoftSubject(items.PracticeId, items.Name , SoftManage.Instance.softName, items.UseSeats, LoadManage.Instance.me.user_id);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 清空步骤
|
|
/// </summary>
|
|
public void DistroyStepItem()
|
|
{
|
|
for (int i = 0; i < stepParent.childCount; i++)
|
|
{
|
|
Destroy(stepParent.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 生成步骤前排序
|
|
/// </summary>
|
|
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)
|
|
{
|
|
DistroyStepItem();
|
|
BubblrSort();
|
|
foreach (var items in steps)
|
|
{
|
|
if (items.PracticeSubjectId.Equals(subjectname))
|
|
{
|
|
switch (items.StepType)
|
|
{
|
|
case "环节":
|
|
GameObject steplink = Instantiate(Resources.Load("Prefabs/CommandPlane/StepItemPrefab") as GameObject, stepParent);
|
|
steplink.transform.Find("content").GetComponent<Text>().text = items.Name;
|
|
steplink.GetComponent<CurrentStepObj>().currentStep = items;
|
|
steplink.GetComponent<CurrentStepObj>().InitButtonState();
|
|
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/CommandPlane/GroupPrefab") as GameObject, stepParent);
|
|
stepGroup.transform.Find("content").GetComponent<Text>().text = items.Name;
|
|
stepGroup.GetComponent<CurrentStepObj>().currentStep = items;
|
|
stepGroup.GetComponent<CurrentStepObj>().InitButtonState();
|
|
foreach (var item in LoadManage.Instance.psteps)
|
|
{
|
|
if (item.GroupId.Equals(items.ID))
|
|
{
|
|
GameObject step = Instantiate(Resources.Load("Prefabs/CommandPlane/LinkPrefab") 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;
|
|
}
|
|
|
|
}
|
|
}
|
|
Invoke("CheckButtonSort", 1);
|
|
}
|
|
/// <summary>
|
|
/// 点击按钮排序
|
|
/// </summary>
|
|
public void CheckButtonSort()
|
|
{
|
|
CurrentStepObj[] stepObjs = stepParent.GetComponentsInChildren<CurrentStepObj>();
|
|
clickCount = 0;
|
|
int tempCount = 0;
|
|
for (int i = clickCount; i < stepObjs.Length; i++)
|
|
{
|
|
if (!stepObjs[i].isCheckButton)
|
|
{
|
|
tempCount++;
|
|
stepObjs[i].SetId(tempCount);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < stepObjs.Length; i++)
|
|
{
|
|
int j = i;
|
|
Button button = stepObjs[j].GetComponentInChildren<Button>();
|
|
button.GetComponentInChildren<Button>().onClick.AddListener(() =>
|
|
{
|
|
if (stepObjs[j].id != clickCount + 1 || !startCurrentSubject) return;
|
|
|
|
if (!stepObjs[j].isCheckButton)
|
|
{
|
|
//stepObjs[j].audioSource.clip = stepObjs[j].audioClip;
|
|
stepObjs[j].audioSource.PlayOneShot(stepObjs[j].audioClip);
|
|
currentPstep = stepObjs[j].currentStep;
|
|
currentBtn = button;
|
|
string spritename = button.GetComponent<Image>().sprite.name;
|
|
switch (spritename)
|
|
{
|
|
case "未开始":
|
|
SetStepState(0);
|
|
break;
|
|
case "进行中":
|
|
SetStepState(1);
|
|
if (currentPstep.OrderIndex.Equals(GetEndSubject())) endCurrentSubject = true;
|
|
break;
|
|
default:
|
|
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
public int GetEndSubject()
|
|
{
|
|
int stepIndex = 0;
|
|
foreach (var item in steps)
|
|
{
|
|
if (item.PracticeSubjectId.Equals(currentPsubjects.Id))
|
|
{
|
|
switch (item.StepType)
|
|
{
|
|
case "分组环节":
|
|
break;
|
|
default:
|
|
stepIndex = item.OrderIndex;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return stepIndex;
|
|
}
|
|
public void SetSubjectState(int state)
|
|
{
|
|
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/Handler/Practice.ashx?action=updatepracticesubjectstate&practicesubjectId=" + currentPsubjects.Id + "&State=" + state, str =>
|
|
{
|
|
CallResultObject back = JsonMapper.ToObject<CallResultObject>(str);
|
|
if (back.state)
|
|
{
|
|
SubjectChange(currentPsubjects.PracticeId, currentPsubjects.Id, currentPsubjects.Name, state == 0 ? true : false);
|
|
}
|
|
}));
|
|
}
|
|
public void SetStepState(int state)
|
|
{
|
|
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/Handler/Practice.ashx?action=updatepracticesubjectstepstate&practicesubjectstepId=" + currentPstep.ID + "&StepState=" + state, str =>
|
|
{
|
|
CallResultObject back = JsonMapper.ToObject<CallResultObject>(str);
|
|
|
|
if (back.state)
|
|
{
|
|
StepChange(currentPstep.PracticeId, currentPstep.PracticeSubjectId, currentPsubjects.Name, currentPstep.ID, state == 0 ? true : false);
|
|
}
|
|
}));
|
|
}
|
|
/// <summary>
|
|
/// 开关科目
|
|
/// </summary>
|
|
/// <param name="practiceId"></param>
|
|
/// <param name="subjectid"></param>
|
|
/// <param name="subjectName"></param>
|
|
/// <param name="OpenOrClose"></param>
|
|
private void SubjectChange(string practiceId, string praticeSubjectId, string subjectName, bool OpenOrClose)
|
|
{
|
|
//参数
|
|
byte[] gra = Encoding.UTF8.GetBytes(practiceId + "," + praticeSubjectId + "," + subjectName + "," + (OpenOrClose ? "开" : "关"));
|
|
|
|
byte[] data = new byte[4 + gra.Length];
|
|
Array.Copy(BitConverter.GetBytes(gra.Length), 0, data, 0, 4);
|
|
Array.Copy(gra, 0, data, 4, gra.Length);
|
|
MyNetMQClient.instance.Send(LoadManage.Instance.currentRoomArea, 40, data);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开关步骤
|
|
/// </summary>
|
|
/// <param name="practiceId"></param>
|
|
/// <param name="praticeSubjectId"></param>
|
|
/// <param name="subjectName"></param>
|
|
/// <param name="pratciesubjectstrpId"></param>
|
|
/// <param name="OpenOrClose"></param>
|
|
private void StepChange(string practiceId, string praticeSubjectId, string subjectName, string pratciesubjectstrpId, bool OpenOrClose)
|
|
{
|
|
//参数
|
|
byte[] gra = Encoding.UTF8.GetBytes(practiceId + "," + praticeSubjectId + "," + subjectName + "," + pratciesubjectstrpId + "," + (OpenOrClose ? "开" : "关"));
|
|
|
|
byte[] data = new byte[4 + gra.Length];
|
|
Array.Copy(BitConverter.GetBytes(gra.Length), 0, data, 0, 4);
|
|
Array.Copy(gra, 0, data, 4, gra.Length);
|
|
MyNetMQClient.instance.Send(LoadManage.Instance.currentRoomArea, 50, data);
|
|
|
|
}
|
|
/// <summary>
|
|
/// 启动科目
|
|
/// </summary>
|
|
public void StartSub()
|
|
{
|
|
if (LoadManage.Instance.currentPracticeSubejct == null || currentPsubjects.OrderIndex.Equals(LoadManage.Instance.currentPracticeSubejct.OrderIndex))
|
|
SetSubjectState(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭科目
|
|
/// </summary>
|
|
public void EndSub()
|
|
{
|
|
if (endCurrentSubject)
|
|
{
|
|
SetSubjectState(1);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 刷新科目
|
|
/// </summary>
|
|
public void RefreshSub(Button active, Button completed)
|
|
{
|
|
startCurrentSubject = false;
|
|
endCurrentSubject = false;
|
|
active.interactable = true;
|
|
completed.interactable = true;
|
|
}
|
|
}
|