/// <summary>
        /// Processes the end of the input.
        /// </summary>
        /// <param name="touch">The UnityEngine touch.</param>
        public TouchType End(Touch touch) {
            var start = this._startPosition;
            var end = touch.position;
            var yDifference = Mathf.Abs(start.y - end.y);
            var xDifference = Mathf.Abs(start.x - end.x);
            var timeDifference = Time.time - this._startTime;

            if (yDifference > SimpleMobile.Instance.MinimumScreenHeightSwipeDistance && yDifference >= xDifference) {
                if (end.y > start.y)
                    return TouchType.Up;
                else
                    return TouchType.Down;
            }
            else if (xDifference > SimpleMobile.Instance.MinimumScreenWidthSwipeDistance && xDifference > yDifference) {
                if (end.x > start.x) {
                    return TouchType.Right;
                }
                else {
                    return TouchType.Left;
                }
            }
            else if (timeDifference < SimpleMobile.Instance.MaximumTapTime) {
                return TouchType.Tap;
            }

            return TouchType.Down;
        }
Example #2
0
 private void HandlePinchStarted()
 {
     this.InitialScale = this.CurrentScale;
     
     this.TouchStart0 = Input.GetTouch(0);
     this.TouchStart1 = Input.GetTouch(1);
 }
		void Update () {

			// If there are two touches on the device...
			if (Input.touchCount == 2) {
				// Store both touches.
				touchZero = Input.GetTouch (0);
				touchOne = Input.GetTouch (1);

				// Find the position in the previous frame of each touch.
				touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
				touchOnePrevPos = touchOne.position - touchOne.deltaPosition;

				// Find the magnitude of the vector (the distance) between the touches in each frame.
				// Find the difference in the distances between each frame.
				deltaMagnitudeDiff = (touchZeroPrevPos - touchOnePrevPos).magnitude -
					(touchZero.position - touchOne.position).magnitude;
			}

			if (Input.mousePresent){
				deltaMagnitudeDiff =  Input.GetAxis("Mouse ScrollWheel") * -mouseScrollSpeed;
			}

			if ( deltaMagnitudeDiff != 0 ){
				Zoom (deltaMagnitudeDiff);
				deltaMagnitudeDiff = 0;
			}

		}
Example #4
0
        void HandleTranslation(Touch a_touch)
        {
            Vector3 translation = Vector3.zero;

            #if UNITY_EDITOR
            if (Input.touchSupported)
            {
                // Calculate mouse delta
                Vector3 currentMouseDelta = mouseDelta;

                if (Input.GetMouseButton(0))
                {
                    // Calculate mouse delta, and apply translation
                    translation = new Vector3(mouseDelta.x, 0.0f, mouseDelta.y);
                    _cameraController.TranslateCamera(-translation);
                }

                // Update last mouse position for next frame
                _lastMousePos = Input.mousePosition;

                return;
            }
            #endif
            // Get touch delta
            Vector2 deltaTouchPos = a_touch.deltaPosition;

            // Apply transaltion
            translation = new Vector3(deltaTouchPos.x, 0.0f, deltaTouchPos.y);
            _cameraController.TranslateCamera(-translation);
        }
        /// <summary>
        ///     Gets the current InputState.
        /// </summary>
        /// <param name="touch">The current touch.</param>
        /// <param name="state">The state to check against.</param>
        /// <returns>True if the InputState matches the current input</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">touch;null</exception>
        public static bool GetState(Touch touch, InputState state)
        {
            #if UNITY_EDITOR
            switch (state)
            {
                case InputState.Began:
                    return Input.GetMouseButtonDown(0);
                case InputState.Moving:
                    return Input.GetMouseButton(0);
                case InputState.Ended:
                    return Input.GetMouseButtonUp(0);
                case InputState.Canceled:
                    return false;
                default:
                    throw new ArgumentOutOfRangeException("touch", state, null);
            }
            #else
            switch (state)
            {
                case InputState.Began:
                    return touch.phase == TouchPhase.Began;
                case InputState.Moving:
                    return touch.phase == TouchPhase.Moved;
                case InputState.Ended:
                    return touch.phase == TouchPhase.Ended;
                case InputState.Canceled:
                    return touch.phase == TouchPhase.Canceled;
                default:
                    throw new ArgumentOutOfRangeException("touchPhase", state, null);
            }

            #endif //UNITY_EDITOR
        }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Touch o;
         o = new UnityEngine.Touch();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Example #7
0
		public void Update(Touch[] touches)
		{
			closeInfo();
			for (int i = 0; i < touches.Length; ++i)
			{
				updateInfo(ref touches[i]);
			}
		}
