コード例 #1
0
ファイル: InputHelper.cs プロジェクト: KXue/GuitarDemo
 private void Update()
 {
     if (Input.GetMouseButtonDown(1))
     {
         TouchCreator newHold = new TouchCreator();
         newHold.phase         = TouchPhase.Moved;
         newHold.deltaPosition = new Vector2(0, 0);
         newHold.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
         newHold.fingerId      = ++holdID;
         holds.Add(newHold.Create());
     }
     if (Input.GetButton("Clear"))
     {
         foreach (Touch item in holds)
         {
             TouchCreator newRelease = new TouchCreator();
             newRelease.phase         = TouchPhase.Ended;
             newRelease.deltaPosition = item.deltaPosition;
             newRelease.position      = item.position;
             newRelease.fingerId      = item.fingerId;
             releases.Add(newRelease.Create());
         }
         holds.Clear();
     }
 }
コード例 #2
0
ファイル: TouchCreator.cs プロジェクト: allfa/Reborn
 public static TouchCreator GetTouchCreator()
 {
     if (tc == null)
     {
         tc = new TouchCreator();
     }
     return(tc);
 }
コード例 #3
0
    public static List <Touch> GetTouches()
    {
        touches.Clear();
        touches.AddRange(Input.touches);
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            if (lastFakeTouch == null)
            {
                lastFakeTouch = new TouchCreator();
            }

            lastFakeTouch.phase         = TouchPhase.Began;
            lastFakeTouch.deltaPosition = new Vector2(0, 0);
            lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.fingerId      = 0;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (lastFakeTouch == null)
            {
                lastFakeTouch = new TouchCreator();
            }

            lastFakeTouch.phase = TouchPhase.Ended;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
        }
        else if (Input.GetMouseButton(0))
        {
            if (lastFakeTouch == null)
            {
                lastFakeTouch = new TouchCreator();
            }

            //lastFakeTouch.phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.phase         = TouchPhase.Moved;            //lastFakeTouch.deltaPosition.magnitude == 0 ? TouchPhase.Stationary : TouchPhase.Moved;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
        }
        else
        {
            lastFakeTouch = null;
        }
        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch.Create());
        }
#endif

        return(touches);
    }
コード例 #4
0
ファイル: InputHelper.cs プロジェクト: xartishuk/StickFall
    public static List <Touch> GetTouches()
    {
        PointerEventData pe = new PointerEventData(EventSystem.current);

        List <Touch> touches = new List <Touch>();

        if (pe.selectedObject == null)
        {
            touches.AddRange(Input.touches);
#if UNITY_EDITOR
            if (lastFakeTouch == null)
            {
                lastFakeTouch = new TouchCreator();
            }
            if (Input.GetMouseButtonDown(0))
            {
                lastFakeTouch.phase         = TouchPhase.Began;
                lastFakeTouch.deltaPosition = new Vector2(0, 0);
                lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                lastFakeTouch.fingerId      = 0;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                lastFakeTouch.phase = TouchPhase.Ended;
                Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
                lastFakeTouch.position      = newPosition;
                lastFakeTouch.fingerId      = 0;
            }
            else if (Input.GetMouseButton(0))
            {
                lastFakeTouch.phase = TouchPhase.Moved;
                Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
                lastFakeTouch.position      = newPosition;
                lastFakeTouch.fingerId      = 0;
            }
            else
            {
                lastFakeTouch = null;
            }
            if (lastFakeTouch != null)
            {
                touches.Add(lastFakeTouch.Create());
            }
#endif
        }


        return(touches);
    }
コード例 #5
0
    public static List <Touch> GetTouches()
    {
        List <Touch> touches = new List <Touch>();

        touches.AddRange(Input.touches);

        // Uncomment if you want it only to allow mouse swipes in the Unity Editor
        //#if UNITY_EDITOR
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new TouchCreator();
        }

        if (Input.GetMouseButtonDown(0))
        {
            lastFakeTouch.Phase         = TouchPhase.Began;
            lastFakeTouch.DeltaPosition = new Vector2(0, 0);
            lastFakeTouch.Position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.FingerId      = 0;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lastFakeTouch.Phase = TouchPhase.Ended;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.DeltaPosition = newPosition - lastFakeTouch.Position;
            lastFakeTouch.Position      = newPosition;
            lastFakeTouch.FingerId      = 0;
        }
        else if (Input.GetMouseButton(0))
        {
            lastFakeTouch.Phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.DeltaPosition = newPosition - lastFakeTouch.Position;
            lastFakeTouch.Position      = newPosition;
            lastFakeTouch.FingerId      = 0;
        }
        else
        {
            lastFakeTouch = null;
        }

        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch.Create());
        }
        // Uncomment if you want it only to allow mouse swipes in the Unity Editor
        //#endif

        return(touches);
    }
