void OnSGPushStarted(SGPushStartedEvent gesture)
        {
            sGPushStartedEvent   = gesture;
            gesture.Listener     = gameObject;
            gesture.Description += gameObject.name;
            log.InfoMS($"<Color=magenta>\n{gesture.Description}</Color>");

            SetFrame(0);
            animatorTimeline.Play("Pressed", 0, 0);
            SetTimelineSpeed(0);
        }
Ejemplo n.º 2
0
        protected override void OnDisable()
        {
            if (linkedObject != null)
            {
                linkedObject.InteractableObjectUsed   -= InteractableObjectUsed;
                linkedObject.InteractableObjectUnused -= InteractableObjectUnused;
            }

            SGPushStartedEvent.UnregisterListener(OnSGPushStarted);
            SGPushEndedEvent.UnregisterListener(OnSGPushEnded);
            base.InstantClearState();
            base.OnDisable();
        }
        //-----------------------------------------------------------------
        //	                                USED
        //-----------------------------------------------------------------
        protected virtual void InteractableObjectUsed(object sender, InteractableObjectEventArgs e)
        {
            isUsed = true;

            SGPushStartedEvent.RegisterListener(OnSGPushStarted);
            SGPushChangedEvent.RegisterListener(OnSGPushChanged);
            SGPushEndedEvent.RegisterListener(OnSGPushEnded);

            controller = e.interactingObject.transform;

            //log.InfoMS("Controller: " + controller.name);
            //log.InfoMS("Button: " + gameObject.name);//(sender as GameObject).name);
            //log.InfoMS("<Color=red>\n+++Used+++</Color>");



            atEnd = false;
        }
        //-----------------------------------------------------------------
        //                                NOT USED
        //-----------------------------------------------------------------
        protected virtual void InteractableObjectUnused(object sender, InteractableObjectEventArgs e)
        {
            if (isUsed && sGPushStartedEvent.HasFired)
            {
                OnSGPushCanceled();
            }

            isUsed = false;

            SGPushStartedEvent.UnregisterListener(OnSGPushStarted);
            SGPushChangedEvent.UnregisterListener(OnSGPushChanged);
            SGPushEndedEvent.UnregisterListener(OnSGPushEnded);

            //log.InfoMS("<Color=blue>\n---Unused---</Color>");
            frameOffset = currentFrame;
            if (rewindOnRelease)
            {
                RewindAnimation();
            }
            SetTimelineSpeed(1);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Additional methods can be called here during button state changes. e.g. play a sound.
        /// The listeners for the Skeleton Gestures are managed here.
        /// </summary>
        /// <param name="state">the standard button selection states.</param>
        /// <param name="instant">will use fade tiem or transition instantly.</param>
        protected override void DoStateTransition(SelectionState state, bool instant)
        {
            //log.InfoMS($"<Color=cyan>state transition </Color> <b>{state}</b> <Color=cyan>of </Color><Color=green>{gameObject.name}</Color>");

            switch (state)
            {
            case SelectionState.Normal:
                SGPushStartedEvent.UnregisterListener(OnSGPushStarted);
                SGPushEndedEvent.UnregisterListener(OnSGPushEnded);
                break;

            case SelectionState.Highlighted:
                SGPushStartedEvent.RegisterListener(OnSGPushStarted);
                break;

            case SelectionState.Pressed:
                SGPushStartedEvent.UnregisterListener(OnSGPushStarted);
                SGPushEndedEvent.RegisterListener(OnSGPushEnded);
                break;

            case SelectionState.Selected:
                break;

            case SelectionState.Disabled:
                SGPushStartedEvent.UnregisterListener(OnSGPushStarted);
                SGPushEndedEvent.UnregisterListener(OnSGPushEnded);
                break;

            default:
                SGPushStartedEvent.UnregisterListener(OnSGPushStarted);
                SGPushEndedEvent.UnregisterListener(OnSGPushEnded);
                break;
            }

            base.DoStateTransition(state, instant);
        }
Ejemplo n.º 6
0
        // Update is called once per frame
        void FixedUpdate()
        {
            // TODO: @msaw - limit the distance to character facing direction.
            pushDistance = Vector3.Distance(bones.rightUpperArm.position, bones.rightHand.position); // distance between shoulder and hand.


            ////Calculate the normalized float;
            //NormalizedPushDistance = (pushDistance - min) / (max - min);
            ////Clamp the pushDistance float between "min" value and "max" value
            //pushDistance = Mathf.Clamp(pushDistance, min, max);
            ////Clamp the normalized float between 0 and 1
            //NormalizedPushDistance = Mathf.Clamp(NormalizedPushDistance, 0, 1);

            // TODO: @msaw - check what the Remap really outputs
            NormalizedPushDistance = ExtensionMethods.Remap(pushDistance, min, max, 0.00f, 1.00f);

            if (pushStartedEvent != null && pushChangedEvent != null && pushEndedEvent != null)
            {
                if (!pushStartedEvent.HasFired && NormalizedPushDistance <= 0 && bones.rightUpperArm.rotation.z > 0.6f)
                {
                    // pushStartedEvent Args
                    pushStartedEvent.Description = gameObject.name + " started Push on ";
                    pushStartedEvent.Sender      = gameObject;

                    pushStartedEvent.FireEvent();

                    pushChangedEvent.ResetEvent();
                    pushEndedEvent.ResetEvent();

                    message = "Started the Push";
                }
                // (check if the start event has a listener - to only limit the action to buttons)
                if (pushStartedEvent.HasFired && NormalizedPushDistance > 0 && NormalizedPushDistance < 1 && bones.rightUpperArm.rotation.z > 0.6f)
                {
                    pushChangedEvent.Description = gameObject.name + $" performing {NormalizedPushDistance * 100:F0}% Push on ";
                    pushChangedEvent.Sender      = gameObject;
                    //only perform a push if we are still on the same object, otherwise reset the push start event

                    // did the start event get a listener object?
                    // did the changed event get a listener object?
                    if (pushStartedEvent.Listener != null && pushChangedEvent.Listener != null)
                    {
                        // get  the changed listener
                        // ...
                        if (pushStartedEvent.Listener.GetHashCode() == pushChangedEvent.Listener.GetHashCode())
                        {
                            // the start listener matches the change listener -> perform the push
                            pushChangedEvent.PushDistance = NormalizedPushDistance;
                            pushChangedEvent.FireEvent(true);
                            Debug.Log("Mark 002");
                        }
                        else
                        {
                            // the start listener is different for the change listener -> reset the change event
                            pushStartedEvent.ResetEvent();
                            pushChangedEvent.ResetEvent();
                            pushChangedEvent.FireEvent();
                            Debug.Log("Mark 003"); // code wont reach here anymore because of the start event control in the Listener
                        }
                    }
                    // did the start event get a listener object? -> run the change event once to get a listener
                    else if (pushStartedEvent.Listener != null && pushChangedEvent.Listener == null)
                    {
                        pushChangedEvent.ResetEvent();
                        pushChangedEvent.FireEvent();
                        Debug.Log("Mark 001");
                    }
                    // the start event has no lister -> reset the start event
                    else
                    {
                        pushStartedEvent.ResetEvent();
                        Debug.Log("Mark 000");
                    }

                    message  = $"Pushing {(NormalizedPushDistance * 100):F0}%\n";
                    message += $"rotationX {(bones.rightUpperArm.rotation.x):F3}\n";
                    message += $"rotationZ {(bones.rightUpperArm.rotation.z):F3}\n";
                }
                if (pushStartedEvent.HasFired && pushChangedEvent.HasFired && NormalizedPushDistance >= 1 && bones.rightUpperArm.rotation.z > 0.6f)
                {
                    if (!pushEndedEvent.HasFired)
                    {
                        // pushEndedEvent Args
                        pushEndedEvent.Description = gameObject.name + " ended Push on ";
                        pushEndedEvent.Sender      = gameObject;

                        pushEndedEvent.FireEvent();

                        pushChangedEvent.ResetEvent();
                        pushStartedEvent.ResetEvent();
                    }

                    message  = $"rotationX {(bones.rightUpperArm.rotation.x):F3}\n";
                    message += $"rotationZ {(bones.rightUpperArm.rotation.z):F3}\n";
                }
                else
                {
                    message = "";
                }
            }
            else
            {
                pushStartedEvent = new SGPushStartedEvent();
                pushChangedEvent = new SGPushChangedEvent();
                pushEndedEvent   = new SGPushEndedEvent();
            }
        }
Ejemplo n.º 7
0
        /*
         * public void OnTriggerExits(ColliderEventData eventData)
         * {
         *
         *  //StopCoroutine(DeleayedSelection());
         *  this.StopAllCoroutines();
         *  events.onTriggerExits.Invoke(eventData);
         *
         *  if (debug)
         *      log.InfoMS("Trigger exit");
         *  //  @msaw - the normal state should be used when the button is not in use instead of exit trigger to avoid jtter
         *  DoStateTransition(SelectionState.Normal, true);
         * }
         *
         * public void OnTriggerEnters(ColliderEventData eventData)
         * {
         *  //DoStateTransition(currentSelectionState, false);
         *  //DoStateTransition(SelectionState.Highlighted, false);
         *  StartCoroutine(DeleayedSelection(eventData));
         *  events.onTriggerEnters.Invoke(eventData);
         *
         *
         *  if (debug)
         *      log.InfoMS("Trigger enter");
         *  log.InfoMS(eventData.Controller.name + " touched " + eventData.Collider.name);
         * }
         */
        #endregion

        #region Skeleton Gesture Methods

        void OnSGPushStarted(SGPushStartedEvent gesture)
        {
            log.InfoMS($"<Color=blue>{gameObject.name} button recived push started</Color>");

            DoStateTransition(SelectionState.Pressed, true);
        }