2025-03-10 10:18:11 +08:00

105 lines
3.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZXK.UTility;
using DG.Tweening;
/*******************************************************************************
*Create By CG
*Function 在UI中的二级工序单项预制体
*******************************************************************************/
namespace ZXK.ZPS
{
public class UISecondItemCtrl : MonoBehaviour
{
[SerializeField]
private Text _nameTxt = null;
[SerializeField]
private Color _selectState = Color.white;
[SerializeField]
private Color _noSelectState = Color.white;
[MyReadOnly]
public bool _IsSecondSelectState = false;
private Transform _secondContainerParent = null;
private Transform _secondSelectContainerParent = null;
private DataItemModel _info = null;
/// <summary>
///
/// </summary>
/// <param name="itemInfo">当前二级工序数据模型</param>
/// <param name="secondProcessParent">界面选中后的二级工序集合地</param>
/// <param name="secondSelectContainerParent">界面备选区二级工序集合地</param>
public void InitItem(DataItemModel itemInfo,Transform secondProcessParent, Transform secondSelectContainerParent)
{
_info = itemInfo;
_secondContainerParent = secondProcessParent;
_secondSelectContainerParent = secondSelectContainerParent;
transform.name = _nameTxt.text = _info.SecondName.Trim();
SetLight();
GetComponent<Button>().onClick.AddListener(() =>
{
SetSelected();
GetComponent<Outline>().effectColor = new Color(1, 1, 1, 0);
DOTween.Kill("SecondItemHight");
});
}
private void SetSelected()
{
if (!_IsSecondSelectState)
{//之前未选中,改为选中
if(GameRoot.Instance._CurModel == EnumCtrl.Model.Train)
{
if(GameRoot.Instance._NextSecondProcess == transform.name)
{
GameRoot.Instance._CurSecondProcess = transform.name;
transform.SetParent(_secondContainerParent);
GetComponent<Image>().color = _selectState;
_IsSecondSelectState = true;
GameRoot.Instance._TrainMng.OpenProcess(_info);
}
}
else
{
GameRoot.Instance._CurSecondProcess = transform.name;
transform.SetParent(_secondContainerParent);
GetComponent<Image>().color = _selectState;
_IsSecondSelectState = true;
GameRoot.Instance._ExamMng.OpenProcess(_info);
}
}
//TODO 暂时不允许回头操作
//else
//{
// if (GameRoot.Instance._CurModel == EnumCtrl.Model.Exam)
// {//非考核状态不允许反向操作
// GameRoot.Instance._CurSecondProcess = null;
// transform.SetParent(_secondSelectContainerParent);
// GetComponent<Image>().color = _noSelectState;
// _IsSecondSelectState = false;
// //GameRoot.Instance._TrainMng.CloseProcess();
// }
//}
}
public void SetLight()
{
if (GameRoot.Instance._CurModel == EnumCtrl.Model.Train&&
GameRoot.Instance._NextSecondProcess==transform.name)
{
Outline btnHieght = GetComponent<Outline>();
DOTween.To(() => btnHieght.effectColor, x => btnHieght.effectColor = x, Color.white, 1.0f).SetLoops(-1, LoopType.Yoyo).SetId("SecondItemHight");
}
}
}
}