コード例 #6
0
        public Touch[] GetTouches()
        {
            List <Touch> touches = new List <Touch>();

            touches.AddRange(Input.touches);
#if UNITY_EDITOR
            if (!Input.touchSupported)
            {
                if (lastFakeTouch == null)
                {
                    lastFakeTouch = new TouchCreator();
                }
                if (Input.GetMouseButtonDown(0))
                {
                    lastFakeTouch.phase         = TouchPhase.Began;
                    lastFakeTouch.deltaPosition = new Vector2(0, 0);
                    lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    lastFakeTouch.fingerId      = 0;
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    lastFakeTouch.phase = TouchPhase.Ended;
                    Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
                    lastFakeTouch.position      = newPosition;
                    lastFakeTouch.fingerId      = 0;
                }
                else if (Input.GetMouseButton(0))
                {
                    lastFakeTouch.phase = TouchPhase.Moved;
                    Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
                    lastFakeTouch.position      = newPosition;
                    lastFakeTouch.fingerId      = 0;
                }
                else
                {
                    lastFakeTouch = null;
                }
                if (lastFakeTouch != null)
                {
                    touches.Add(lastFakeTouch.Create());
                }
            }
#endif
            return(touches.ToArray());
        }
コード例 #7
0
ファイル: TouchHandler.cs プロジェクト: pan-pawka/Unity-Touch
 void Start()
 {
     screenPixelsPerCm = Screen.dpi;         //initialize
     _measureUnits     = measureUnits;
     _tapTimeout       = tapTimeout;
     _longPressTime    = longPressTime;
     _dragThreshold    = UnitsToPixels(dragThreshold);
     _swipeThreshold   = swipeThreshold;
     tc[0]             = new TouchCreator();
     tc[1]             = new TouchCreator();
     fakeTouch         = tc[0].CreateEmpty();
     simulatePinch     = tc[1].CreateEmpty();
     if (Input.touchSupported && Input.multiTouchEnabled)
     {
         simulateTouchWithMouse = false;
     }
 }
コード例 #8
0
    public static List<Touch> GetTouches()
    {
        List<Touch> touches = new List<Touch>();
        touches.AddRange(Input.touches);

#if UNITY_EDITOR
         if(lastFakeTouch == null) lastFakeTouch = new TouchCreator();

         if(Input.GetMouseButtonDown(0))
         {
             lastFakeTouch.phase = TouchPhase.Began;
             lastFakeTouch.deltaPosition = new Vector2(0,0);
             lastFakeTouch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
             lastFakeTouch.fingerId = 0;
         }
         else if (Input.GetMouseButtonUp(0))
         {
             lastFakeTouch.phase = TouchPhase.Ended;
             Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
             lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
             lastFakeTouch.position = newPosition;
             lastFakeTouch.fingerId = 0;
         }
         else if (Input.GetMouseButton(0))
         {
             lastFakeTouch.phase = TouchPhase.Moved;
             Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
             lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;

             if (lastFakeTouch.deltaPosition.magnitude <= 0.05f)
                lastFakeTouch.phase = TouchPhase.Stationary;

             lastFakeTouch.position = newPosition;
             lastFakeTouch.fingerId = 0;
         }
         else
         {
             lastFakeTouch = null;
         }

         if (lastFakeTouch != null) touches.Add(lastFakeTouch.Create());
#endif
        
        return touches;
    }
コード例 #9
0
    // Simulate mouse input as touches
    public static List<Touch> GetTouches()
    {
        List<Touch> touches = new List<Touch>();
        touches.AddRange(Input.touches);
#if UNITY_EDITOR
        if (lastFakeTouch == null) lastFakeTouch = new TouchCreator();
        if (Input.GetMouseButtonDown(0))
        {
            lastFakeTouch.phase = TouchPhase.Began;
            lastFakeTouch.deltaPosition = new Vector2(0, 0);
            lastFakeTouch.deltaTime = Time.deltaTime;
            lastFakeTouch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.fingerId = -123;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lastFakeTouch.phase = TouchPhase.Ended;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.deltaTime = Time.deltaTime;
            lastFakeTouch.position = newPosition;
            lastFakeTouch.fingerId = -123;
        }
        else if (Input.GetMouseButton(0))
        {
            lastFakeTouch.phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.deltaTime = Time.deltaTime;
            lastFakeTouch.position = newPosition;
            lastFakeTouch.fingerId = -123;
        }
        else
        {
            lastFakeTouch = null;
        }
        if (lastFakeTouch != null) touches.Add(lastFakeTouch.Create());
#endif


        return touches;
    }