Example #8
0
		public void Init(Touch touch)
		{
			this.fingerID = touch.fingerId;
			this.stateTime = touch.deltaTime;
			this.totalTime = touch.deltaTime;
			this.pos = touch.position;
			this.deltaPos = touch.deltaPosition;
			this.totalVec = touch.deltaPosition;
			this.state = TouchStateUtil.PhaseToState(touch.phase);
		}
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.Touch o;
			o=new UnityEngine.Touch();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Example #10
0
 private void startRecord(Touch touch)
 {
     if (touch.phase == TouchPhase.Began){
         rec = new UserActionRecord(touch.position);
     }
     if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary){
         rec.checkNewPosition(touch.position);
     }
     if (touch.phase == TouchPhase.Ended){
         rec.checkNewPosition(touch.position);
         PlayerControlHolder.Instance.SwipeControl(rec.getResultAction());
     }
 }
Example #11
0
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.Touch o;
         o=new UnityEngine.Touch();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Example #12
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.Touch o;
         o = new UnityEngine.Touch();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #13
0
 public override TouchInfo GetTouch(int touchIndex)
 {
     UnityEngine.Touch inputTouch = UnityEngine.Input.GetTouch(touchIndex);
     return(new TouchInfo()
     {
         FingerId = inputTouch.fingerId,
         TapCount = inputTouch.tapCount,
         Position = inputTouch.position,
         PositionDelta = inputTouch.deltaPosition,
         TimeDelta = inputTouch.deltaTime,
         Phase = inputTouch.phase,
     });
 }
Example #14
0
 private GameObject DetectTouchOnGameObject(Touch touch)
 {
     //  Mask = 1 << 5;
     Vector3 pos = Camera.main.ScreenToWorldPoint(touch.position);
     if (Physics2D.Raycast(pos, Vector2.up, 0, 10, Mask) == true) Debug.Log("Its Work");
     RaycastHit2D hit = Physics2D.Raycast(pos, Vector2.zero, 0, Mask);
     if (hit != null && hit.collider != null)
     {
         Debug.Log("I'm hitting " + hit.collider.name);
         return hit.collider.gameObject;
     }
     else return null;
 }
Example #15
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.Touch o;
         o = new UnityEngine.Touch();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Example #16
