AddEventTriggerEvent() public static method

Add Event to Unity's Event Trigger(Script)
public static AddEventTriggerEvent ( EventTrigger te, EventTriggerType type, EventTriggerEvent func ) : void
te EventTrigger
type EventTriggerType
func EventTriggerEvent
return void
Beispiel #1
0
        /* Functions */

        private void Start()
        {
            // Only need it for the UI.
            if (GetObjectType() == JCS_UnityObjectType.UI ||
                GetObjectType() == JCS_UnityObjectType.TEXT)
            {
                // Get panel root, in order to calculate the correct distance
                // base on the resolution.
                mPanelRoot = this.GetComponentInParent <JCS_PanelRoot>();

                if (mAutoAddEvent)
                {
                    // Event trigger is the must if we need to add the
                    // event to event trigger system.
                    {
                        this.mEventTrigger = this.GetComponent <EventTrigger>();
                        if (this.mEventTrigger == null)
                        {
                            this.mEventTrigger = this.gameObject.AddComponent <EventTrigger>();
                        }
                    }

                    JCS_Util.AddEventTriggerEvent(mEventTrigger, mActiveEventTriggerType, JCS_OnMouseOver);
                    JCS_Util.AddEventTriggerEvent(mEventTrigger, mDeactiveEventTriggerType, JCS_OnMouseExit);
                }
            }

            Vector3 currentScale = this.transform.localScale;

            // record down the scale.
            mRecordScale = currentScale;
            mTargetScale = currentScale;

            SetTargetScale();
        }
        /* Functions */

        private void Awake()
        {
            this.mEventTrigger = this.GetComponent <EventTrigger>();
            this.mButton       = this.GetComponent <Button>();
            this.mJCS_Button   = this.GetComponent <JCS_Button>();

            // Try find it.
            if (this.mText == null)
            {
                this.mText = this.GetComponentInChildren <Text>();
            }

            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerEnter,
                                          OnPointerEnter);
            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerExit,
                                          OnPointerExit);
            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerDown,
                                          OnPointerDown);
            JCS_Util.AddEventTriggerEvent(mEventTrigger,
                                          EventTriggerType.PointerUp,
                                          OnPointerUp);

            // Initialize the first color.
            if (IsButtonInteractable())
            {
                mText.color = mNormalColor;
            }
            else
            {
                mText.color = mDisabledColor;
            }
        }
Beispiel #3
0
        private void Start()
        {
            /*
             * NOTE(jenchieh): First get the sound player from its own
             * transform, if it still missing then grab the global sound
             * player.
             */
            if (mSoundPlayer == null)
            {
                mSoundPlayer = JCS_SoundManager.instance.GetGlobalSoundPlayer();
            }

            if (mAutoAddEvent)
            {
                JCS_Util.AddEventTriggerEvent(mEventTrigger, EventTriggerType.PointerEnter, JCS_OnMouseOver);
                JCS_Util.AddEventTriggerEvent(mEventTrigger, EventTriggerType.PointerEnter, JCS_OnMouseDoubleClick);
                JCS_Util.AddEventTriggerEvent(mEventTrigger, EventTriggerType.PointerExit, JCS_OnMouseExit);
                JCS_Util.AddEventTriggerEvent(mEventTrigger, EventTriggerType.PointerDown, JCS_OnMouseDown);
                JCS_Util.AddEventTriggerEvent(mEventTrigger, EventTriggerType.PointerUp, JCS_OnMouseUp);
                JCS_Util.AddEventTriggerEvent(mEventTrigger, EventTriggerType.PointerClick, JCS_OnMouseClick);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initalize all the button.
        /// </summary>
        private void InitBtnsSet()
        {
            if (mOkBtn != null)
            {
                mOkBtn.SetSystemCallback(OkBtnCallback);
            }

            if (mNoBtn != null)
            {
                mNoBtn.SetSystemCallback(NoBtnCallback);
            }

            if (mYesBtn != null)
            {
                mYesBtn.SetSystemCallback(YesBtnCallback);
            }

            if (mNextBtn != null)
            {
                mNextBtn.SetSystemCallback(NextBtnCallback);
            }

            if (mPreviousBtn != null)
            {
                mPreviousBtn.SetSystemCallback(PreviousBtnCallback);
            }

            if (mExitBtn != null)
            {
                mExitBtn.SetSystemCallback(ExitBtnCallback);
            }

            if (mAcceptBtn != null)
            {
                mAcceptBtn.SetSystemCallback(AcceptBtnCallback);
            }

            if (mDeclineBtn != null)
            {
                mDeclineBtn.SetSystemCallback(DeclineBtnCallback);
            }

            for (int index = 0; index < mSelectBtn.Length; ++index)
            {
                JCS_Button btn = mSelectBtn[index];

                if (btn == null)
                {
                    continue;
                }

                btn.SetSystemCallback(SelectionInt, index);

                if (mMakeHoverSelect)
                {
                    if (btn.ButtonSelection == null)
                    {
                        JCS_Debug.LogWarning(@"Cannot make hover select 
because button selection is not attach to all selections in the list...");
                    }
                    else
                    {
                        EventTrigger eventTrigger = btn.GetComponent <EventTrigger>();
                        if (eventTrigger == null)
                        {
                            eventTrigger = btn.gameObject.AddComponent <EventTrigger>();
                        }

                        JCS_Util.AddEventTriggerEvent(
                            eventTrigger,
                            EventTriggerType.PointerEnter,
                            mButtonSelectionGroup.SelectSelection,
                            btn.ButtonSelection);
                    }
                }
            }
        }
        private void Start()
        {
            // Only need it for the UI.
            if (GetObjectType() == JCS_UnityObjectType.UI ||
                GetObjectType() == JCS_UnityObjectType.TEXT)
            {
                // Get panel root, in order to calculate the
                // correct distance base on the resolution.
                mPanelRoot = this.GetComponentInParent <JCS_PanelRoot>();

                if (mAutoAddEvent)
                {
                    // Event trigger is the must if we need to add the
                    // event to event trigger system.
                    {
                        this.mEventTrigger = this.GetComponent <EventTrigger>();
                        if (this.mEventTrigger == null)
                        {
                            this.mEventTrigger = this.gameObject.AddComponent <EventTrigger>();
                        }
                    }

                    JCS_Util.AddEventTriggerEvent(mEventTrigger, mActiveEventTriggerType, JCS_OnMouseOver);
                    JCS_Util.AddEventTriggerEvent(mEventTrigger, mDeactiveEventTriggerType, JCS_OnMouseExit);
                }
            }

            Vector3 newPos = this.transform.localPosition;

            // record the original position
            this.mRecordPosition = newPos;
            this.mTargetPosition = newPos;

            switch (mAxis)
            {
            case JCS_Axis.AXIS_X:
            {
                // mPanelRoot will be null is the object isn't
                // UI game object.
                if (mPanelRoot != null)
                {
                    mDistance *= mPanelRoot.PanelDeltaWidthRatio;
                }

                newPos.x += mDistance;
            }
            break;

            case JCS_Axis.AXIS_Y:
            {
                // mPanelRoot will be null is the object isn't
                // UI game object.
                if (mPanelRoot != null)
                {
                    mDistance *= mPanelRoot.PanelDeltaHeightRatio;
                }

                newPos.y += mDistance;
            }
            break;

            case JCS_Axis.AXIS_Z:
            {
                newPos.z += mDistance;
            }
            break;
            }

            this.mTowardPosition = newPos;
        }