コード例 #10
0
ファイル: MyJoystick.cs プロジェクト: allfa/Reborn
    void Update()
    {
        //if (initialTouch)
        //return;
        List <Touch> tList = new List <Touch> ();

        tList.AddRange(Input.touches);
        if (tList.Count == 0)
        {
            Touch t = TouchCreator.GetTouchCreator().Create();
            if (t.fingerId == 10)
            {
                tList.Add(t);
            }
        }
        foreach (Touch temp in tList)
        {
            //Debug.Log("ID: "+ temp.fingerId + " phase: "+temp.phase);
            if (temp.fingerId == initialTouch.fingerId)
            {
                //codigo principal
                switch (temp.phase)
                {
                case TouchPhase.Ended:
                    Destroy(gameObject);
                    break;

                case TouchPhase.Moved:
                    Vector3 pos   = toWorld(temp.position);
                    Vector3 pdiff = pos - transform.position;
                    inner.localPosition = Vector3.MoveTowards(Vector3.zero, pdiff, 1);
                    //inner.localPosition = limitVar(pdiff, 1);

                    break;

                default:
                    //Debug.Log("Joystick TouchPhase:" + temp.phase + " ignored.");
                    break;
                }
            }
        }
    }
コード例 #11
0
    void Update()
    {
        TouchCreator fakeTouch = TouchCreator.GetTouchCreator();

        fakeTouch.deltaPosition = (Vector2)Input.mousePosition - (Vector2)fakeTouch.position;
        fakeTouch.position      = Input.mousePosition;
        fakeTouch.deltaTime     = Time.deltaTime;
        if (Input.GetMouseButton(0))
        {
            if (fakeTouch.fingerId == 10)
            {
                //Debug.Log ("On Click");
                fakeTouch.phase =
                    (fakeTouch.deltaPosition.sqrMagnitude > 1f ?
                     TouchPhase.Moved : TouchPhase.Stationary);
                //fakeTouch.tapCount += 1;
            }
        }
        else if (fakeTouch.phase == TouchPhase.Ended)
        {
            fakeTouch.fingerId = 0;
        }

        if (Input.GetMouseButtonDown(0))
        {
            //Debug.Log ("Click Detected");
            fakeTouch.fingerId = 10;
            if (fakeTouch.phase == TouchPhase.Began)
            {
                fakeTouch.tapCount += 1;
                return;
            }
            fakeTouch.phase    = TouchPhase.Began;
            fakeTouch.tapCount = 1;
        }
        if (Input.GetMouseButtonUp(0))
        {
            //Debug.Log ("Released TouchData:\n" + fakeTouch.Create());
            fakeTouch.phase = TouchPhase.Ended;
        }
    }
コード例 #12
0
ファイル: TouchHandler.cs プロジェクト: darthcoder1/SMFShared
 public Touch[] GetTouches()
 {
     List<Touch> touches = new List<Touch>();
     touches.AddRange(Input.touches);
     #if UNITY_EDITOR
     if (!Input.touchSupported)
     {
         if (lastFakeTouch == null) lastFakeTouch = new TouchCreator();
         if (Input.GetMouseButtonDown(0))
         {
             lastFakeTouch.phase = TouchPhase.Began;
             lastFakeTouch.deltaPosition = new Vector2(0, 0);
             lastFakeTouch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
             lastFakeTouch.fingerId = 0;
         }
         else if (Input.GetMouseButtonUp(0))
         {
             lastFakeTouch.phase = TouchPhase.Ended;
             Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
             lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
             lastFakeTouch.position = newPosition;
             lastFakeTouch.fingerId = 0;
         }
         else if (Input.GetMouseButton(0))
         {
             lastFakeTouch.phase = TouchPhase.Moved;
             Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
             lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
             lastFakeTouch.position = newPosition;
             lastFakeTouch.fingerId = 0;
         }
         else
         {
             lastFakeTouch = null;
         }
         if (lastFakeTouch != null) touches.Add(lastFakeTouch.Create());
     }
     #endif
     return touches.ToArray();
 }
