using UnityEngine; using UnityEngine.UI; using QFramework; using UnityEngine.EventSystems; namespace QFramework.Example { public class UIImageSelectMap_JiHeData : UIPanelData { public string DragItemName; public string TargetObj; public string ItemPath; } public partial class UIImageSelectMap_JiHe : UIPanel { protected override void OnInit(IUIData uiData = null) { TypeEventSystem.Global.Register(OnModuleQuit).UnRegisterWhenGameObjectDestroyed(gameObject); } ResLoader loader; protected override void OnOpen(IUIData uiData = null) { mData = uiData as UIImageSelectMap_JiHeData ?? new UIImageSelectMap_JiHeData(); loader = ResLoader.Allocate(); LeftContent.DestroyChildren(); uIImageDrag_JiHe = null; Frame1.DestroyChildren(); Frame2.DestroyChildren(); Frame1.GetComponent().color = Color.white; Frame2.GetComponent().color = Color.white; // Destory(Kuang1.gameObject.GetComponentInChildren()); string s = mData.DragItemName; // 生成单个物体 GameObject obj = GameObject.Instantiate(LeftItem, LeftContent.transform); obj.name = s; string path = Global.deviceIconsPath + mData.ItemPath; loader.Add2Load(path.ToNetImageResName(), (success, res) => { if (success) { obj.GetComponent().sprite = Utility.GetSprite(res.Asset as Texture2D); obj.GetComponentInChildren().text = s; } }); uIImageDrag_JiHe = obj.GetComponent(); CloseBtn.onClick.RemoveAllListeners(); CloseBtn.onClick.AddListener(() => { Hide(); }); loader.LoadAsync(); } public UIImageDrag_JiHe uIImageDrag_JiHe; protected override void OnShow() { } protected override void OnHide() { StringEventSystem.Global.Send("UIImageSelectMap_JiHe使用结束"); } protected override void OnClose() { } public void OnModuleQuit(OnModuleQuit arg) { Hide(); } } }