Example #1
0
        /// <inheritdoc />
        public bool AddLayer(TouchLayer layer, int index)
        {
            if (layer == null)
            {
                return(false);
            }
            if (index >= layers.Count)
            {
                return(AddLayer(layer));
            }
            var i = layers.IndexOf(layer);

            if (i == -1)
            {
                layers.Insert(index, layer);
            }
            else
            {
                if (index == i || i == index - 1)
                {
                    return(true);
                }
                layers.RemoveAt(i);
                if (index < i)
                {
                    layers.Insert(index, layer);
                }
                else
                {
                    layers.Insert(index - 1, layer);
                }
            }
            return(true);
        }
        /// <inheritdoc />
        protected override void touchesBegan(IList <ITouch> touches)
        {
            base.touchesBegan(touches);

            if (touchesNumState == TouchesNumState.PassedMaxThreshold ||
                touchesNumState == TouchesNumState.PassedMinMaxThreshold)
            {
                switch (State)
                {
                case GestureState.Began:
                case GestureState.Changed:
                    setState(GestureState.Ended);
                    break;

                case GestureState.Possible:
                    setState(GestureState.Failed);
                    break;
                }
            }
            else if (touches.Count == NumTouches)
            {
                projectionLayer = activeTouches[0].Layer;
                updateProjectionPlane();
            }
        }
Example #3
0
        /// <inheritdoc />
        public bool GetHitTarget(Vector2 position, out ITouchHit hit, out TouchLayer layer)
        {
            hit   = null;
            layer = null;

            var count = layers.Count;

            for (var i = 0; i < count; i++)
            {
                var touchLayer = layers[i];
                if (touchLayer == null)
                {
                    continue;
                }
                ITouchHit _hit;
                if (touchLayer.Hit(position, out _hit) == TouchLayer.LayerHitResult.Hit)
                {
                    hit   = _hit;
                    layer = touchLayer;
                    return(true);
                }
            }

            return(false);
        }
Example #4
0
 public bool ShouldReceivePointer(TouchLayer layer, IPointer pointer)
 {
     if (layer == RenderTextureLayer)
     {
         return(pointer.InputSource == (IInputSource)Source);
     }
     return(pointer.InputSource != (IInputSource)Source);
 }
Example #5
0
 public bool ShouldReceiveTouch(TouchLayer layer, TouchPoint touch)
 {
     if (layer == RenderTextureLayer)
     {
         return(touch.InputSource == Source);
     }
     return(touch.InputSource != Source);
 }
Example #6
0
    // *****************************************************
    // Touch Controls
    // *****************************************************

    private void initTouchControls()
    {
        touchControls = GameObject.Find("TouchControls").GetComponent <TouchControls>();
        touchLayer    = touchControls.getLayer("grid");

        touchLayer.onPress   += onTouchPress;
        touchLayer.onRelease += onTouchRelease;
        touchLayer.onMove    += onTouchMove;
        touchLayer.onSwipe   += onTouchSwipe;
    }
Example #7
0
        /// <inheritdoc />
        public bool RemoveLayer(TouchLayer layer)
        {
            if (layer == null)
            {
                return(false);
            }
            var result = layers.Remove(layer);

            return(result);
        }
