Esempio n. 1
0
        protected virtual void OnEnable()
        {
            hideFlags = HideFlags.HideAndDontSave;

            instance = target as Gesture;

            advanced = serializedObject.FindProperty("advancedProps");
            friendlyGestures = serializedObject.FindProperty("friendlyGestures");
            requireGestureToFail = serializedObject.FindProperty("requireGestureToFail");
            combineTouches = serializedObject.FindProperty("combineTouches");
            combineTouchesInterval = serializedObject.FindProperty("combineTouchesInterval");
            useSendMessage = serializedObject.FindProperty("useSendMessage");
            sendMessageTarget = serializedObject.FindProperty("sendMessageTarget");
            sendStateChangeMessages = serializedObject.FindProperty("sendStateChangeMessages");

            friendlyGesturesList = new ReorderableList(serializedObject, friendlyGestures, false, false, false, true);
            friendlyGesturesList.headerHeight = 0;
            friendlyGesturesList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                var gesture = friendlyGestures.GetArrayElementAtIndex(index).objectReferenceValue as Gesture;
                if (gesture == null)
                {
                    // Killing null elements.
                    indexToRemove = index;
                    EditorGUI.LabelField(rect, GUIContent.none);
                    return;
                }
                EditorGUI.LabelField(rect, string.Format("{0} @ {1}", gesture.GetType().Name, gesture.name), GUIElements.BoxLabelStyle);
            };
            friendlyGesturesList.onRemoveCallback += list => { indexToRemove = list.index; };
        }
        public override void OnEnter()
        {
            gesture = GestureUtils.GetGesture<Gesture>(Fsm, GameObject, Gesture, Component, false);
            if (gesture == null)
            {
                LogError("Gesture is missing");
                return;
            }

            gesture.StateChanged += gestureStateChangedHandler;
        }
Esempio n. 3
0
        private void addFriendlyGesture(SerializedProperty prop, Gesture value)
        {
            if (value == null || value == target) return;

            addGesture(prop, value);

            var so = new SerializedObject(value);
            so.Update();
            SerializedProperty p = so.FindProperty(FRIENDLY_GESTURES_PROP);
            p.arraySize++;
            p.GetArrayElementAtIndex(p.arraySize - 1).objectReferenceValue = target;

            so.ApplyModifiedProperties();
            EditorUtility.SetDirty(value);
        }
Esempio n. 4
0
        public override void OnEnter()
        {
            gesture = GestureUtils.GetGesture<Gesture>(Fsm, GameObject, Gesture, Component, false);
            if (gesture == null)
            {
                LogError("Gesture is missing");
                return;
            }

            ITouchHit hit;
            gesture.GetTargetHitResult(out hit);
            var hit3d = hit as ITouchHit3D;
            if (hit3d == null) return;

            if (Collider != null) Collider.Value = hit3d.Collider;
            if (RigidBody != null) RigidBody.Value = hit3d.Rigidbody;
            if (Normal != null) Normal.Value = hit3d.Normal;
            if (Point != null) Point.Value = hit3d.Point;

            Finish();
        }
