Example #1
0
        public void OnUpdate()
        {
            if (!isActive)
            {
                return;
            }
            float   dis        = (GrabObject.transform.position - Camera.main.transform.position).magnitude; //相机到物体的距离
            Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex);                              //当前手的屏幕坐标

            //Vector3 vector = (screenHand-recordPos)*speed*Time.deltaTime;  //手移动的向量
            //移动距离转旋转值
            x += (screenHand.x - recordPos.x) / 1920 * 360;
            y -= (screenHand.y - recordPos.y) / 1080 * 360;
            //限制范围
            x = Mathf.Clamp(x, leftAndRight.x, leftAndRight.y);
            y = Mathf.Clamp(y, upAndDown.x, upAndDown.y);

            Quaternion q = Quaternion.Euler(y, x, 0);

            Vector3 direction = q * GrabObject.transform.forward;

            Camera.main.transform.position = GrabObject.transform.position - direction * dis;
            Camera.main.transform.rotation = q;
            recordPos = screenHand;
        }
Example #2
0
        private void Update()
        {
            if (IsDown && handIndex != -1 && IsEnable && enabled)
            {
                //屏幕坐标
                Vector3 screenPoint = MOperateManager.GetHandScreenPoint(handIndex);

                //将屏幕坐标传递出去
                OnExecute(screenPoint);
            }
        }
Example #3
0
        /// <summary>
        /// 是否存在区域内
        /// </summary>
        /// <param name="screenPoint">屏幕坐标</param>
        /// <param name="size">大小</param>
        /// <param name="handIndex">手势</param>
        /// <returns></returns>
        public static bool IsAreaContains(Vector2 screenPoint, Vector2 size, int handIndex)
        {
            //if (!KinectTransfer.IsHandActive(handIndex)) return false;

            //获取到此时手的屏幕坐标屏幕坐标
            Vector3 screenHandPoint = MOperateManager.GetHandScreenPoint(handIndex);

            //根据自身此时的屏幕坐标,去算区域

            return(ScreenPointContains(screenPoint, size, screenHandPoint));
        }
Example #4
0
        public void OnOpen(int handIndex)
        {
            this.handIndex = handIndex;
            Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex);

            Vector3 vector = GrabObject.transform.position - Camera.main.transform.position;

            // Camera.main.transform.position=GrabObject.transform.forward*vector.magnitude;//相机朝向物体
            Camera.main.transform.forward = vector.normalized;
            recordPos = screenHand; //记录手的屏幕坐标
            isActive  = true;
        }
Example #5
0
        /// <summary>
        /// 打开
        /// </summary>
        public virtual void OnOpen(int handIndex = 0)
        {
            this.handIndex = handIndex;
            Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex);

            Vector3 screenPosition = MUtility.MainWorldToScreenPoint(GrabObject.transform.position);

            recordPos = MUtility.MainScreenToWorldPoint(new Vector3(screenHand.x, screenHand.y, screenPosition.z));//手的坐标


            recordEuler = space == Space.World ? GrabObject.transform.eulerAngles : GrabObject.transform.localEulerAngles;
            isActive    = true;
        }
Example #6
0
        void Update()
        {
            if (IsPressed && MSwitchManager.CurrentMode == OperateModeType.Tool)
            {
                Vector3 temp = MOperateManager.GetHandScreenPoint(handIndex);

                temp.x = Mathf.Clamp(temp.x, 0, Screen.width);
                temp.y = Mathf.Clamp(temp.y, 0, Screen.height);

                Vector2 mouse_world_position = MUtility.UICamera.ScreenToWorldPoint(temp);

                currentBrush(mouse_world_position);
            }
        }
Example #7
0
 /// <summary>
 /// 容器水平滚动
 /// </summary>
 /// <param name="direction"></param>
 public void PanelScrollX(int direction)
 {
     if (isFollowHand)
     {
         var handXPos = MOperateManager.GetHandScreenPoint(curXHand);
         var x        = recordXPos.x + handXPos.x - recordXHandPos.x;
         x = Mathf.Clamp(x, viewInfoX.minValue, viewInfoX.maxValue);
         var pos = content.localPosition;
         pos.x = x;
         content.localPosition = pos;
     }
     else
     {
         horizontal.Value -= direction * 1.5f * Time.deltaTime;
     }
 }
