コード例 #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; };
        }
コード例 #2
0
        public override void OnEnter()
        {
            gesture = GestureUtils.GetGesture<Gesture>(Fsm, GameObject, Gesture, Component, false);
            if (gesture == null)
            {
                LogError("Gesture is missing");
                return;
            }

            gesture.StateChanged += gestureStateChangedHandler;
        }
コード例 #3
0
ファイル: GestureEditor.cs プロジェクト: ksmylz/TouchScript
        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);
        }
コード例 #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();
        }
コード例 #5
0
ファイル: Gesture.cs プロジェクト: gijs/TouchScript
        {
            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>
コード例 #6
0
 private bool shouldBegin(Gesture gesture)
 {
     bool result = true;
     if (GlobalGestureDelegate != null) result = GlobalGestureDelegate.ShouldBegin(gesture);
     return result && gesture.ShouldBegin();
 }
コード例 #7
0
 private void failGesture(Gesture gesture)
 {
     gesture.INTERNAL_SetState(Gesture.GestureState.Failed);
 }
コード例 #8
0
 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;
     }
 }
コード例 #9
0
 private void doUpdateEnded(Gesture gesture, TouchPoint touch)
 {
     gesture.INTERNAL_TouchEnded(touch);
 }
コード例 #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;
        }
コード例 #11
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
 /// <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);
 }
コード例 #12
0
ファイル: TouchManager.cs プロジェクト: kod3r/TouchScript
 private void failGesture(Gesture gesture)
 {
     gesture.SetState(Gesture.GestureState.Failed);
 }
コード例 #13
0
ファイル: TouchManager.cs プロジェクト: kod3r/TouchScript
        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;
        }
コード例 #14
0
ファイル: GestureEditor.cs プロジェクト: scbwin/TouchScript
        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});
            }
        }
コード例 #15
0
ファイル: Gesture.cs プロジェクト: oleprinds/TouchScript
 internal bool IsFriendly(Gesture gesture)
 {
     return(friendlyGestureIds.Contains(gesture.GetInstanceID()));
 }
コード例 #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));
 }
コード例 #17
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
 /// <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);
 }
コード例 #18
0
ファイル: TouchManager.cs プロジェクト: kod3r/TouchScript
        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;
        }
コード例 #19
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
        internal virtual void INTERNAL_RemoveFriendlyGesture(Gesture gesture)
        {
            if (gesture == null || gesture == this) return;

            unregisterFriendlyGesture(gesture);
            gesture.unregisterFriendlyGesture(this);
        }
コード例 #20
0
ファイル: TouchManager.cs プロジェクト: kod3r/TouchScript
 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);
         }
     }
 }
コード例 #21
0
 private void doUpdateBegan(Gesture gesture, TouchPoint touch)
 {
     gesture.INTERNAL_TouchBegan(touch);
 }
コード例 #22
0
ファイル: Gesture.cs プロジェクト: NormLi/TouchScript
 /// <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);
     }
 }
コード例 #23
0
 private void doUpdateCancelled(Gesture gesture, TouchPoint touch)
 {
     gesture.INTERNAL_TouchCancelled(touch);
 }
コード例 #24
0
 /// <inheritdoc />
 public override bool CanPreventGesture(Gesture gesture)
 {
     if (Delegate == null) return false;
     return Delegate.ShouldRecognizeSimultaneously(this, gesture);
 }
コード例 #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;
        }
コード例 #26
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
        private void registerFriendlyGesture(Gesture gesture)
        {
            if (gesture == null || gesture == this) return;

            if (!friendlyGestures.Contains(gesture)) friendlyGestures.Add(gesture);
        }
コード例 #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);
 }
コード例 #28
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
        private void unregisterFriendlyGesture(Gesture gesture)
        {
            if (gesture == null || gesture == this) return;

            friendlyGestures.Remove(gesture);
        }
コード例 #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);
 }
コード例 #30
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
 /// <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;
 }
コード例 #31
0
ファイル: Gesture.cs プロジェクト: gijs/TouchScript
        /// <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;
コード例 #32
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
        /// <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);
        }