コード例 #13
0
    public static List <Touch> GetTouches()
    {
        List <Touch> touches = new List <Touch>();

        #if UNITY_EDITOR
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return(touches);
        }
        #else
        if (Input.touchCount > 0)
        {
            if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                return(touches);
            }
        }
        #endif

        touches.AddRange(Input.touches);
 #if UNITY_EDITOR
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new TouchCreator();
        }
        if (Input.GetMouseButtonDown(0))
        {
            lastFakeTouch.phase         = TouchPhase.Began;
            lastFakeTouch.deltaPosition = new Vector2(0, 0);
            lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.fingerId      = 0;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lastFakeTouch.phase = TouchPhase.Ended;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
        }
        else if (Input.GetMouseButton(0))
        {
            lastFakeTouch.phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
        }
        else
        {
            lastFakeTouch = null;
        }
        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch.Create());
        }
 #endif


        return(touches);
    }
コード例 #14
0
    void Update()
    {
        List <Touch> touches = new List <Touch>();

        touches.AddRange(Input.touches);
#if UNITY_EDITOR
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new TouchCreator();
        }
        if (Input.GetMouseButtonDown(0))
        {
            lastFakeTouch.phase         = TouchPhase.Began;
            lastFakeTouch.deltaPosition = new Vector2(0, 0);
            lastFakeTouch.deltaTime     = 0;
            lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.fingerId      = 0;
            lastFakeTouch.fakeTime      = Time.time;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lastFakeTouch.phase = TouchPhase.Ended;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
            lastFakeTouch.deltaTime     = Time.time - lastFakeTouch.fakeTime;
        }
        else if (Input.GetMouseButton(0))
        {
            lastFakeTouch.phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
            lastFakeTouch.deltaTime     = Time.time - lastFakeTouch.fakeTime;
        }
        else
        {
            lastFakeTouch = null;
        }
        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch.Create());
        }
#endif
        if (touches.Count > 0)
        {
            touchesOld = new GameObject[touchList.Count];
            touchList.CopyTo(touchesOld);
            touchList.Clear();
            foreach (Touch t in touches)
            {
                Vector2      touchOnWorld = _camera.ScreenToWorldPoint(t.position);
                RaycastHit2D hit;
                if (hit = Physics2D.Linecast(touchOnWorld, touchOnWorld, touchInputMask))
                {
                    GameObject racipient = hit.transform.gameObject;
                    touchList.Add(racipient);
                    string methodName = "";
                    switch (t.phase)
                    {
                    case TouchPhase.Began:
                        methodName = "OnTouchDown";
                        if (draggedObject == null)
                        {
                            draggedObject = racipient;
                        }
                        break;

                    case TouchPhase.Ended:
                        methodName = "OnTouchUp";
                        if (draggedObject != null && racipient != draggedObject)
                        {
                            draggedObject.SendMessage("OnTouchUp", new object[] { t.deltaPosition, t.deltaTime, new Vector2(), t.position }, SendMessageOptions.DontRequireReceiver);
                        }
                        draggedObject = null;
                        break;

                    case TouchPhase.Moved:
                        methodName = "OnTouchMove";
                        if (draggedObject == null)
                        {
                            draggedObject = racipient;
                        }
                        break;

                    case TouchPhase.Stationary:
                        methodName = "OnTouchStay";
                        break;

                    case TouchPhase.Canceled:
                        methodName = "OnTouchExit";
                        break;
                    }
                    racipient.SendMessage(methodName, new object[] { t.deltaPosition, t.deltaTime, hit.point }, SendMessageOptions.DontRequireReceiver);
                }
                else if (draggedObject != null && t.phase == TouchPhase.Ended)
                {
                    draggedObject.SendMessage("OnTouchUp", new object[] { t.deltaPosition, t.deltaTime, new Vector2(), t.position }, SendMessageOptions.DontRequireReceiver);
                    draggedObject = null;
                }

                foreach (GameObject g in touchesOld)
                {
                    if (!touchList.Contains(g))
                    {
                        g.SendMessage("OnTouchExit", new object[] { t.deltaPosition, t.deltaTime, hit.point }, SendMessageOptions.DontRequireReceiver);
                    }
                }
                if (draggedObject != null)
                {
                    draggedObject.SendMessage("OnTouchDrag", new object[] { t.deltaPosition, t.deltaTime, new Vector2(), t.position }, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    }
コード例 #15
0
ファイル: InputHelper.cs プロジェクト: willroyMyles/Bouncer
    public static List <Touch> GetTouches()
    {
        List <Touch> touches = new List <Touch>();

        touches.AddRange(Input.touches);
#if UNITY_EDITOR
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new TouchCreator();
        }

        if (Input.GetMouseButtonDown(0))
        {
            lastFakeTouch.phase         = TouchPhase.Began;
            lastFakeTouch.deltaPosition = new Vector2(0, 0);
            lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.fingerId      = 0;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lastFakeTouch.phase = TouchPhase.Ended;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;

            clicked++;
            if (clicked == 1)
            {
                clicktime = Time.time;
            }

            if (clicked > 1 && Time.time - clicktime < clickdelay)
            {
                clicked   = 1;
                clicktime = 0;
                lastFakeTouch.tapCount = 2;
            }
            if (Time.time - clicktime > clickdelay)
            {
                clicked = 0;
            }
        }
        else if (Input.GetMouseButton(0))
        {
            lastFakeTouch.phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
        }
        else
        {
            lastFakeTouch = null;
        }
        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch.Create());
        }
#endif


        return(touches);
    }
