private void RegisterEnableEvents(IUILoadCtrl loadCtrl, ItemInfoBase trigger)
        {
            UnityAction onEnableAction = () =>
            {
                loadCtrl.GetGameObjectInfo(trigger);
            };

            trigger.OnCreate = (x) =>
            {
                trigger.instence = x;
                IPanelEnable irm = x.GetComponent <IPanelEnable>();
                if (irm != null)
                {
                    onEnable -= onEnableAction;

                    irm.OnDelete += () =>
                    {
                        onEnable += onEnableAction;
                    };
                }
                else
                {
                    onDisable += () =>
                    {
                        if (trigger.instence != null && trigger.instence is GameObject)
                        {
                            Destroy((GameObject)trigger.instence);
                        }
                    };
                }
                RegisterDestoryAction(trigger.assetName, x);
            };

            onEnable += onEnableAction;
        }
        private void RegisterButtonEvents(IUILoadCtrl loadCtrl, ItemInfoBase trigger)
        {
            UnityAction CreateByButton = () =>
            {
                loadCtrl.GetGameObjectInfo(trigger);
            };

            trigger.button.onClick.AddListener(CreateByButton);
            onDestroy       += () => { trigger.button.onClick.RemoveAllListeners(); };
            trigger.OnCreate = (x) =>
            {
                IPanelButton ib = x.GetComponent <IPanelButton>();
                if (ib != null)
                {
                    ib.Btn = trigger.button;
                    trigger.button.onClick.RemoveListener(CreateByButton);

                    ib.OnDelete += () =>
                    {
                        trigger.button.onClick.AddListener(CreateByButton);
                    };
                }
                RegisterDestoryAction(trigger.assetName, x);
            };
        }
        private void RegisterBundleEvents(IUILoadCtrl loadCtrl, List <ItemInfoBase> bundles)
        {
            for (int i = 0; i < bundles.Count; i++)
            {
                ItemInfoBase trigger = bundles[i];
                switch (trigger.type)
                {
                case UIBundleInfo.Type.Button:
                    RegisterButtonEvents(loadCtrl, trigger);
                    break;

                case UIBundleInfo.Type.Toggle:
                    RegisterToggleEvents(loadCtrl, trigger);
                    break;

                case UIBundleInfo.Type.Name:
                    RegisterMessageEvents(loadCtrl, trigger);
                    break;

                case UIBundleInfo.Type.Enable:
                    RegisterEnableEvents(loadCtrl, trigger);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 4
0
        private void RegisterMessageEvents(IUILoadCtrl loadCtrl, ItemInfoBase trigger)
        {
            UnityAction <object> createAction = (x) =>
            {
                trigger.dataQueue.Enqueue(x);//
                loadCtrl.GetGameObjectInfo(trigger);
            };

            UnityAction <object> handInfoAction = (data) =>
            {
                IPanelName irm = trigger.instence.GetComponent <IPanelName>();
                irm.HandleData(data);
            };

            trigger.OnCreate = (x) =>
            {
                IPanelName irm = x.GetComponent <IPanelName>();
                if (irm != null)
                {
                    trigger.instence = x;
                    eventHold.Remove(trigger.assetName, createAction);
                    eventHold.Record(trigger.assetName, handInfoAction);
                    irm.onDelete += () =>
                    {
                        trigger.instence = null;
                        eventHold.Remove(trigger.assetName, handInfoAction);
                        eventHold.Record(trigger.assetName, createAction);
                    };
                    irm.onCallBack += (state) =>
                    {
                        InvokeCallBack(trigger.assetName, state);
                    };

                    while (trigger.dataQueue.Count > 0)
                    {
                        var data = trigger.dataQueue.Dequeue();
                        irm.HandleData(data);
                    }
                }
                RegisterHideAndDestroyAction(trigger.assetName, x);
            };

            eventHold.Record(trigger.assetName, createAction);

            onDestroy += () =>
            {
                eventHold.Remove(trigger.assetName, createAction);
            };
        }
        private void RegisterToggleEvents(IUILoadCtrl loadCtrl, ItemInfoBase trigger)
        {
            UnityAction <bool> CreateByToggle = (x) =>
            {
                if (x)
                {
                    trigger.toggle.interactable = false;
                    loadCtrl.GetGameObjectInfo(trigger);
                }
                else
                {
                    Destroy((GameObject)trigger.instence);
                }
            };

            trigger.toggle.onValueChanged.AddListener(CreateByToggle);

            onDestroy += () =>
            {
                trigger.toggle.onValueChanged.RemoveAllListeners();
            };

            trigger.OnCreate = (x) =>
            {
                trigger.toggle.interactable = true;

                trigger.instence = x;
                IPanelToggle it = x.GetComponent <IPanelToggle>();
                if (it != null)
                {
                    it.toggle = trigger.toggle;

                    trigger.toggle.onValueChanged.RemoveListener(CreateByToggle);

                    it.OnDelete += () =>
                    {
                        trigger.toggle.onValueChanged.AddListener(CreateByToggle);
                    };
                }
                RegisterDestoryAction(trigger.assetName, x);
            };
        }