Beispiel #1
0
        public void UpEvent(UIWidget middle, UIWidget target)
        {
            if (middle == null || target == null)
            {
                return;
            }

            RemoveEvent(middle);

            UIEventTrigger  middleET       = middle.GetComponent <UIEventTrigger>();
            UIEventListener middleListener = middle.GetComponent <UIEventListener>();

            bool isFind = false;

            if (middleET != null && target.GetComponent <UIButton>() != null)
            {
                UIButton widgetBtn = target.GetComponent <UIButton>();

                middleET.onClick.Add(new EventDelegate(() =>
                {
                    if (widgetBtn.OnClickAction != null)
                    {
                        widgetBtn.OnClickAction();
                    }
                }));
                middleET.onDragOut.Add(new EventDelegate(() =>
                {
                    if (widgetBtn.OnDragOutAction != null)
                    {
                        widgetBtn.OnDragOutAction();
                    }
                }));
                middleET.onDragOver.Add(new EventDelegate(() =>
                {
                    if (widgetBtn.OnDragOverAction != null)
                    {
                        widgetBtn.OnDragOverAction();
                    }
                }));
                middleET.onPress.Add(new EventDelegate(() =>
                {
                    if (widgetBtn.OnPressAction != null)
                    {
                        widgetBtn.OnPressAction(true);
                    }
                }));
                middleET.onRelease.Add(new EventDelegate(() =>
                {
                    if (widgetBtn.OnPressAction != null)
                    {
                        widgetBtn.OnPressAction(false);
                    }
                }));
                isFind = true;
            }

            if (middleET != null && target.GetComponent <UIEventTrigger>() != null)
            {
                UIEventTrigger targetET = target.GetComponent <UIEventTrigger>();
                if (targetET.onClick != null)
                {
                    middleET.onClick.AddRange(targetET.onClick);
                }
                if (targetET.onDrag != null)
                {
                    middleET.onDrag.AddRange(targetET.onDrag);
                }
                if (targetET.onDragOut != null)
                {
                    middleET.onDragOut.AddRange(targetET.onDragOut);
                }
                if (targetET.onDragOver != null)
                {
                    middleET.onDragOver.AddRange(targetET.onDragOver);
                }
                if (targetET.onHoverOut != null)
                {
                    middleET.onHoverOut.AddRange(targetET.onHoverOut);
                }
                if (targetET.onHoverOver != null)
                {
                    middleET.onHoverOver.AddRange(targetET.onHoverOver);
                }
                if (targetET.onPress != null)
                {
                    middleET.onPress.AddRange(targetET.onPress);
                }
                if (targetET.onRelease != null)
                {
                    middleET.onRelease.AddRange(targetET.onRelease);
                }
                if (targetET.onDeselect != null)
                {
                    middleET.onDeselect.AddRange(targetET.onDeselect);
                }
                if (targetET.onDoubleClick != null)
                {
                    middleET.onDoubleClick.AddRange(targetET.onDoubleClick);
                }
                if (targetET.onDragStart != null)
                {
                    middleET.onDragStart.AddRange(targetET.onDragStart);
                }
                if (targetET.onDragEnd != null)
                {
                    middleET.onDragEnd.AddRange(targetET.onDragEnd);
                }

                isFind = true;
            }

            if (middleListener != null && target.GetComponent <UIEventListener>() != null)
            {
                UIEventListener targetListener = target.GetComponent <UIEventListener>();
                if (targetListener.onDrag != null)
                {
                    middleListener.onDrag = new UIEventListener.VectorDelegate((GameObject go, Vector2 d) => { targetListener.onDrag(go, d); });
                }
                if (targetListener.onClick != null)
                {
                    middleListener.onClick = new UIEventListener.VoidDelegate((GameObject go) => { targetListener.onClick(go); });
                }
                if (targetListener.onDoubleClick != null)
                {
                    middleListener.onDoubleClick = new UIEventListener.VoidDelegate((GameObject go) => { targetListener.onDoubleClick(go); });
                }
                if (targetListener.onDragEnd != null)
                {
                    middleListener.onDragEnd = new UIEventListener.VoidDelegate((GameObject go) => { targetListener.onDragEnd(go); });
                }
                if (targetListener.onDragOut != null)
                {
                    middleListener.onDragOut = new UIEventListener.VoidDelegate((GameObject go) => { targetListener.onDragOut(go); });
                }
                if (targetListener.onDragOver != null)
                {
                    middleListener.onDragOver = new UIEventListener.VoidDelegate((GameObject go) => { targetListener.onDragOver(go); });
                }
                if (targetListener.onDragStart != null)
                {
                    middleListener.onDragStart = new UIEventListener.VoidDelegate((GameObject go) => { targetListener.onDragStart(go); });
                }
                if (targetListener.onDrop != null)
                {
                    middleListener.onDrop = new UIEventListener.ObjectDelegate((GameObject go, GameObject obj) => { targetListener.onDrop(go, obj); });
                }
                if (targetListener.onHover != null)
                {
                    middleListener.onHover = new UIEventListener.BoolDelegate((GameObject go, bool obj) => { targetListener.onHover(go, obj); });
                }
                if (targetListener.onKey != null)
                {
                    middleListener.onKey = new UIEventListener.KeyCodeDelegate((GameObject go, KeyCode obj) => { targetListener.onKey(go, obj); });
                }
                if (targetListener.onPress != null)
                {
                    middleListener.onPress = new UIEventListener.BoolDelegate((GameObject go, bool obj) => { targetListener.onPress(go, obj); });
                }
                if (targetListener.onScroll != null)
                {
                    middleListener.onScroll = new UIEventListener.FloatDelegate((GameObject go, float obj) => { targetListener.onScroll(go, obj); });
                }
                if (targetListener.onSelect != null)
                {
                    middleListener.onSelect = new UIEventListener.BoolDelegate((GameObject go, bool obj) => { targetListener.onSelect(go, obj); });
                }
                if (targetListener.onSubmit != null)
                {
                    middleListener.onSubmit = new UIEventListener.VoidDelegate((GameObject go) => { targetListener.onSubmit(go); });
                }
                isFind = true;
            }

            if (middleET != null && target.GetComponent <ConsecutiveClickCoolTrigger>() != null)
            {
                ConsecutiveClickCoolTrigger ccct = target.GetComponent <ConsecutiveClickCoolTrigger>();

                if (ccct.enabled)
                {
                    middleET.onClick.Add(new EventDelegate(() => { if (ccct != null)
                                                                   {
                                                                       ccct.OnClick();
                                                                   }
                                                           }));
                }

                isFind = true;
            }

            if (middleET != null && target.GetComponent <ContinueClickCDTrigger>() != null)
            {
                ContinueClickCDTrigger cdCom = target.GetComponent <ContinueClickCDTrigger>();

                if (cdCom.enabled)
                {
                    middleET.onClick.Add(new EventDelegate(() =>
                    {
                        if (cdCom != null)
                        {
                            cdCom.OnPress(true);
                        }
                    }));
                }

                isFind = true;
            }

            if (isFind)
            {
                middle.gameObject.GetComponent <Collider>().enabled = true;
            }
        }