Example #1
0
    private void OnMouseDrag()
    {
        //Debug.Log("OnMouseDrag:"+Time.time );
        if (!enabled)
        {
            return;
        }
        if (PlateformData.GetCurrentPlatform() == PlatformType.PC && _enableMove)
        {
            //三维物体坐标转屏幕坐标
            Vector3 screenSpace   = GlobeData.GetCurrentEventCamera().WorldToScreenPoint(transform.position);
            Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
            //物体的位置,屏幕坐标转换为世界坐标
            Vector3 objectPosition = GlobeData.GetCurrentEventCamera().ScreenToWorldPoint(mousePosition);
            Vector3 offset         = objectPosition - lastpos;
            //Vector3 pos = GlobeData._DragObj.position + offset;
            // GlobeData._DragObj.position = Vector3.Lerp(GlobeData._DragObj.position, pos, speed * Time.deltaTime * 10);

            // transform.position += offset;
            if (action == 1 && _Tran != null)
            {
                Vector3 pos = _Tran.position + offset;
                _Tran.position = Vector3.Lerp(_Tran.position, pos, _speed * Time.deltaTime * 10);
            }
            else
            {
                Vector3 pos = transform.position + offset;
                transform.position = Vector3.Lerp(transform.position, pos, _speed * Time.deltaTime * 10);
            }
            lastpos = objectPosition;
        }
    }
Example #2
0
 /// <summary>
 /// 检测是否拖动子节点
 /// </summary>
 private void DragOther()
 {
     if (Input.GetMouseButtonDown(0))
     {
         //Debug.Log(GlobeData._RightRaycaster._Result.gameObject);
         OperationBaseItem zom = isCheckChild();
         if (zom != null && zom == this)
         {
             isChild = true;
             CheckAction();
             GlobeData._DragObj = transform;
             //三维物体坐标转屏幕坐标
             Vector3 screenSpace   = GlobeData.GetCurrentEventCamera().WorldToScreenPoint(GlobeData._DragObj.position);
             Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
             //物体的位置,屏幕坐标转换为世界坐标
             Vector3 objectPosition = GlobeData.GetCurrentEventCamera().ScreenToWorldPoint(mousePosition);
             lastpos = objectPosition;
         }
     }
     if (Input.GetMouseButton(0) && GlobeData._DragObj != null && GlobeData._RightRaycaster._Result.gameObject != null)
     {
         if (isChild)
         {
             OnMouseDrag();
         }
     }
     if (Input.GetMouseButtonUp(0))
     {
         GlobeData._DragObj = null;
         isChild            = false;
     }
 }
Example #3
0
    private void RotationAxis(Transform t)
    {
        //计算方向向量
        Vector3 nowPos = GlobeData.GetCurrentEventCamera().WorldToScreenPoint(GlobeData._RightRaycaster.BreakPoints[0]);
        Vector3 offset = lastPenPos - nowPos;

        CheckAction();
        if (action == 1 && _Tran != null)
        {
            if (_enableX)
            {
                _Tran.Rotate(Vector3.right * offset.y * Time.deltaTime * _RotationSpeed, Space.Self);
            }
            if (_enableY)
            {
                _Tran.Rotate(Vector3.up * offset.x * Time.deltaTime * _RotationSpeed, Space.Self);
            }
        }
        else
        {
            if (_enableX)
            {
                transform.Rotate(Vector3.right * offset.y * Time.deltaTime * _RotationSpeed, Space.Self);
            }
            if (_enableY)
            {
                transform.Rotate(Vector3.up * offset.x * Time.deltaTime * _RotationSpeed, Space.Self);
            }
        }
        lastPenPos = nowPos;
    }
Example #4
0
    /// <summary>
    /// 中键按下后设置拖拽初始化数据
    /// </summary>
    /// <param name="hitObject"></param>
    /// <param name="hitDistance"></param>
    /// <param name="inputPosition"></param>
    /// <param name="inputRotation"></param>
    private void BeginGrab(GameObject hitObject, float hitDistance, Vector3 inputPosition, Quaternion inputRotation)
    {
        Vector3 inputEndPosition = inputPosition + (inputRotation * (Vector3.forward * hitDistance));

        _initialGrabOffset   = Quaternion.Inverse(hitObject.transform.rotation) * (hitObject.transform.position - inputEndPosition);
        _initialGrabRotation = Quaternion.Inverse(inputRotation) * hitObject.transform.rotation;
        _initialGrabDistance = hitDistance;
        GlobeData._DragObj   = transform;
        //设置单轴旋转基准点
        // roaPenPos =GlobeData._ZspaceCamera.WorldToScreenPoint(inputPosition);
        // lastPenPos = roaPenPos;
        lastPenPos = GlobeData.GetCurrentEventCamera().WorldToScreenPoint(inputPosition);
        // Debug.Log("press 屏幕坐标点:"+ roaPenPos);
        if (action == 1 && _Tran != null)//分身缩放
        {
            GlobeData._DragObj   = _Tran;
            _initialGrabOffset   = Quaternion.Inverse(_Tran.rotation) * (_Tran.position - inputEndPosition);
            _initialGrabRotation = Quaternion.Inverse(inputRotation) * _Tran.rotation;
        }
    }
Example #5
0
 private void OnMouseDown()
 {
     if (PlateformData.GetCurrentPlatform() == PlatformType.PC && _enableMove)
     {
         CheckAction();
         if (action == 1)
         {
             GlobeData._DragObj = _Tran;
         }
         else
         {
             GlobeData._DragObj = transform;
         }
         //三维物体坐标转屏幕坐标
         Vector3 screenSpace   = GlobeData.GetCurrentEventCamera().WorldToScreenPoint(transform.position);
         Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
         //物体的位置,屏幕坐标转换为世界坐标
         Vector3 objectPosition = GlobeData.GetCurrentEventCamera().ScreenToWorldPoint(mousePosition);
         lastpos = objectPosition;
     }
 }