Example #8
0
 /// <summary>
 /// 容器垂直滚动
 /// </summary>
 /// <param name="direction"></param>
 public void PanelScrollY(int direction)
 {
     if (isFollowHand)
     {
         var handPos = MOperateManager.GetHandScreenPoint(curHand);
         var y       = recordPos.y + handPos.y - recordHandPos.y;
         y = Mathf.Clamp(y, viewInfoY.minValue, viewInfoY.maxValue);
         var pos = content.localPosition;
         pos.y = y;
         content.localPosition = pos;
     }
     else
     {
         vertical.Value -= direction * 1.5f * Time.deltaTime;
     }
 }
Example #9
0
        IEnumerator OnUpdate(int handIndex)
        {
            while (true)
            {
                yield return(new WaitForFixedUpdate());

                Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex);

                Vector3 screenPosition = MUtility.MainWorldToScreenPoint(GrabObject.transform.position);
                Vector3 position       = MUtility.MainScreenToWorldPoint(new Vector3(screenHand.x, screenHand.y, screenPosition.z));

                if (OnCustomizeUpdate != null)
                {
                    OnCustomizeUpdate.Invoke(GrabObject, position, handIndex);
                }
            }
        }
Example #10
0
        private void Update()
        {
            if (IsDown && handIndex != -1 && enabled)
            {
                //屏幕坐标
                Vector3 screenPoint = MOperateManager.GetHandScreenPoint(handIndex);

                Vector3 screenDevice = MUtility.MarkWorldToScreenPoint(sliderObject.transform.position);
                Vector3 vPos         = MUtility.MarkScreenToWorldPoint(new Vector3(screenPoint.x, screenPoint.y, screenDevice.z));

                OnExecute(vPos);
            }

            //if (tempValue != Value)
            //{
            //    SetChangingValue(Value);
            //}
        }
Example #11
0
        public virtual void OnUpdate()
        {
            if (!isActive)
            {
                return;
            }
            Vector3 screenHand     = MOperateManager.GetHandScreenPoint(handIndex);
            Vector3 screenPosition = MUtility.MainWorldToScreenPoint(recordPos);
            Vector3 handPos        = MUtility.MainScreenToWorldPoint(new Vector3(screenHand.x, screenHand.y, screenPosition.z)); //手的坐标
            float   dis            = handPos.x - recordPos.x;                                                                    //手移动的距离

            float   ratio = dis * speed;
            float   angle = 0;
            Vector3 euler = recordEuler;

            angle = GetAngle(ratio, angle);
            euler = GetEuler(angle, euler);
            RotateSelf(euler);
        }
Example #12
0
        private void Update()
        {
            if (!enabled)
            {
                return;
            }

            OnEnterHandle(0); //右手
            OnEnterHandle(1); //左手

            if (IsDown && handIndex != -1)
            {
                //屏幕坐标
                Vector3 screenPoint = MOperateManager.GetHandScreenPoint(handIndex);

                //将屏幕坐标传递出去
                OnExecute(screenPoint);
            }
        }
Example #13
0
        /// <summary>
        /// 是否存在区域内
        /// </summary>
        /// <param name="transform">指定物体</param>
        /// <param name="handIndex"></param>
        /// <returns></returns>
        public static bool IsAreaContains(Transform transform, int handIndex)
        {
            //if (!KinectTransfer.IsHandActive(handIndex)) return false;

            try
            {
                //获取到此时手的屏幕坐标屏幕坐标
                Vector3 screenHandPoint = MOperateManager.GetHandScreenPoint(handIndex);

                Vector3 screenPoint = MUtility.UIWorldToScreenPoint(transform.position);

                //根据自身此时的屏幕坐标,去算区域

                RectTransform rectTransform = transform.GetComponent <RectTransform>();

                return(ScreenPointContains(screenPoint, rectTransform.sizeDelta, screenHandPoint));
            }
            catch (Exception)
            {
                return(false);
                //throw new Exception("手势可能没激活,如果是在编辑器上遇到此问题,不用理会");
            }
        }
Example #14
0
        private void Update()
        {
            if (!enabled)
            {
                return;
            }
            if (!Active)
            {
                return;
            }
            OnEnterHandle(0); //右手
            OnEnterHandle(1); //左手

            if (!IsDown || handIndex == -1)
            {
                return;
            }
            //屏幕坐标
            var screenPoint = MOperateManager.GetHandScreenPoint(handIndex);

            //将屏幕坐标传递出去
            OnExecute(screenPoint);
        }
Example #15
0
 private void OnDown(int arg0, bool arg1)
 {
     curHand       = arg0;
     recordHandPos = MOperateManager.GetHandScreenPoint(curHand);
     recordPos     = content.localPosition;
 }