//TODO: @msaw - when the gesture is canceled the animation could be rewinded void OnSGPushCanceled() { sGPushStartedEvent.ResetEvent(); sGPushStartedEvent.Description = (sGPushStartedEvent.Listener == null ? gameObject.name : sGPushStartedEvent.Listener.name) + " Cancelled the Push from " + (sGPushStartedEvent.Sender == null ? "" : sGPushStartedEvent.Sender.name); log.InfoMS($"<Color=red>\n{sGPushStartedEvent.Description}</Color>"); }
// 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(); } }