2025-02-12 08:43:33 +08:00

135 lines
5.1 KiB
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZXK.Framework;
/*******************************************************************************
*Create By CG
*Function 设备认知数据处理
*******************************************************************************/
namespace ZXK.BYSS
{
public class CognizePanel : UIBase
{
protected override void Awake()
{
base.Awake();
}
private void Start()
{
Transform nameItemParent = GetWedage("Content_N").transform;
GameObject nameItemPrefab = nameItemParent.Find("EquipmentNameItemPrefab").gameObject;
//初始化数据
List<EquipmentInfo> equipArray = AppManagement.Instance._CognizeData._EquipmentData[
UTility.EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)];
for (int i = 0; i < equipArray.Count; i++)
{
GameObject modelItem = Instantiate(nameItemPrefab, nameItemParent);
modelItem.transform.name = equipArray[i]._ModelID;
modelItem.GetComponentInChildren<Text>().text = equipArray[i]._ModelName;
modelItem.SetActive(true);
Toggle modelTog = modelItem.transform.GetComponent<Toggle>();
modelTog.onValueChanged.AddListener((isOn) =>
{
if (isOn)
{
EquipmentInfo temp = EquipmentInfo.Default;
List<EquipmentInfo> tempArray = AppManagement.Instance._CognizeData._EquipmentData[
UTility.EnumCtrl.GetEnumDescription(AppManagement.Instance._CurType)];
for (int a = 0; a < tempArray.Count; a++)
{
if (equipArray[a]._ModelID.Equals(modelTog.transform.name))
{
temp = equipArray[a];
}
}
ClickEquipmentArgs args = new()
{
info =temp,
};
EventCenterManager.Instance.Dispatch(EventEnum.ClickEquipment, this, args);
Toggle[] togChildrens = nameItemParent.GetComponentsInChildren<Toggle>();
for (int i = 0; i < togChildrens.Length; i++)
{
//添加toggleGroup
togChildrens[i].group = GetWedage("Content_N").transform.GetComponent<ToggleGroup>();
if (!togChildrens[i].name.Equals(modelTog.name))
{
// Debug.Log(togChildrens[i].name+"名字是???");
togChildrens[i].isOn = false;
}
}
}
});
}
GetWedage("Content_N").transform.GetComponentInChildren<Toggle>().isOn = true;
//目录伸缩控制
AddEventListener("CatalogStretchTog_N", UIEventType.OnToggleValueChanged, (isOn) =>
{
if (isOn)
{
GetWedage("CatalogScrollView_N").GetComponent<RectTransform>().DOAnchorPosX(10.0f, 0.5f);
}
else
{
GetWedage("CatalogScrollView_N").GetComponent<RectTransform>().DOAnchorPosX(-200.0f, 0.5f);
}
});
//说明伸缩控制
AddEventListener("ExplainStretchTog_N", UIEventType.OnToggleValueChanged, (isOn) =>
{
if (isOn)
{
GetWedage("ExplainView_N").GetComponent<RectTransform>().DOAnchorPosX(-10.0f, 0.5f);
}
else
{
GetWedage("ExplainView_N").GetComponent<RectTransform>().DOAnchorPosX(300.0f, 0.5f);
}
});
//一键拆卸
AddEventListener("SplitBtn_N", UIEventType.OnButtonClick, () =>
{
EventCenterManager.Instance.Dispatch(EventEnum.SplitEquipment, this, null);
});
//一键合成
AddEventListener("CombineBtn_N", UIEventType.OnButtonClick, () =>
{
EventCenterManager.Instance.Dispatch(EventEnum.CombineEquipment, this, null);
});
}
/// <summary>
/// 显示选中物体信息
/// </summary>
/// <param name="equipmentExplain"></param>
public void ShowEquipment(string equipmentExplain,string equipmentName)
{
SetText("ExplainContent_N", equipmentExplain);
SetText("ModelNameTxt_N", equipmentName);
}
protected override void OnDestroy()
{
base.OnDestroy();
}
}
}