コード例 #16
0
    void doTouch()
    {
        List <Touch> temp = new List <Touch>();

        temp.AddRange(Input.touches);
        if (temp.Count == 0)
        {
            Touch tc = TouchCreator.GetTouchCreator().Create();
            if (tc.fingerId == 10)
            {
                temp.Add(tc);
            }
        }

        if (temp.Count < 1)
        {
            return;
        }
        //Debug.Log ("Correct Finger ID Phase:"+ tc.phase);

        foreach (Touch t in temp)
        {
            switch (t.phase)
            {
            case TouchPhase.Began:
                if (!tList.ContainsKey(t.fingerId))
                {
                    tList.Add(t.fingerId, t);
                }
                break;

            case TouchPhase.Ended:
                //Debug.Log ("Began" + tList.ContainsKey(t.fingerId));
                if (tList.ContainsKey(t.fingerId))
                {
                    if ((tList[t.fingerId].phase == TouchPhase.Stationary) || (t.phase == TouchPhase.Began))
                    {
                        //Debug.Log ("Shooting");
                        anim.SetBool("isShooting", true);
                        tList.Remove(t.fingerId);
                    }
                }
                break;

            case TouchPhase.Moved:
                if (tList.ContainsKey(t.fingerId))
                {
                    if ((tList[t.fingerId].phase == TouchPhase.Began || tList[t.fingerId].phase == TouchPhase.Stationary))
                    {
                        if (currentJoystick)
                        {
                            break;
                        }
                        CreateJoystick(t);
                        tList.Remove(t.fingerId);
                    }
                }
                break;

            case TouchPhase.Stationary:
                if (tList.ContainsKey(t.fingerId))
                {
                    if (!(tList[t.fingerId].phase == TouchPhase.Moved))
                    {
                        tList[t.fingerId] = t;
                    }
                }
                break;
            }
        }
    }
コード例 #17
0
ファイル: TouchCreator.cs プロジェクト: allfa/Reborn
 public static TouchCreator GetTouchCreator()
 {
     if(tc == null)
         tc= new TouchCreator();
     return tc;
 }
コード例 #18
0
    //private static TouchCreator mirrorFakeTouch;

    public static List <Touch> GetTouches()
    {
        List <Touch> touches = new List <Touch> ();

        touches.AddRange(Input.touches);
#if UNITY_EDITOR
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new TouchCreator();
            //mirrorFakeTouch = new TouchCreator ();
        }
        if (Input.GetMouseButtonDown(0))
        {
            lastFakeTouch.phase         = TouchPhase.Began;
            lastFakeTouch.deltaPosition = new Vector2(0, 0);
            lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.fingerId      = 0;

            //mirrorFakeTouch.phase = TouchPhase.Began;
            //mirrorFakeTouch.deltaPosition = new Vector2 (0, 0);
            //mirrorFakeTouch.position = new Vector2 (Input.mousePosition.x, Input.mousePosition.y) + Vector2.right * 10f;
            //mirrorFakeTouch.fingerId = 13;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lastFakeTouch.phase = TouchPhase.Ended;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;

            //mirrorFakeTouch.phase = TouchPhase.Ended;
            //newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y) + Vector2.right * 10f;
            //mirrorFakeTouch.deltaPosition = newPosition - mirrorFakeTouch.position;
            //mirrorFakeTouch.position = newPosition;
            //mirrorFakeTouch.fingerId = 13;
        }
        else if (Input.GetMouseButton(0))
        {
            lastFakeTouch.phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;

            //mirrorFakeTouch.phase = TouchPhase.Moved;
            //newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y) + Vector2.right * 10f;
            //mirrorFakeTouch.deltaPosition = newPosition - mirrorFakeTouch.position;
            //mirrorFakeTouch.position = newPosition;
            //mirrorFakeTouch.fingerId = 13;
        }
        else
        {
            lastFakeTouch = null;
            //mirrorFakeTouch = null;
        }
        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch.Create());
            //touches.Add (mirrorFakeTouch.Create ());
        }
#endif


        return(touches);
    }