Example #8
0
        /// <inheritdoc />
        protected override void touchesBegan(IList <ITouch> touches)
        {
            base.touchesMoved(touches);

            if (touches.Count == activeTouches.Count)
            {
                projectionLayer = activeTouches[0].Layer;
                updateProjectionPlane();
            }
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HitData"/> struct.
        /// </summary>
        /// <param name="target"> Target Target. </param>
        /// <param name="layer"> Touch layer this hit came from. </param>
        /// <param name="screenSpace"> If the hit is screenspace UI. </param>
        public HitData(Transform target, TouchLayer layer, bool screenSpace = false)
        {
            this.target      = target;
            this.layer       = layer;
            this.screenSpace = screenSpace;

            sortingLayer = -1;
            sortingOrder = -1;
            raycastHit   = default(RaycastHit);
            raycastHit2D = default(RaycastHit2D);
            raycastHitUI = default(RaycastHitUI);
            type         = HitType.Screen;
        }
Example #10
0
 /// <inheritdoc />
 public bool AddLayer(TouchLayer layer)
 {
     if (layer == null)
     {
         return(false);
     }
     if (layers.Contains(layer))
     {
         return(true);
     }
     layers.Add(layer);
     return(true);
 }
Example #11
0
        /// <inheritdoc />
        protected override void touchesBegan(IList <TouchPoint> touches)
        {
            base.touchesBegan(touches);

            if (State != GestureState.Possible)
            {
                return;
            }
            if (NumTouches == touches.Count)
            {
                projectionLayer = activeTouches[0].Layer;
                updateProjectionPlane();
            }
        }
Example #12
0
        /// <inheritdoc />
        protected override void touchBegan(TouchPoint touch)
        {
            base.touchBegan(touch);

            if (State != GestureState.Possible)
            {
                return;
            }
            if (NumTouches == 1)
            {
                projectionLayer = activeTouches[0].Layer;
                updateProjectionPlane();
            }
        }
        /// <inheritdoc />
        protected override void pointersPressed(IList <Pointer> pointers)
        {
            gestureSampler.Begin();

            base.pointersPressed(pointers);

            if (NumPointers == pointers.Count)
            {
                projectionLayer = activePointers[0].GetPressData().Layer;
                updateProjectionPlane();
            }

            gestureSampler.End();
        }
Example #14
0
    public TouchLayer addLayer(string name)
    {
        if (mappedLayers.ContainsKey(name))
        {
            return(mappedLayers[name]);
        }

        TouchLayer layer = new TouchLayer(name);

        mappedLayers.Add(name, layer);
        sortedLayers.Insert(0, layer);

        return(layer);
    }
Example #15
0
        /// <summary>
        /// Gets result of casting a ray from specific screen position.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="hit">Raycast result.</param>
        /// <returns>true if ray hits gesture's target; otherwise, false.</returns>
        public virtual bool GetTargetHitResult(Vector2 position, out ITouchHit hit)
        {
            TouchLayer layer = null;

            if (!touchManager.GetHitTarget(position, out hit, out layer))
            {
                return(false);
            }

            if (cachedTransform == hit.Transform || hit.Transform.IsChildOf(cachedTransform))
            {
                return(true);
            }
            return(false);
        }
Example #16
0
        private void Start()
        {
            if (instance == null)
            {
                instance = this;
                DontDestroyOnLoad(gameObject);
            }

            layer = GetComponent <TouchLayer>();

#if UNITY_EDITOR
            var guids = AssetDatabase.FindAssets("t:Scene", new string[] { "Assets/TouchScript/Examples" });
            if (EditorBuildSettings.scenes.Length != guids.Length)
            {
                if (EditorUtility.DisplayDialog("Add Example Scenes to Build Settings?",
                                                "You are running Examples scene but example scenes are not added to Build Settings. Do you want to add them now?", "Yes", "No"))
                {
                    var importers = Array.ConvertAll(guids, (string guid) => AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
                    Array.Sort(importers, (AssetImporter a, AssetImporter b) =>
                    {
                        var i1 = string.IsNullOrEmpty(a.userData) ? 42 : Convert.ToInt32(a.userData);
                        var i2 = string.IsNullOrEmpty(b.userData) ? 42 : Convert.ToInt32(b.userData);
                        if (i1 == i2)
                        {
                            return(0);
                        }
                        return(i1 - i2);
                    });
                    EditorBuildSettings.scenes = Array.ConvertAll(importers, (AssetImporter i) => new EditorBuildSettingsScene(i.assetPath, true));
                    EditorUtility.DisplayDialog("Success", "Example scenes were added to Build Settings. Please restart Play Mode.", "OK");
                }
            }
#endif

#if UNITY_5_4_OR_NEWER
            SceneManager.sceneLoaded += sceneLoadedHandler;
#endif

#if UNITY_5_3_OR_NEWER
            if (SceneManager.GetActiveScene().name == "Examples" && SceneManager.sceneCountInBuildSettings > 1)
#else
            if (Application.loadedLevelName == "Examples" && Application.levelCount > 1)
#endif
            {
                LoadNextLevel();
            }
        }
Example #17
0
        /// <inheritdoc />
        public bool AddLayer(TouchLayer layer, int index = -1, bool addIfExists = true)
        {
            if (layer == null)
            {
                return(false);
            }

            var i = layers.IndexOf(layer);

            if (i != -1)
            {
                if (!addIfExists)
                {
                    return(false);
                }
                layers.RemoveAt(i);
                layerCount--;
            }
            if (index == 0)
            {
                layers.Insert(0, layer);
                layerCount++;
                return(i == -1);
            }
            if (index == -1 || index >= layerCount)
            {
                layers.Add(layer);
                layerCount++;
                return(i == -1);
            }
            if (i != -1)
            {
                if (index < i)
                {
                    layers.Insert(index, layer);
                }
                else
                {
                    layers.Insert(index - 1, layer);
                }
                layerCount++;
                return(false);
            }
            layers.Insert(index, layer);
            layerCount++;
            return(true);
        }
Example #18
0
        /// <summary>
        /// Gets result of casting a ray from specific screen position.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="hit">Raycast result.</param>
        /// <returns>true if ray hits gesture's target; otherwise, false.</returns>
        public virtual bool GetTargetHitResult(Vector2 position, out RaycastHit hit)
        {
            hit = new RaycastHit();

            TouchLayer layer = null;

            if (!TouchManager.Instance.GetHitTarget(position, out hit, out layer))
            {
                return(false);
            }

            if (transform == hit.transform || hit.transform.IsChildOf(transform))
            {
                return(true);
            }
            return(false);
        }
Example #19
0
        /// <summary>
        /// Removes a layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <returns>True if layer was removed.</returns>
        public static bool RemoveLayer(TouchLayer layer)
        {
            if (shuttingDown)
            {
                return(false);
            }
            if (layer == null)
            {
                return(false);
            }
            if (instance == null)
            {
                return(false);
            }
            var result = instance.layers.Remove(layer);

            return(result);
        }
Example #20
0
        /// <inheritdoc />
        protected override void touchesBegan(IList <TouchPoint> touches)
        {
            base.touchesBegan(touches);

            if (State != GestureState.Possible)
            {
                return;
            }
            if (NumTouches == touches.Count)
            {
                projectionLayer = activeTouches[0].Layer;
                updateProjectionPlane();

#if TOUCHSCRIPT_DEBUG
                drawDebug(activeTouches[0].ProjectionParams.ProjectFrom(cachedTransform.position), activeTouches[0].Position);
#endif
            }
        }
        /// <inheritdoc />
        protected override void pointersPressed(IList <Pointer> pointers)
        {
            gestureSampler.Begin();

            base.pointersPressed(pointers);

            if (NumPointers == pointers.Count)
            {
                projectionLayer = activePointers[0].GetPressData().Layer;
                updateProjectionPlane();

#if TOUCHSCRIPT_DEBUG
                drawDebug(activePointers[0].ProjectionParams.ProjectFrom(cachedTransform.position), activePointers[0].Position);
#endif
            }

            gestureSampler.End();
        }
        /// <inheritdoc />
        protected override void touchesBegan(IList <ITouch> touches)
        {
            base.touchesBegan(touches);

            if (State != GestureState.Possible)
            {
                return;
            }
            if (touches.Count == NumTouches)
            {
                projectionLayer = activeTouches[0].Layer;
                updateProjectionPlane();

#if DEBUG
                drawDebug(projectionLayer.ProjectFrom(cachedTransform.position), activeTouches[0].Position);
#endif
            }
        }
Example #23
0
 /// <summary>
 /// Adds a layer.
 /// </summary>
 /// <param name="layer">The layer.</param>
 /// <returns>True if layer was added.</returns>
 public static bool AddLayer(TouchLayer layer)
 {
     if (shuttingDown)
     {
         return(false);
     }
     if (layer == null)
     {
         return(false);
     }
     if (Instance == null)
     {
         return(false);
     }
     if (Instance.layers.Contains(layer))
     {
         return(false);
     }
     Instance.layers.Add(layer);
     return(true);
 }
Example #24
0
        /// <inheritdoc />
        public bool GetHitTarget(Vector2 position, out ITouchHit hit, out TouchLayer layer)
        {
            hit   = null;
            layer = null;

            foreach (var touchLayer in layers)
            {
                if (touchLayer == null)
                {
                    continue;
                }
                ITouchHit _hit;
                if (touchLayer.Hit(position, out _hit) == TouchLayer.LayerHitResult.Hit)
                {
                    hit   = _hit;
                    layer = touchLayer;
                    return(true);
                }
            }

            return(false);
        }
Example #25
0
        /// <summary>
        /// Gets result of casting a ray from specific screen position.
        /// </summary>
        /// <param name="position"> The position. </param>
        /// <param name="hit"> Raycast result. </param>
        /// <returns> <c>true</c> if ray hits gesture's target; <c>false</c> otherwise. </returns>
        public virtual bool GetTargetHitResult(Vector2 position, out TouchHit hit)
        {
            if (layer != null)
            {
                if (layer.Hit(position, out hit) != TouchLayer.LayerHitResult.Hit)
                {
                    return(false);
                }
            }
            else
            {
                TouchLayer l = null;
                if (!touchManager.GetHitTarget(position, out hit, out l))
                {
                    return(false);
                }
            }

            if (cachedTransform == hit.Transform || hit.Transform.IsChildOf(cachedTransform))
            {
                return(true);
            }
            return(false);
        }
Example #26
0
        /// <summary>
        /// Gets result of casting a ray from gesture touch points centroid screen position.
        /// </summary>
        /// <param name="hit">Raycast result</param>
        /// <returns>True if ray hits gesture's target; otherwise, false.</returns>
        public virtual bool GetTargetHitResult(out RaycastHit hit)
        {
            hit = new RaycastHit();

            var camera = Cluster.GetClusterCamera(activeTouches);

            if (camera == null)
            {
                return(false);
            }

            TouchLayer layer = null;

            if (!TouchManager.Instance.GetHitTarget(ScreenPosition, out hit, out layer))
            {
                return(false);
            }

            if (transform == hit.transform || hit.transform.IsChildOf(transform))
            {
                return(true);
            }
            return(false);
        }
Example #27
0
        internal void INTERNAL_TouchBegan(TouchPoint touch)
        {
            if (numTouches == 0)
            {
                layer = touch.Layer;
            }

            var total = numTouches + 1;

            touchesNumState = TouchesNumState.InRange;

            if (minTouches <= 0)
            {
                // minTouches is not set and we got our first touches
                if (numTouches == 0)
                {
                    touchesNumState = TouchesNumState.PassedMinThreshold;
                }
            }
            else
            {
                if (numTouches < minTouches)
                {
                    // had < minTouches, got >= minTouches
                    if (total >= minTouches)
                    {
                        touchesNumState = TouchesNumState.PassedMinThreshold;
                    }
                    else
                    {
                        touchesNumState = TouchesNumState.TooFew;
                    }
                }
            }

            if (maxTouches > 0)
            {
                if (numTouches <= maxTouches)
                {
                    if (total > maxTouches)
                    {
                        // this event we crossed both minTouches and maxTouches
                        if (touchesNumState == TouchesNumState.PassedMinThreshold)
                        {
                            touchesNumState = TouchesNumState.PassedMinMaxThreshold;
                        }
                        // this event we crossed maxTouches
                        else
                        {
                            touchesNumState = TouchesNumState.PassedMaxThreshold;
                        }
                    }
                }
                // last event we already were over maxTouches
                else
                {
                    touchesNumState = TouchesNumState.TooMany;
                }
            }

            if (state == GestureState.Began || state == GestureState.Changed)
            {
                touch.INTERNAL_Retain();
            }

            activeTouches.Add(touch);
            numTouches = total;
            touchBegan(touch);
        }
Example #28
0
 /// <summary>
 /// Called to reset gesture state after it fails or recognizes.
 /// </summary>
 protected virtual void reset()
 {
     layer = null;
     cachedScreenPosition         = TouchManager.INVALID_POSITION;
     cachedPreviousScreenPosition = TouchManager.INVALID_POSITION;
 }
 private bool layerRemovePointer(TouchLayer layer)
 {
     layer.INTERNAL_RemovePointer(tmpPointer);
     return(true);
 }
 private bool layerUpdatePointer(TouchLayer layer)
 {
     layer.INTERNAL_UpdatePointer(tmpPointer);
     return(true);
 }