Esempio n. 5
0
        {
            get; private set;
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Determines whether this instance can prevent the specified gesture.
        /// </summary>
        /// <param name="gesture">The gesture.</param>
        /// <returns>
 private bool shouldBegin(Gesture gesture)
 {
     bool result = true;
     if (GlobalGestureDelegate != null) result = GlobalGestureDelegate.ShouldBegin(gesture);
     return result && gesture.ShouldBegin();
 }
 private void failGesture(Gesture gesture)
 {
     gesture.INTERNAL_SetState(Gesture.GestureState.Failed);
 }
 private bool gestureIsActive(Gesture gesture)
 {
     if (gesture.gameObject.activeInHierarchy == false) return false;
     if (gesture.enabled == false) return false;
     switch (gesture.State)
     {
         case Gesture.GestureState.Failed:
         case Gesture.GestureState.Recognized:
         case Gesture.GestureState.Cancelled:
             return false;
         default:
             return true;
     }
 }
 private void doUpdateEnded(Gesture gesture, TouchPoint touch)
 {
     gesture.INTERNAL_TouchEnded(touch);
 }
Esempio n. 10
0
        internal Gesture.GestureState INTERNAL_GestureChangeState(Gesture gesture, Gesture.GestureState state)
        {
            bool recognized = false;
            switch (state)
            {
                case Gesture.GestureState.Possible:
                    break;
                case Gesture.GestureState.Began:
                    switch (gesture.State)
                    {
                        case Gesture.GestureState.Possible:
                            break;
                        default:
                            print(String.Format("Gesture {0} erroneously tried to enter state {1} from state {2}",
                                new object[] {gesture, state, gesture.State}));
                            break;
                    }
                    recognized = recognizeGestureIfNotPrevented(gesture);
                    if (!recognized)
                    {
                        if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                        return Gesture.GestureState.Failed;
                    }
                    break;
                case Gesture.GestureState.Changed:
                    switch (gesture.State)
                    {
                        case Gesture.GestureState.Began:
                        case Gesture.GestureState.Changed:
                            break;
                        default:
                            print(String.Format("Gesture {0} erroneously tried to enter state {1} from state {2}",
                                new object[] {gesture, state, gesture.State}));
                            break;
                    }
                    break;
                case Gesture.GestureState.Failed:
                    if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                    break;
                case Gesture.GestureState.Recognized: // Ended
                    if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                    switch (gesture.State)
                    {
                        case Gesture.GestureState.Possible:
                            recognized = recognizeGestureIfNotPrevented(gesture);
                            if (!recognized)
                            {
                                return Gesture.GestureState.Failed;
                            }
                            break;
                        case Gesture.GestureState.Began:
                        case Gesture.GestureState.Changed:
                            break;
                        default:
                            print(string.Format("Gesture {0} erroneously tried to enter state {1} from state {2}",
                                new object[] {gesture, state, gesture.State}));
                            break;
                    }
                    break;
                case Gesture.GestureState.Cancelled:
                    if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                    break;
            }

            return state;
        }
Esempio n. 11
0
 /// <summary>
 /// Determines whether this instance can be prevented by specified gesture.
 /// </summary>
 /// <param name="gesture"> The gesture. </param>
 /// <returns> <c>true</c> if this instance can be prevented by specified gesture; <c>false</c> otherwise. </returns>
 public virtual bool CanBePreventedByGesture(Gesture gesture)
 {
     if (Delegate == null) return !IsFriendly(gesture);
     return !Delegate.ShouldRecognizeSimultaneously(this, gesture);
 }
Esempio n. 12
0
 private void failGesture(Gesture gesture)
 {
     gesture.SetState(Gesture.GestureState.Failed);
 }
Esempio n. 13
0
        internal Gesture.GestureState GestureChangeState(Gesture gesture, Gesture.GestureState state)
        {
            switch (state)
            {
                case Gesture.GestureState.Possible:
                    break;
                case Gesture.GestureState.Began:
                    switch (gesture.State)
                    {
                        case Gesture.GestureState.Possible:
                            break;
                        default:
                            print(String.Format("Gesture {0} erroneously tried to enter state {1} from state {2}", gesture, state, gesture.State));
                            break;
                    }
                    if (gestureCanRecognize(gesture))
                    {
                        recognizeGesture(gesture);
                    } else
                    {
                        if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                        return Gesture.GestureState.Failed;
                    }
                    break;
                case Gesture.GestureState.Changed:
                    switch (gesture.State)
                    {
                        case Gesture.GestureState.Began:
                        case Gesture.GestureState.Changed:
                            break;
                        default:
                            print(String.Format("Gesture {0} erroneously tried to enter state {1} from state {2}", gesture, state, gesture.State));
                            break;
                    }
                    break;
                case Gesture.GestureState.Failed:
                    if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                    break;
                case Gesture.GestureState.Recognized: // Ended
                    if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                    switch (gesture.State)
                    {
                        case Gesture.GestureState.Possible:
                            if (gestureCanRecognize(gesture))
                            {
                                recognizeGesture(gesture);
                            } else
                            {
                                return Gesture.GestureState.Failed;
                            }
                            break;
                        case Gesture.GestureState.Began:
                        case Gesture.GestureState.Changed:
                            break;
                        default:
                            print(String.Format("Gesture {0} erroneously tried to enter state {1} from state {2}", gesture, state, gesture.State));
                            break;
                    }
                    break;
                case Gesture.GestureState.Cancelled:
                    if (!gesturesToReset.Contains(gesture)) gesturesToReset.Add(gesture);
                    break;
            }

            return state;
        }
Esempio n. 14
0
        private void addFriendlyGesture(SerializedProperty prop, Gesture value)
        {
            if (value == null || value == target) return;

            // Adding that gesture to this gesture.
            var shouldAdd = true;
            for (int i = 0; i < prop.arraySize; i++)
            {
                if (prop.GetArrayElementAtIndex(i).objectReferenceValue == value)
                {
                    shouldAdd = false;
                    break;
                }
            }

            if (shouldAdd)
            {
                prop.arraySize++;
                prop.GetArrayElementAtIndex(prop.arraySize - 1).objectReferenceValue = value;
                addFriendlyGestureId.Invoke(instance, new object[] {value});
            }

            // Adding this gesture to that gesture.
            shouldAdd = true;
            var so = new SerializedObject(value);
            so.Update();
            SerializedProperty p = so.FindProperty(FRIENDLY_GESTURES_PROP);
            for (int i = 0; i < p.arraySize; i++)
            {
                if (p.GetArrayElementAtIndex(i).objectReferenceValue == target)
                {
                    shouldAdd = false;
                    break;
                }
            }

            if (shouldAdd)
            {
                p.arraySize++;
                p.GetArrayElementAtIndex(p.arraySize - 1).objectReferenceValue = target;
                so.ApplyModifiedProperties();
                EditorUtility.SetDirty(value);
                addFriendlyGestureId.Invoke(value, new object[] {instance});
            }
        }
Esempio n. 15
0
 internal bool IsFriendly(Gesture gesture)
 {
     return(friendlyGestureIds.Contains(gesture.GetInstanceID()));
 }
Esempio n. 16
0
 /// <summary>
 /// Checks if a gesture is friendly with this gesture.
 /// </summary>
 /// <param name="gesture">A gesture to check.</param>
 /// <returns>True if gestures are friendly; false otherwise.</returns>
 public bool IsFriendly(Gesture gesture)
 {
     return(friendlyGestures.Contains(gesture));
 }
Esempio n. 17
0
 /// <summary>
 /// Checks if a gesture is friendly with this gesture.
 /// </summary>
 /// <param name="gesture"> A gesture to check. </param>
 /// <returns> <c>true</c> if gestures are friendly; <c>false</c> otherwise. </returns>
 public bool IsFriendly(Gesture gesture)
 {
     return friendlyGestures.Contains(gesture);
 }
Esempio n. 18
0
        private bool gestureCanRecognize(Gesture gesture)
        {
            if (!gesture.ShouldBegin()) return false;

            var gestures = getHierarchyContaining(gesture.transform);
            foreach (var otherGesture in gestures)
            {
                if (gesture == otherGesture) continue;
                if (!gestureIsActive(otherGesture)) continue;
                if ((otherGesture.State == Gesture.GestureState.Began || otherGesture.State == Gesture.GestureState.Changed) &&
                    otherGesture.CanPreventGesture(gesture))
                {
                    return false;
                }
            }

            return true;
        }
Esempio n. 19
0
        internal virtual void INTERNAL_RemoveFriendlyGesture(Gesture gesture)
        {
            if (gesture == null || gesture == this) return;

            unregisterFriendlyGesture(gesture);
            gesture.unregisterFriendlyGesture(this);
        }
Esempio n. 20
0
 private void recognizeGesture(Gesture gesture)
 {
     var gestures = getHierarchyContaining(gesture.transform);
     foreach (var otherGesture in gestures)
     {
         if (gesture == otherGesture) continue;
         if (!gestureIsActive(otherGesture)) continue;
         if (!(otherGesture.State == Gesture.GestureState.Began || otherGesture.State == Gesture.GestureState.Changed) &&
             gesture.CanPreventGesture(otherGesture))
         {
             failGesture(otherGesture);
         }
     }
 }
Esempio n. 21
0
 private void doUpdateBegan(Gesture gesture, TouchPoint touch)
 {
     gesture.INTERNAL_TouchBegan(touch);
 }
Esempio n. 22
0
 /// <summary>
 /// Determines whether this instance can prevent the specified gesture.
 /// </summary>
 /// <param name="gesture">The gesture.</param>
 /// <returns>
 ///   <c>true</c> if this instance can prevent the specified gesture; otherwise, <c>false</c>.
 /// </returns>
 public virtual bool CanPreventGesture(Gesture gesture)
 {
     if (Delegate == null)
     {
         if (gesture.CanBePreventedByGesture(this))
         {
             if (shouldRecognizeWith.Contains(gesture.GetInstanceID()))
             {
                 return false;
             } else
             {
                 return true;
             }
         } else
         {
             return false;
         }
     } else
     {
         return !Delegate.ShouldRecognizeSimultaneously(this, gesture);
     }
 }
Esempio n. 23
0
 private void doUpdateCancelled(Gesture gesture, TouchPoint touch)
 {
     gesture.INTERNAL_TouchCancelled(touch);
 }
Esempio n. 24
0
 /// <inheritdoc />
 public override bool CanPreventGesture(Gesture gesture)
 {
     if (Delegate == null) return false;
     return Delegate.ShouldRecognizeSimultaneously(this, gesture);
 }
Esempio n. 25
0
        private bool recognizeGestureIfNotPrevented(Gesture gesture)
        {
            if (!shouldBegin(gesture)) return false;

            var gesturesToFail = gestureListPool.Get();
            var gesturesInHierarchy = gestureListPool.Get();
            bool canRecognize = true;
            getHierarchyContaining(gesture.transform, gesturesInHierarchy);

            var count = gesturesInHierarchy.Count;
            for (var i = 0; i < count; i++)
            {
                var otherGesture = gesturesInHierarchy[i];
                if (gesture == otherGesture) continue;
                if (!gestureIsActive(otherGesture)) continue;

                if (otherGesture.State == Gesture.GestureState.Began ||
                    otherGesture.State == Gesture.GestureState.Changed)
                {
                    if (canPreventGesture(otherGesture, gesture))
                    {
                        canRecognize = false;
                        break;
                    }
                }
                else
                {
                    if (canPreventGesture(gesture, otherGesture))
                    {
                        gesturesToFail.Add(otherGesture);
                    }
                }
            }

            if (canRecognize)
            {
                count = gesturesToFail.Count;
                for (var i = 0; i < count; i++)
                {
                    failGesture(gesturesToFail[i]);
                }
            }

            gestureListPool.Release(gesturesToFail);
            gestureListPool.Release(gesturesInHierarchy);

            return canRecognize;
        }
Esempio n. 26
0
        private void registerFriendlyGesture(Gesture gesture)
        {
            if (gesture == null || gesture == this) return;

            if (!friendlyGestures.Contains(gesture)) friendlyGestures.Add(gesture);
        }
Esempio n. 27
0
 private bool shouldReceiveTouch(Gesture gesture, TouchPoint touch)
 {
     bool result = true;
     if (GlobalGestureDelegate != null) result = GlobalGestureDelegate.ShouldReceiveTouch(gesture, touch);
     return result && gesture.ShouldReceiveTouch(touch);
 }
Esempio n. 28
0
        private void unregisterFriendlyGesture(Gesture gesture)
        {
            if (gesture == null || gesture == this) return;

            friendlyGestures.Remove(gesture);
        }
Esempio n. 29
0
 private bool canPreventGesture(Gesture first, Gesture second)
 {
     bool result = true;
     if (GlobalGestureDelegate != null) result = !GlobalGestureDelegate.ShouldRecognizeSimultaneously(first, second);
     return result && first.CanPreventGesture(second);
 }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GestureStateChangeEventArgs"/> class.
 /// </summary>
 /// <param name="state"> Current gesture state. </param>
 /// <param name="previousState"> Previous gesture state. </param>
 public GestureStateChangeEventArgs(Gesture.GestureState state, Gesture.GestureState previousState)
 {
     State = state;
     PreviousState = previousState;
 }
Esempio n. 31
0
        /// <param name="touch">The touch.</param>
        /// <returns><c>true</c> if this touch should be received by the gesture; otherwise, <c>false</c>.</returns>
        public virtual bool ShouldReceiveTouch(TouchPoint touch)
        {
            if (Delegate == null) return true;
            return Delegate.ShouldReceiveTouch(this, touch);
        }

        /// <summary>
        /// Tells that the gesture should (or shouldn't) work simultaneously with this gesture.
        /// </summary>
        /// <param name="gesture">The gesture.</param>
        /// <param name="value">if set to <c>true</c> allows simultaneous recognition.</param>
        public void ShouldRecognizeSimultaneouslyWith(Gesture gesture, bool value = true)
        {
            if (gesture == this) return;
Esempio n. 32
0
        /// <summary>
        /// Adds a friendly gesture.
        /// </summary>
        /// <param name="gesture"> The gesture. </param>
        public void AddFriendlyGesture(Gesture gesture)
        {
            if (gesture == null || gesture == this) return;

            registerFriendlyGesture(gesture);
            gesture.registerFriendlyGesture(this);
        }