0
        internal void SetWithTouchData(UnityEngine.Touch touch, ulong updateTick, float deltaTime)
        {
            phase    = touch.phase;
            tapCount = touch.tapCount;

#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
            type                    = TouchType.Direct;
            altitudeAngle           = Mathf.PI / 2.0f;
            azimuthAngle            = Mathf.PI / 2.0f;
            maximumPossiblePressure = 1.0f;
            pressure                = 1.0f;
            radius                  = 1.0f;
            radiusVariance          = 0.0f;
#else
            altitudeAngle           = touch.altitudeAngle;
            azimuthAngle            = touch.azimuthAngle;
            maximumPossiblePressure = touch.maximumPossiblePressure;
            pressure       = touch.pressure;
            radius         = touch.radius;
            radiusVariance = touch.radiusVariance;
#endif

            var touchPosition = touch.position;

            // Deal with Unity Remote weirdness.
            if (touchPosition.x < 0.0f)
            {
                touchPosition.x = Screen.width + touchPosition.x;
            }

            if (phase == TouchPhase.Began)
            {
                deltaPosition = Vector2.zero;
                lastPosition  = touchPosition;
                position      = touchPosition;
            }
            else
            {
                if (phase == TouchPhase.Stationary)
                {
                    phase = TouchPhase.Moved;
                }

                deltaPosition = touchPosition - lastPosition;
                lastPosition  = position;
                position      = touchPosition;
            }

            this.deltaTime  = deltaTime;
            this.updateTick = updateTick;
        }
 static public int GetTouch_s(IntPtr l)
 {
     try{
         System.Int32 a1;
         checkType(l, 1, out a1);
         UnityEngine.Touch ret = UnityEngine.Input.GetTouch(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Example #18
0
        internal void SetWithTouchData(UnityEngine.Touch touch, ulong updateTick, float deltaTime)
        {
            phase       = touch.phase;
            tapCount    = touch.tapCount;
            mouseButton = 0;

                        #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
            type                    = TouchType.Direct;
            altitudeAngle           = Mathf.PI / 2.0f;
            azimuthAngle            = Mathf.PI / 2.0f;
            maximumPossiblePressure = 1.0f;
            pressure                = 1.0f;
            radius                  = 1.0f;
            radiusVariance          = 0.0f;
                        #else
            altitudeAngle           = touch.altitudeAngle;
            azimuthAngle            = touch.azimuthAngle;
            maximumPossiblePressure = touch.maximumPossiblePressure;
            pressure       = touch.pressure;
            radius         = touch.radius;
            radiusVariance = touch.radiusVariance;
                        #endif

            var touchPosition = touch.position;
            touchPosition.x = Mathf.Clamp(touchPosition.x, 0.0f, Screen.width);
            touchPosition.y = Mathf.Clamp(touchPosition.y, 0.0f, Screen.height);

            if (phase == TouchPhase.Began)
            {
                startPosition = touchPosition;
                deltaPosition = Vector2.zero;
                lastPosition  = touchPosition;
                position      = touchPosition;
            }
            else
            {
                if (phase == TouchPhase.Stationary)
                {
                    phase = TouchPhase.Moved;
                }

                deltaPosition = touchPosition - lastPosition;
                lastPosition  = position;
                position      = touchPosition;
            }

            this.deltaTime  = deltaTime;
            this.updateTick = updateTick;
        }
    void Update()
    {
        if (Input.touchCount > 0)
        {
            UnityEngine.Touch touch = Input.GetTouch(0);
            currentPosition = touch.position;
        }

        alpha = Mathf.Clamp(alpha, 0, 1);
        Vector2 filteredPosition = alpha * currentPosition + (1 - alpha) * previousFilteredPosition;

        previousFilteredPosition = filteredPosition;

        transform.position = Camera.main.ScreenToWorldPoint(new Vector3(filteredPosition.x, filteredPosition.y, 8));
    }
Example #20
0
		public void Update(Touch touch)
		{
			this.stateTime += touch.deltaTime;
			this.pos = touch.position;
			this.deltaPos = touch.deltaPosition;
			this.totalVec += this.DeltaPos;
			this.totalTime += touch.deltaTime;

			TouchState state = TouchStateUtil.PhaseToState(touch.phase);
			if (this.state != state)
			{
				this.state = state;
				this.stateTime = touch.deltaTime;
			}
		}
Example #21
0
 static int GetTouch(IntPtr L)
 {
     try
     {
         int arg0            = (int)LuaDLL.luaL_checknumber(L, 1);
         int arg1            = LuaDLL.luaL_optinteger(L, 2, TouchBits.ALL);
         UnityEngine.Touch o = UnityEngine.Input.GetTouch(arg0);
         ToLua.Push(L, o, arg1);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #22
0
 public void SendTouchInput()
 {
     for (int i = 0; i < Input.touchCount; ++i)
     {
         UnityEngine.Touch touch = Input.GetTouch(i);
         writer.BeginMessage(RemoteMessage.TouchInput);
         writer.Write(touch.position.x);
         writer.Write(touch.position.y);
         writer.Write((long)Time.frameCount);
         writer.Write(touch.fingerId);
         writer.Write((int)touch.phase);
         writer.Write((int)touch.tapCount);
         writer.EndMessage(stream);
     }
 }
 static int GetTouch(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         int arg0            = (int)LuaDLL.luaL_checknumber(L, 1);
         UnityEngine.Touch o = UnityEngine.Input.GetTouch(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #24
0
        public TKLTouch populateWithTouch( Touch touch )
        {
            position = touch.position;
            deltaPosition = touch.deltaPosition;
            deltaTime = touch.deltaTime;
            tapCount = touch.tapCount;

            // canceled and ended are the same to us
            if( touch.phase == TouchPhase.Canceled )
            phase = TouchPhase.Ended;
            else
            phase = touch.phase;

            return this;
        }
 static int QPYX_GetTouch_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_arg0_YXQP  = (int)LuaDLL.luaL_checknumber(L_YXQP, 1);
         int QPYX_arg1_YXQP  = LuaDLL.luaL_optinteger(L_YXQP, 2, TouchBits.ALL);
         UnityEngine.Touch o = UnityEngine.Input.GetTouch(QPYX_arg0_YXQP);
         ToLua.Push(L_YXQP, o, QPYX_arg1_YXQP);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L_YXQP, e));
     }
 }
    //=========================
    // 更新処理
    //=========================
    void Update()
    {
        this.IsTouch = false;

        // マウス操作(エディタ上)
        if (Application.isEditor)
        {
            // 押した瞬間
            if (Input.GetMouseButtonDown(0))
            {
                this.IsTouch = true;
                this.Phase   = TouchPhase.Began;
                Debug.Log("押した瞬間");
            }
            // 離した瞬間
            else if (Input.GetMouseButtonUp(0))
            {
                this.IsTouch = true;
                this.Phase   = TouchPhase.Ended;
                Debug.Log("離した瞬間");
            }
            // 押しっぱなし
            else if (Input.GetMouseButton(0))
            {
                this.IsTouch = true;
                this.Phase   = TouchPhase.Moved;
                Debug.Log("押しっぱなし");
            }

            // 座標取得
            if (this.IsTouch)
            {
                this.TouchPos = Input.mousePosition;
            }
        }
        // 実機(スマホ)使用時
        else
        {
            if (Input.touchCount > 0)
            {
                UnityEngine.Touch touch = Input.GetTouch(0);

                this.TouchPos = touch.position;
                this.Phase    = touch.phase;
                this.IsTouch  = true;
            }
        }
    }
Example #27
0
 public static int GetTouch_wrap(long L)
 {
     try
     {
         int arg0 = FCLibHelper.fc_get_int(L, 0);
         UnityEngine.Touch ret = UnityEngine.Input.GetTouch(arg0);
         long ret_ptr          = FCLibHelper.fc_get_return_ptr(L);
         long v = FCGetObj.PushObj(ret);
         FCLibHelper.fc_set_value_wrap_objptr(ret_ptr, v);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
        private void CheckTouch(Touch touch)
        {
            Vector3 v3;

            #if UNITY_EDITOR
            var pos = Input.mousePosition;
            #else
            var pos = touch.position;
            #endif //UNITY_EDITOR

            if (EditorInput.GetState(touch, EditorInput.InputState.Began))
            {
                Dragging = false;
                _prisonerTransform = null;

                RaycastHit hit;
                var ray = Camera.main.ScreenPointToRay(pos);

                if (Physics.Raycast(ray, out hit))
                {
                    _prisonerAi = hit.collider.GetComponent<PrisonerAi>();

                    if (_prisonerAi == null) return;

                    _prisonerTransform = hit.transform;
                    _prisonerAi.Rigidbody.isKinematic = true;
                    _dist = hit.transform.position.z - Camera.main.transform.position.z;
                    v3 = new Vector3(pos.x, pos.y, _dist);
                    v3 = Camera.main.ScreenToWorldPoint(v3);
                    _offset = _prisonerTransform.position - v3;
                    Dragging = true;
                }
            }
            if (Dragging && EditorInput.GetState(touch, EditorInput.InputState.Moving))
            {
                v3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, _dist);
                v3 = Camera.main.ScreenToWorldPoint(v3);
                if (_prisonerTransform != null) _prisonerTransform.position = v3 + _offset;
            }
            if (Dragging &&
                (EditorInput.GetState(touch, EditorInput.InputState.Ended) ||
                 EditorInput.GetState(touch, EditorInput.InputState.Canceled)))
            {
                Dragging = false;
                _objectPool.SetAllFree();
            }
        }
    static int GetTouch(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.Input.GetTouch");
#endif
        try
        {
            int arg0            = (int)LuaDLL.luaL_checknumber(L, 1);
            int arg1            = LuaDLL.luaL_optinteger(L, 2, TouchBits.ALL);
            UnityEngine.Touch o = UnityEngine.Input.GetTouch(arg0);
            ToLua.Push(L, o, arg1);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #30
0
 public override void GetInputState(int fingerIndex, out bool down, out Vector2 position)
 {
     down     = false;
     position = Vector2.zero;
     if (HasValidTouch(fingerIndex))
     {
         UnityEngine.Touch touch = GetTouch(fingerIndex);
         if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
         {
             down = false;
         }
         else
         {
             down     = true;
             position = touch.position;
         }
     }
 }
Example #31
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.Touch touch = (UnityEngine.Touch)value;
     writer.WriteProperty("fingerId", touch.fingerId);
     writer.WriteProperty("position", touch.position);
     writer.WriteProperty("rawPosition", touch.rawPosition);
     writer.WriteProperty("deltaPosition", touch.deltaPosition);
     writer.WriteProperty("deltaTime", touch.deltaTime);
     writer.WriteProperty("tapCount", touch.tapCount);
     writer.WriteProperty("phase", touch.phase);
     writer.WriteProperty("pressure", touch.pressure);
     writer.WriteProperty("maximumPossiblePressure", touch.maximumPossiblePressure);
     writer.WriteProperty("type", touch.type);
     writer.WriteProperty("altitudeAngle", touch.altitudeAngle);
     writer.WriteProperty("azimuthAngle", touch.azimuthAngle);
     writer.WriteProperty("radius", touch.radius);
     writer.WriteProperty("radiusVariance", touch.radiusVariance);
 }
 protected PointerEventData GetTouchPointerEventData(Touch input, out bool pressed, out bool released)
 {
   PointerEventData data;
   bool pointerData = this.GetPointerData(input.fingerId, out data, true);
   data.Reset();
   pressed = pointerData || input.phase == TouchPhase.Began;
   released = input.phase == TouchPhase.Canceled || input.phase == TouchPhase.Ended;
   if (pointerData)
     data.position = input.position;
   data.delta = !pressed ? input.position - data.position : Vector2.zero;
   data.position = input.position;
   data.button = PointerEventData.InputButton.Left;
   this.eventSystem.RaycastAll(data, this.m_RaycastResultCache);
   RaycastResult firstRaycast = BaseInputModule.FindFirstRaycast(this.m_RaycastResultCache);
   data.pointerCurrentRaycast = firstRaycast;
   this.m_RaycastResultCache.Clear();
   return data;
 }
Example #33
0
        /// <summary>多点触碰</summary>
        public void MultiTouch()
        {
            UnityEngine.Touch newTouch1 = Input.GetTouch(0);
            UnityEngine.Touch newTouch2 = Input.GetTouch(1);

            //第2点刚开始接触屏幕, 只记录,不做处理
            if (newTouch2.phase == TouchPhase.Began)
            {
                oldTouch2 = newTouch2;
                oldTouch1 = newTouch1;
                return;
            }

            //计算老的两点距离和新的两点间距离,变大要放大模型,变小要缩放模型
            float oldDistance = Vector2.Distance(oldTouch1.position, oldTouch2.position);
            float newDistance = Vector2.Distance(newTouch1.position, newTouch2.position);

            oldDis = oldDistance;
            newDis = newDistance;

            //两个距离之差,为正表示放大手势, 为负表示缩小手势
            float offset = newDistance - oldDistance;

            //放大因子, 一个像素按 0.01倍来算(100可调整)
            float   scaleFactor = offset / 100f;
            Vector3 localScale  = transform.localScale;
            Vector3 scale       = new Vector3(localScale.x + scaleFactor,
                                              localScale.y + scaleFactor,
                                              localScale.z + scaleFactor);

            scaler = scaleFactor;

            //允许模型最小缩放到 minMultiple倍,最大放大maxMultiple
            if (scale.x > minMultiple && scale.y > minMultiple && scale.z > minMultiple)
            {
                //实用差值运算,模型平滑缩放
                transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(Mathf.Clamp(localScale.x + scaleFactor, minMultiple, maxMultiple),
                                                                                      Mathf.Clamp(localScale.y + scaleFactor, minMultiple, maxMultiple),
                                                                                      Mathf.Clamp(localScale.z + scaleFactor, minMultiple, maxMultiple)), 1f);
            }
            //记住最新的触摸点,下次使用
            oldTouch1 = newTouch1;
            oldTouch2 = newTouch2;
        }
Example #34
0
        public void setPhase(Touch touch)
        {
            if (!Enabled) return;

            switch (touch.phase)
            {
                case TouchPhase.Began:
                    IsTouched = true;
                    break;

                case TouchPhase.Moved:
                    IsTouched = false;
                    break;

                case TouchPhase.Ended:
                    if(IsTouched) SelectedGameObject = DetectTouchOnGameObject(touch);
                    break;
            }
        }
Example #35
0
        public static TouchEntity Pop()
        {
            List <Vector3> positionList = new List <Vector3>();
            TouchPhase     phase        = TouchPhase.Canceled;

            if (RuntimePlatform.OSXEditor == Application.platform)
            {
                if (false != Input.GetMouseButtonDown(0))
                {
                    positionList.Add(Input.mousePosition);
                    phase = TouchPhase.Began;
                }
                else if (false != Input.GetMouseButton(0))
                {
                    positionList.Add(Input.mousePosition);
                    phase = TouchPhase.Moved;
                }
                if (false != Input.GetMouseButtonUp(0))
                {
                    positionList.Add(Input.mousePosition);
                    phase = TouchPhase.Ended;
                }
            }
            else if (RuntimePlatform.IPhonePlayer == Application.platform || RuntimePlatform.Android == Application.platform)
            {
                bool recognizedTouchPhase = false;
                for (int i = 0; i < Input.touchCount; i++)
                {
                    UnityEngine.Touch touch = Input.GetTouch(i);
                    positionList.Add(touch.position);
                    if (false == recognizedTouchPhase)
                    {
                        phase = touch.phase;
                        recognizedTouchPhase = true;
                    }
                }
            }
            TouchEntity entity = new TouchEntity();

            entity.touchPhase        = phase;
            entity.touchPositionList = positionList;
            return(entity);
        }
Example #36
0
    private void Update()
    {
        if (Input.touchCount < 2 && Input.touchCount != 0)
        {
            camTransform.position += ((Vector3)(-bufferVector / 6) * Time.deltaTime * speedModifier);
        }
        if (canMouse)
        {
            MouseMoveCamera(mouseBufferVector / 6);
        }

        if (Input.touchCount >= 2)
        {
            Touch touch = Input.GetTouch(1);
            if (!canPinch)
            {
                t1Pos           = Input.GetTouch(0).position / screenSize;
                t2Pos           = Input.GetTouch(1).position / screenSize;
                initialDistance = Vector3.Distance(t1Pos, t2Pos);
                initialSize     = cam.orthographicSize;
                canPinch        = true;
            }
            else
            {
                if (touch.phase == TouchPhase.Moved)
                {
                    t1Pos                = Input.GetTouch(0).position / screenSize;
                    t2Pos                = Input.GetTouch(1).position / screenSize;
                    bufferDistance       = (Vector2.Distance(t1Pos, t2Pos) - initialDistance) * pinchVelocity;
                    cam.orthographicSize = initialSize - bufferDistance;
                    sText.SetText(bufferDistance.ToString());
                }
            }
        }
        else
        {
            canPinch = false;
            if (sText)
            {
                sText.SetText("NOT PINCHING");
            }
        }
    }
Example #37
0
		void updateInfo(ref Touch touch)
		{
			TouchInfo info;
			if (!infos.TryGetValue(touch.fingerId, out info))
			{
				info = new TouchInfo(touch);
				infos.Add(info.FingerID, info);
			}

			if (touch.phase == TouchPhase.Began)
			{
				info.Init(touch);
			}
			else
			{
				info.Update(touch);
			}

			taskList.Add(info);
		}
Example #38
0
 public static UnityEngine.Touch[] GetArray(ref UnityEngine.Touch[] rList, long L, int nIndex)
 {
     try
     {
         long ptr        = FCLibHelper.fc_get_param_ptr(L, nIndex);
         int  nArraySize = FCLibHelper.fc_get_array_size(ptr);
         rList = new UnityEngine.Touch[nArraySize];
         for (int i = 0; i < nArraySize; ++i)
         {
             long item_ptr          = FCLibHelper.fc_get_array_node_temp_ptr(ptr, i);
             UnityEngine.Touch item = FCGetObj.GetObj <UnityEngine.Touch>(item_ptr);
             rList[i] = item;
         }
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(rList);
 }
Example #39
0
 public Vector3 GetTouchPos()
 {
     if (Application.isEditor)
     {
         if (GetTouch() != None)
         {
             return(Input.mousePosition);
         }
     }
     else
     {
         if (Input.touchCount > 0)
         {
             UnityEngine.Touch touch = Input.GetTouch(0);
             touchPos   = touch.position;
             touchPos.z = 0;
             return(touchPos);
         }
     }
     return(Vector3.zero);
 }
Example #40
0
        private void DispatchInput(UnityEngine.Touch touch)
        {
            if (InputEvent != null)
            {
                inputArgs.position = touch.position;

                inputArgs.dragVelocity = touch.deltaPosition;

                inputArgs.fingerId = touch.fingerId;

                inputArgs.touchPhase = touch.phase;

                inputArgs.tapCount = touch.tapCount;

                inputArgs.holdTime = touch.deltaTime;

                Log("Touch Input Event {0}", inputArgs);

                InputEvent(this, inputArgs);
            }
        }
Example #41
0
 void Update()
 {
     if (!paused)
     {
         if (platform == RuntimePlatform.WindowsEditor || platform == RuntimePlatform.WindowsPlayer)
         {
             if (Input.GetMouseButtonDown(0))
             {
                 GetObject(Input.mousePosition, MouseState.Down);
             }
             else if (Input.GetMouseButton(0))
             {
                 GetObject(Input.mousePosition, MouseState.Drag);
             }
             else if (Input.GetMouseButtonUp(0))
             {
                 GetObject(Input.mousePosition, MouseState.Up);
             }
         }
         else if (platform == RuntimePlatform.Android)
         {
             if (Input.touchCount > 0)
             {
                 touch = Input.GetTouch(0);
                 if (touch.phase == TouchPhase.Began)
                 {
                     GetObject(touch.position, MouseState.Down);
                 }
                 else if (touch.phase == TouchPhase.Moved)
                 {
                     GetObject(touch.position, MouseState.Drag);
                 }
                 else if (touch.phase == TouchPhase.Ended)
                 {
                     GetObject(touch.position, MouseState.Up);
                 }
             }
         }
     }
 }
Example #42
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            UnityEngine.Touch touch = Input.GetTouch(0);
            Vector3           touchPos;
            Ray        ray;
            RaycastHit hit;
            switch (touch.phase)
            {
            case TouchPhase.Began:
                Vector3 touchPosToVector3 = new Vector3(touch.position.x, touch.position.y, 100);
                touchPos = Camera.main.ScreenToWorldPoint(touchPosToVector3);
                ray      = Camera.main.ScreenPointToRay(touchPosToVector3);
                break;

            case TouchPhase.Ended:
                Onoff.onoff = true; break;

            default: break;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            UnityEngine.Touch touch     = Input.GetTouch(0);
            Vector3           touch_Pos = Camera.main.ScreenToWorldPoint(touch.position);


            if (touch_Pos.x > 0)
            {
                PlayerMove.MoveRight();
            }
            else if (touch_Pos.x < 0)
            {
                PlayerMove.MoveLeft();
            }

            else
            {
                PlayerMove.StopMoving();
            }
        }
    }
    private void UpdateTouch()
    {
        for (int i = 0; i < UnityEngine.Input.touchCount; i++)
        {
            UnityEngine.Touch touch = UnityEngine.Input.GetTouch(i);
            uint id = (uint)touch.fingerId;
            UnityEngine.Vector2    pos   = ProjectPointer(touch.position.x, touch.position.y);
            UnityEngine.TouchPhase phase = touch.phase;

            if (phase == UnityEngine.TouchPhase.Began)
            {
                _uiView.TouchDown((int)pos.x, (int)pos.y, id);
            }
            else if (phase == UnityEngine.TouchPhase.Moved || phase == UnityEngine.TouchPhase.Stationary)
            {
                _uiView.TouchMove((int)pos.x, (int)pos.y, id);
            }
            else
            {
                _uiView.TouchUp((int)pos.x, (int)pos.y, id);
            }
        }
    }
Example #45
0
        public void setPhase(Touch touch)
        {
            if (!Enabled) return;

            switch (touch.phase)
            {
                case TouchPhase.Began:
                    BeganPosition = touch.position;
                    Phase = touch.phase;
                    break;

                case TouchPhase.Ended:
                    if (Phase != TouchPhase.Began) break;
                    EndPosition = touch.position;
                    float Goal = Mathf.Abs(BeganPosition.x - EndPosition.x);
                    if (Goal >= Distance) Move = true;
                    break;

                case TouchPhase.Canceled:

                    break;
            }
        }
Example #46
0
        public UTouch UpdateFromTouch(UnityEngine.Touch touch)
        {
            position      = touch.position;
            deltaPosition = touch.deltaPosition;
            deltaTime     = touch.deltaTime;
            tapCount      = touch.tapCount;

            if (touch.phase == TouchPhase.Began)
            {
                startPosition = touch.position;
            }

            if (touch.phase == TouchPhase.Canceled)
            {
                phase = TouchPhase.Ended;
            }
            else
            {
                phase = touch.phase;
            }

            return(this);
        }
Example #47
0
        private void HandleTouch()
        {
            if (Input.touchCount == 1)
            {
                UnityEngine.Touch touch = Input.GetTouch(0);
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    isMoving = !UIExtensions.IsClickingOverUI(touch.position, uiMasks);
                    if (isMoving)
                    {
                        lastObject = FindNearestObject(touch.position);
                        onMouseDown?.Invoke(touch.position, lastObject);
                    }

                    break;

                case TouchPhase.Moved:
                    if (!isMoving)
                    {
                        return;
                    }

                    onMouseDrag?.Invoke(touch.position, lastObject);
                    break;

                case TouchPhase.Ended:
                    isMoving = false;
                    if (lastObject != null)
                    {
                        onMouseUp?.Invoke(touch.position, lastObject);
                    }

                    break;
                }
            }
        }
        private void OnInputSourceUpdate()
        {
            //Debug.Log( "InputManager.OnInputSourceUpdate()" );

            for( var _index = 0; _index < ReInput.touch.touchCount; _index++ )
            {
                // Get the Touch
                touch = ReInput.touch.GetTouch( _index );

                // Translate touch positoin(pixels) to screen position(0, 1)
                viewportPoint = camera.ScreenToViewportPoint( touch.position );

                // See if the rect contains the point
                if ( rect.Contains( viewportPoint ) )
                {
                    // Set the value on the controller
                    controller.SetButtonValue( (int)button, true );
                    return;
                }
            }

            // If the mouse is down then process the mouse
            if ( ReInput.controllers.Mouse.GetButtonDown( 0 ) )
            {
                viewportPoint = camera.ScreenToViewportPoint( ReInput.controllers.Mouse.screenPosition );

                // See if the rect contains the point
                if ( rect.Contains( viewportPoint ) )
                {
                    // Set the value on the controller
                    controller.SetButtonValue( (int)button, true );
                    return;
                }
            }
        
            controller.SetButtonValue( (int)button, false );
        }
        // ---------------
        private void UpdateTouchPressure()
        {
#if !UNITY_PRE_5_3
            if (UnityEngine.Input.touchPressureSupported)
            {
                for (int i = 0; i < UnityEngine.Input.touchCount; ++i)
                {
                    UnityEngine.Touch t = UnityEngine.Input.GetTouch(i);
                    if ((t.phase == TouchPhase.Canceled) || (t.phase == TouchPhase.Ended))
                    {
                        continue;
                    }

                    SystemTouch st = this.FindTouch(t.fingerId);
                    if (st == null)
                    {
                        continue;
                    }

                    st.touch.SetPressure(t.pressure, t.maximumPossiblePressure);
                }
            }
#endif
        }
        void DoTouch(Touch touch)
        {
            // Filter by finger ID

            if (fingerId.IsNone || touch.fingerId == fingerId.Value)
            {
                // Get the screen position of the touch

                Vector3 touchPos = touch.position;

                // Is touchPos inside the guiElement's rect

                if (guiElement.HitTest(touchPos))
                {
                    // First touch?

                    if (touch.phase == TouchPhase.Began)
                    {
                        touchStartPos = touchPos;
                    }

                    // Store results

                    storeFingerId.Value = touch.fingerId;

                    if (normalizeHitPoint.Value)
                    {
                        touchPos.x /= Screen.width;
                        touchPos.y /= Screen.height;
                    }

                    storeHitPoint.Value = touchPos;

                    // Store touch offset

                    DoTouchOffset(touchPos);

                    // Send Events

                    switch (touch.phase)
                    {
                        case TouchPhase.Began:
                            Fsm.Event(touchBegan);
                            return;

                        case TouchPhase.Moved:
                            Fsm.Event(touchMoved);
                            return;

                        case TouchPhase.Stationary:
                            Fsm.Event(touchStationary);
                            return;

                        case TouchPhase.Ended:
                            Fsm.Event(touchEnded);
                            return;

                        case TouchPhase.Canceled:
                            Fsm.Event(touchCanceled);
                            return;
                    }
                }
                else
                {
                    Fsm.Event(notTouching);
                }
            }
        }
Example #51
0
 protected PointerEventData GetTouchPointerEventData(Touch input, out bool pressed, out bool released)
 {
     PointerEventData data;
     bool flag = this.GetPointerData(input.fingerId, out data, true);
     data.Reset();
     pressed = flag || (input.phase == TouchPhase.Began);
     released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);
     if (flag)
     {
         data.position = input.position;
     }
     if (pressed)
     {
         data.delta = Vector2.zero;
     }
     else
     {
         data.delta = input.position - data.position;
     }
     data.position = input.position;
     data.button = PointerEventData.InputButton.Left;
     base.eventSystem.RaycastAll(data, base.m_RaycastResultCache);
     RaycastResult result = BaseInputModule.FindFirstRaycast(base.m_RaycastResultCache);
     data.pointerCurrentRaycast = result;
     base.m_RaycastResultCache.Clear();
     return data;
 }
Example #52
0
 public void Push(Touch t)
 {
     try
     {
         luaState.Push(t);
         ++argCount;
     }
     catch (Exception e)
     {
         EndPCall();
         throw e;
     }
 }
Example #53
0
 public ScreenInput(Touch touch)
 {
     Init(touch.position, touch.phase, touch.fingerId);
 }
Example #54
0
        void TestForSwipeGesture(Touch touch)
        {
            // test min distance

            var lastPos = touch.position;
            var distance = Vector2.Distance(lastPos, touchStartPos);

            if (distance > minSwipeDistancePixels)
            {
                float dy = lastPos.y - touchStartPos.y;
                float dx = lastPos.x - touchStartPos.x;

                float angle = Mathf.Rad2Deg * Mathf.Atan2(dx, dy);

                angle = (360 + angle - 45) % 360;

                Debug.Log (angle);

                if (angle < 90)
                {
                    Fsm.Event(swipeRightEvent);
                }
                else if (angle < 180)
                {
                    Fsm.Event(swipeDownEvent);
                }
                else if (angle < 270)
                {
                    Fsm.Event(swipeLeftEvent);
                }
                else
                {
                    Fsm.Event(swipeUpEvent);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of TouchEventArgs.
 /// </summary>
 /// <param name="touch">The touch.</param>
 public TouchEventArgs(Touch touch) {
     this.Touch = touch;
 }
Example #56
0
        // JoyTouchManagment
        private void JoyTouchManagment( Touch touch, UMJ_Joystick Joystick )
        {
            switch( touch.phase )
            {
                case TouchPhase.Began:

                    if( Joystick.CheckPosition( touch.position ) && !Joystick.TouchDown )
                    {
                        Joystick.TouchID = touch.fingerId;
                        Joystick.TouchDown = true;
                        Joystick.GetDefaultPosition( touch.position );
                    }

                    break;

                case TouchPhase.Stationary:
                case TouchPhase.Moved:

                    if( Joystick.TouchID == touch.fingerId && Joystick.TouchDown )
                    {
                        Joystick.GetCurrentPosition( touch.position );
                    }

                    break;

                case TouchPhase.Ended:
                case TouchPhase.Canceled:

                    if( Joystick.TouchID == touch.fingerId )
                    {
                        Joystick.ResetJoystickPosition();
                    }

                    break;
            }
        }
Example #57
0
		private void OnTouchEnd(Touch touch) { }
Example #58
0
		private void OnTouchMove(Touch touch) { }
Example #59
0
		private void OnTouchStay(Touch touch) { }
Example #60
0
		private void OnTouchBegin(Touch touch) {
		
		}