using UnityEngine; using UnityEngine.UI; using QFramework; using System.Collections.Generic; using TMPro; using System.Linq; using DG.Tweening; using static OperationController; namespace QFramework.Example { public class UIToolsData : UIPanelData { public List devices; public string answer; public bool SetActive = true; public string rightLable; public string wrongLabel; public string rightEvent; public string wrongEvent; public float rightScore; public float wrongScore; public string scoreStepName; } public partial class UITools : UIPanel { ResLoader mResLoader; public List answers; protected override void OnInit(IUIData uiData = null) { mData = uiData as UIToolsData ?? new UIToolsData(); // please add init code here TypeEventSystem.Global.Register(OnStepChanged); } private void OnStepChanged(StepStatusOnChange change) { Hide(); } protected override void OnOpen(IUIData uiData = null) { TypeEventSystem.Global.Register(OnModuleQuit).UnRegisterWhenDisabled(gameObject); mResLoader = ResLoader.Allocate(); mData = uiData as UIToolsData ?? new UIToolsData(); if (string.IsNullOrEmpty(mData.answer) == false) { answers = mData.answer.Split(',')?.ToList(); } Content.RemoveAllChildren(); foreach (var device in mData.devices) { var item = DeviceController.Instance.GetDevice(device); if (item==null) { Debug.LogError(device + ":没有找到对应的Device配置"); return; } GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content); obj.name = item.Name; obj.transform.Find("Name").GetComponent().text = item.Name; Image icon = obj.transform.Find("Icon").GetComponent(); var localImageUrl = Global.deviceIconsPath + item.Icon; GameObject right = icon.transform.Find("Right").gameObject; GameObject wrong = icon.transform.Find("Wrong").gameObject; GameObject Selected = icon.transform.Find("Selected").gameObject; GameObject CurSelect = obj.transform.Find("CurSelect").gameObject; mResLoader.Add2Load(localImageUrl.ToNetImageResName(), (bool success, IRes res) => { if (success) { icon.sprite = Utility.GetSprite(res.Asset as Texture2D); } }); Button btn = obj.GetComponent