void OnSGPushChanged(SGPushChangedEvent gesture)
 {
     // |<-        +---+  O
     gesture.Listener     = gameObject;
     gesture.Description += gameObject.name;
     log.InfoMS($"<Color=yellow>\n{gesture.Description}</Color> Frame: {gesture.PushDistance}");
     SetFrame(gesture.PushDistance);
 }
        //-----------------------------------------------------------------
        //	                                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);
        }
Exemplo n.º 4
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();
            }
        }