170 lines
5.1 KiB
C#
170 lines
5.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DataModel.Model;
|
|
using System.Linq;
|
|
using LitJson;
|
|
|
|
public class CheckPanelSubjectItem : MonoBehaviour
|
|
{
|
|
practicesubject practicesubject1;
|
|
List<practiceseat> practiceseats1;
|
|
|
|
/// <summary>
|
|
/// 科目管理的seatitem
|
|
/// </summary>
|
|
[HideInInspector]
|
|
public List<CheckPanelSeatItem> items;
|
|
/// <summary>
|
|
/// 本人选择的岗位
|
|
/// </summary>
|
|
[HideInInspector]
|
|
public CheckPanelSeatItem MyChose;
|
|
|
|
public Button self;
|
|
public Text Name;
|
|
/// <summary>
|
|
/// 未启动
|
|
/// </summary>
|
|
public Image state0;
|
|
/// <summary>
|
|
/// 进行中
|
|
/// </summary>
|
|
public Image state1;
|
|
/// <summary>
|
|
/// 已结束
|
|
/// </summary>
|
|
public Image state2;
|
|
|
|
public ToggleGroup toggleGroup;
|
|
public void Init(practicesubject practicesubject,int index)
|
|
{
|
|
practicesubject1 = practicesubject;
|
|
|
|
Name .text= practicesubject1.Name;
|
|
//if (practicesubject1.State==0)
|
|
//{
|
|
// state0.gameObject.SetActive(true);
|
|
// state1.gameObject.SetActive(false);
|
|
// state2.gameObject.SetActive(false);
|
|
//}
|
|
//else if (practicesubject1.State == 1)
|
|
//{
|
|
// state0.gameObject.SetActive(false);
|
|
// state1.gameObject.SetActive(true);
|
|
// state2.gameObject.SetActive(false);
|
|
//}
|
|
//else if (practicesubject1.State == 2)
|
|
//{
|
|
// state0.gameObject.SetActive(false);
|
|
// state1.gameObject.SetActive(false);
|
|
// state2.gameObject.SetActive(true);
|
|
//}
|
|
|
|
//获取所有practiceseat
|
|
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/Handler/Practice.ashx?action=querypracticeseat&PracticeSubjectId=" + practicesubject1.Id, str =>
|
|
{
|
|
var json = JsonMapper.ToObject<CallResultList<practiceseat>>(str);
|
|
if (json.state)
|
|
{
|
|
//生成岗位
|
|
practiceseats1 = json.data.OrderBy(a=>a.SeatNo).ToList();
|
|
items = new List<CheckPanelSeatItem>();
|
|
|
|
foreach (var item in practiceseats1)
|
|
{
|
|
GameObject obj = Instantiate<GameObject>(CheckPanel.instance.seatItemPrefb, CheckPanel.instance.seatGroup.transform);
|
|
CheckPanelSeatItem script = obj.GetComponent<CheckPanelSeatItem>();
|
|
items.Add(script);
|
|
script.Init(item, this);
|
|
if (index == 0)
|
|
{
|
|
obj.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
obj.SetActive(false);
|
|
}
|
|
}
|
|
|
|
//自己不能重复选择
|
|
if (practiceseats1.Any(a => !string.IsNullOrEmpty(a.UserAccount) && a.UserAccount == LoadManage.Instance.me.user.user_name))
|
|
{
|
|
items.ForEach(b =>
|
|
{
|
|
b.toggle.interactable = false;
|
|
});
|
|
}
|
|
|
|
//点击科目按钮
|
|
self.onClick.AddListener(() =>
|
|
{
|
|
ShowSeat();
|
|
ShowSuebjcet();
|
|
ChangeButtonState();
|
|
});
|
|
|
|
//默认显示第一个
|
|
if(index==0)
|
|
{
|
|
ShowSuebjcet();
|
|
transform.GetComponent<Image>().sprite = CheckPanel.instance.选中sprite;
|
|
}
|
|
else
|
|
{
|
|
transform.GetComponent<Image>().sprite = CheckPanel.instance.未选中sprite;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError(json.message);
|
|
}
|
|
}));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换seat
|
|
/// </summary>
|
|
public void ShowSeat()
|
|
{
|
|
CheckPanel.instance.seatGroup.transform.GetComponentsInChildren<CheckPanelSeatItem>(true).ToList().ForEach(a =>
|
|
{
|
|
if(a.practiceseat1.Field_Char1== practicesubject1.Id)
|
|
{
|
|
a.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
a.gameObject.SetActive(false);
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换subject
|
|
/// </summary>
|
|
public void ShowSuebjcet()
|
|
{
|
|
CheckPanel.instance.subejctText.text = practicesubject1.Name;
|
|
CheckPanel.instance.训练方式Text.text = practicesubject1.OperateModel;
|
|
CheckPanel.instance.操作流程Text.text = practicesubject1.OperateProcess;
|
|
}
|
|
|
|
private void ChangeButtonState()
|
|
{
|
|
CheckPanel.instance.subjectGroup.transform.GetComponentsInChildren<CheckPanelSubjectItem>(true).ToList().ForEach(a =>
|
|
{
|
|
if (a == this)
|
|
{
|
|
a.transform.GetComponent<Image>().sprite = CheckPanel.instance.选中sprite;
|
|
}
|
|
else
|
|
{
|
|
a.transform.GetComponent<Image>().sprite = CheckPanel.instance.未选中sprite;
|
|
}
|
|
});
|
|
}
|
|
}
|