GetTouch() static public method

Get or create a touch event.
static public GetTouch ( int id ) : MouseOrTouch
id int
return MouseOrTouch
Exemplo n.º 1
0
        // Update is called once per frame
        private void Update()
        {
        #if !UNITY_EDITOR
            try
            {
        #endif

            if (canTouch)
            {
                if (null != buffer)
                {
                    var touch = UICamera.GetTouch(curTouchID);
                    if (null != touch)
                    {
                        buffer.UpdatePostion(touch.pos);
                    }
                }
            }

        #if !UNITY_EDITOR
        }

        catch (Exception ex)
        {
            Logger.Error(ex.ToString());
        }
        #endif
        }
Exemplo n.º 2
0
 private void Update()
 {
     if (inpress)
     {
         //触碰的点的位置
         clickPos = UICamera.GetTouch(touchID, false).pos;
         //虚拟按键的点的屏幕坐标
         Vector2 JoyStick = new Vector2(uicamera.WorldToScreenPoint(this.transform.position).x, uicamera.WorldToScreenPoint(this.transform.position).y);
         if (Vector3.Distance(JoyStick, clickPos) <= r)
         {
             sliderblock.transform.position = UICamera.currentCamera.ScreenToWorldPoint(clickPos);
         }
         else
         {
             sliderblock.transform.localPosition = (clickPos - JoyStick).normalized * r;
         }
         float angle = Vector3.Angle(initPos.up, sliderblock.transform.localPosition);
         if (Mathf.Sign(Vector3.Dot(initPos.right, sliderblock.transform.localPosition)) < 0)
         {
             angle = -angle;
         }
         Quaternion targetAngle = Quaternion.Euler(0, angle, 0);
         player.rotation = Quaternion.Slerp(player.rotation, targetAngle, Time.deltaTime);
         ani.SetFloat("Blend", 5.6f, 1f, Time.deltaTime);
     }
     else
     {
         sliderblock.transform.localPosition = Vector3.zero;
         //控制站住 不移动
         player.rotation = Quaternion.Slerp(player.rotation, initRot, Time.deltaTime);
         ani.SetFloat("Blend", 0, 0.5f, Time.deltaTime);
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// Create a plane on which we will be performing the dragging.
    /// </summary>

    public void OnPress2(bool pressed)
    {
        if (target != null)
        {
            mPressed = pressed;

            if (pressed)
            {
                //StopAllCoroutines();
                StopCoroutine("fadeOutJoystick");
                if (Time.time < lastTapTime + doubleTapTimeWindow)
                {
                    if (doubleTapMessageTarget != null && doubleTabMethodeName != "")
                    {
                        doubleTapMessageTarget.SendMessage(doubleTabMethodeName, SendMessageOptions.DontRequireReceiver);
                        tapCount++;
                    }
                    else
                    {
                        Debug.LogWarning("Double Tab on Joystick but no Reciever or Methodename available");
                    }
                }
                else
                {
                    tapCount = 1;
                }
                lastTapTime = Time.time;
                //set Joystick to fingertouchposition
                //Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
                Ray   ray  = UICamera.currentCamera.ScreenPointToRay(UICamera.GetTouch(0).pos);
                float dist = 0f;

                Vector3 currentPos = ray.GetPoint(dist);
                currentPos.z = 0;
                if (centerOnPress)
                {
                    userInitTouchPos = currentPos;
                    foreach (UIWidget widget in widgetsToFade)
                    {
                        TweenColor.Begin(widget.gameObject, 0.1f, Color.white).method = UITweener.Method.EaseIn;
                    }
                    foreach (Transform widgetTF in widgetsToCenter)
                    {
                        widgetTF.position = userInitTouchPos;
                    }
                }
                else
                {
                    userInitTouchPos = target.position;
                    OnDrag(Vector2.zero);
                }
            }
            else
            {
                ResetJoystick();
            }
        }
    }
Exemplo n.º 4
0
    static int GetTouch(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        int arg0 = (int)LuaScriptMgr.GetNumber(L, 1);

        UICamera.MouseOrTouch o = UICamera.GetTouch(arg0);
        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
Exemplo n.º 5
0
 void OnPress(bool pressed)
 {
     if (pressed)//按下
     {
         //要排除是双指或双指以上的模式
         if (!(UICamera.touchCount >= 2))
         {
             GameCamera.Inst.jiaodian = UICamera.lastWorldPosition;//试试这个新学到的
             //SuperGameManager.Instance.core = UICamera.lastWorldPosition;
         }
         //-------------------------------------------
         SuperGameManager.Instance.buttonPressed     = true;
         SuperGameManager.Instance.validClickRequest = true;
         int        id = UICamera.currentTouchID;
         SuperPoint sp = new SuperPoint();
         sp.Init(UICamera.GetTouch(id).pos.x, UICamera.GetTouch(id).pos.y);
         //加入直接先判断是否存在
         if (GameCamera.Inst.pd.ContainsKey(id))
         {
             GameCamera.Inst.pd.Remove(id);
         }
         //无论是主点还是辅点按下皆向map中放入一个新点
         GameCamera.Inst.pd.Add(id, sp);
         if (UICamera.touchCount == 2)
         {
             if (GameCamera.Inst.pd.Count == 2)//如果已经有两个触控点按下
             {
                 //SuperPoint sp1 = GameCamera.Inst.pd[0];//从map中取出第一个点
                 //SuperPoint sp2 = GameCamera.Inst.pd[1];//从map中取出第二个点
                 //GameCamera.Inst.distance = SuperPoint.calDistance(sp1, sp2);//计算两个触控点之间的距离
                 //Debug.Log("这两个触控点的初始距离是" + GameCamera.Inst.distance);
             }
         }
     }
     else//抬起
     {
         SuperGameManager.Instance.validClickRequest = true;
         //-----------------------------------------------------------------------
         SuperGameManager.Instance.buttonPressed = false;
         SuperGameManager.Instance.time          = 0f;
         if (UICamera.currentTouchID == 0)//如果是主点抬起
         {
             GameCamera.Inst.pd.Clear();
             SuperGameManager.Instance.touchMode = SuperGameManager.TouchMode.None;
         }
         else if (UICamera.currentTouchID == 1)//如果是辅点抬起
         {
             GameCamera.Inst.pd.Remove(1);
             SuperGameManager.Instance.validClickRequest = false;
         }
     }
 }
Exemplo n.º 6
0
    private void OnDrag(Vector2 delta)
    {
        if (UICamera.touchCount == 3)
        {
            UICamera.MouseOrTouch touch1 = UICamera.GetTouch(0);
            UICamera.MouseOrTouch touch2 = UICamera.GetTouch(1);
            UICamera.MouseOrTouch touch3 = UICamera.GetTouch(2);

            MainCamera.GetInstance().Rotate((touch1.delta.x + touch2.delta.x + touch3.delta.x) / 3f);
        }
        else if (UICamera.touchCount == 2)
        {
            UICamera.MouseOrTouch touch1 = UICamera.GetTouch(0);
            UICamera.MouseOrTouch touch2 = UICamera.GetTouch(1);

            if (Vector2.Dot(touch1.delta.normalized, touch2.delta.normalized) <= 0f)              // < 0 means the 2 touches are moving in different directions (a pinch gesture)
            {
                Vector2 curDist    = touch1.pos - touch2.pos;                                     //current distance between finger touches
                Vector2 prevDist   = ((touch1.pos - touch1.delta) - (touch2.pos - touch2.delta)); //difference in previous locations using delta positions
                float   touchDelta = curDist.magnitude - prevDist.magnitude;

                MainCamera.GetInstance().Zoom(-touchDelta);
            }
        }
        else if (UICamera.touchCount == 1)
        {
            if (_pressedLayer == LayerMask.NameToLayer("GUI"))
            {
                //ignore the GUI layer
                return;
            }

            /*	else if (_pressedLayer == BuildingManager3D.SELECTION_LAYER)
             * {
             * if (selectedObject != null)
             * {
             *                      Ray ray = mainCamera.ScreenPointToRay(UICamera.lastTouchPosition);
             *                      RaycastHit hit;
             *                      if(Physics.Raycast (ray, out hit, 10000, 1 << BuildingManager3D.TERRAIN_LAYER))
             *                                      selectedObject.SendMessage("OnDragEvent", hit.point - gameView.transform.position, SendMessageOptions.DontRequireReceiver);
             * }
             * else
             * {
             *  MainCamera.GetInstance().Drag(delta);
             * }
             * } */
            else
            {
                MainCamera.GetInstance().Drag(delta);
            }
        }
    }
Exemplo n.º 7
0
 public void ProcessTouches()
 {
     for (int i = 0; i < Input.touchCount; i++)
     {
         Touch touch = Input.GetTouch(i);
         UICamera.currentTouchID = ((!this.allowMultiTouch) ? 1 : touch.fingerId);
         UICamera.currentTouch   = UICamera.GetTouch(UICamera.currentTouchID);
         bool flag  = touch.phase == TouchPhase.Began || UICamera.currentTouch.touchBegan;
         bool flag2 = touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended;
         UICamera.currentTouch.touchBegan = false;
         if (flag)
         {
             UICamera.currentTouch.delta = Vectors.v2zero;
         }
         else
         {
             UICamera.currentTouch.delta = touch.position - UICamera.currentTouch.pos;
         }
         UICamera.currentTouch.pos = touch.position;
         UICamera.hoveredObject    = ((!UICamera.Raycast(UICamera.currentTouch.pos, ref UICamera.lastHit)) ? UICamera.fallThrough : UICamera.lastHit.collider.gameObject);
         if (UICamera.hoveredObject == null)
         {
             UICamera.hoveredObject = UICamera.genericEventHandler;
         }
         UICamera.currentTouch.current = UICamera.hoveredObject;
         UICamera.lastTouchPosition    = UICamera.currentTouch.pos;
         if (flag)
         {
             UICamera.currentTouch.pressedCam = UICamera.currentCamera;
         }
         else if (UICamera.currentTouch.pressed != null)
         {
             UICamera.currentCamera = UICamera.currentTouch.pressedCam;
         }
         if (touch.tapCount > 1)
         {
             UICamera.currentTouch.clickTime = Time.realtimeSinceStartup;
         }
         this.ProcessTouch(flag, flag2);
         if (flag2)
         {
             UICamera.RemoveTouch(UICamera.currentTouchID);
         }
         UICamera.currentTouch = null;
         if (!this.allowMultiTouch)
         {
             break;
         }
     }
 }
Exemplo n.º 8
0
    void Update()
    {
        if (isKeyboardEmulation)
        {
            EmulateKeyboard();
        }

        if (isPressed)
        {
            innerPosition = UICamera.GetTouch(touchId).pos;

            ApplyMovement();
        }
    }
Exemplo n.º 9
0
 public void SetEnableUIInput(bool is_enable)
 {
     if (enableUIInput != is_enable)
     {
         enableUIInput = is_enable;
         if (is_enable)
         {
             nguiCamera.useTouch = initUseTouch;
             nguiCamera.useMouse = initUseMouse;
         }
         else
         {
             nguiCamera.useTouch = false;
             nguiCamera.useMouse = false;
             if (!nguiCamera.allowMultiTouch && UICamera.CountInputSources() == 1)
             {
                 UICamera.MouseOrTouch touch = UICamera.GetTouch(1, false);
                 if (touch != null && touch.pressed != null)
                 {
                     UIButton component = touch.pressed.GetComponent <UIButton>();
                     if (component != null)
                     {
                         component.SetState(UIButtonColor.State.Normal, true);
                     }
                     UIScrollView componentInParent = touch.pressed.GetComponentInParent <UIScrollView>();
                     if (componentInParent != null)
                     {
                         componentInParent.Press(false);
                     }
                     touch.pressed = null;
                 }
                 if (UICamera.currentTouch != null)
                 {
                     nguiCamera.ProcessTouch(false, true);
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
    void onJoystickPress(GameObject obj, bool isPress)
    {
        CloseSubForm();
        mPress = isPress;

        mCurrentTouchID = UICamera.currentTouchID;
        mCurrentTouch   = UICamera.GetTouch(mCurrentTouchID);

        if (!mPress || mCurrentTouch == null)
        {
            MyJoystick.joystickAxis = Vector2.zero;
            ResetButtonPos();
            return;
        }

        mDotPos = mCurrentTouch.pos;

        Vector3 pos = WindowManager.current2DCamera.ScreenToWorldPoint(mDotPos);

        //更新新位置
        Button.transform.position = Sprite.transform.position = pos;
    }
Exemplo n.º 11
0
    /// <summary>
    /// Drag the object along the plane.
    /// </summary>

    void OnDrag(Vector2 delta)
    {
        //Debug.Log("delta " +  delta + " delta.magnitude = " + delta.magnitude);

        //	Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
        Ray   ray  = UICamera.currentCamera.ScreenPointToRay(UICamera.GetTouch(0).pos);
        float dist = 0f;

        Vector3 currentPos = ray.GetPoint(dist);
        Vector3 offset     = currentPos - userInitTouchPos;

        if (offset.x != 0f || offset.y != 0f)
        {
            offset = target.InverseTransformDirection(offset);
            offset.Scale(scale);
            offset = target.TransformDirection(offset);

            offset.y = 0.0f;
            offset.z = 0f;
        }
        if (offset.x > 0.0f)
        {
            m_eDirect = E_CSDIRECT.E_RIGHT;
        }
        else if (offset.x < 0.0f)
        {
            m_eDirect = E_CSDIRECT.E_LEFT;
        }
        else
        {
            m_eDirect = E_CSDIRECT.E_CENTER;
        }


        target.position = userInitTouchPos + offset;

        Vector3 zeroZpos = target.position;

        zeroZpos.z      = 0f;
        target.position = zeroZpos;
        // Calculate the length. This involves a squareroot operation,
        // so it's slightly expensive. We re-use this length for multiple
        // things below to avoid doing the square-root more than one.

        float length = target.localPosition.magnitude;

        if (length < deadZone)
        {
            // If the length of the vector is smaller than the deadZone radius,
            // set the position to the origin.
            position             = Vector2.zero;
            target.localPosition = position;
        }
        else if (length > radius)
        {
            target.localPosition = Vector3.ClampMagnitude(target.localPosition, radius);
            position             = target.localPosition;
        }


        if (normalize)
        {
            // Normalize the vector and multiply it with the length adjusted
            // to compensate for the deadZone radius.
            // This prevents the position from snapping from zero to the deadZone radius.
            position = position / radius * Mathf.InverseLerp(radius, deadZone, 1);
        }
    }