Exemple #1
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;
     }
 }
    private void OnEnable()
    {
        _target = (OperationBaseItem)target;
        GUIStyleState normal = new GUIStyleState()
        {
            textColor = c3
        };

        titleStyle3.normal    = normal;
        titleStyle3.fontStyle = FontStyle.Italic;
        titleStyle3.fontSize  = 10;
    }
Exemple #3
0
    /// <summary>
    /// 检测是否点击到子节点
    /// </summary>
    /// <returns></returns>
    private OperationBaseItem isCheckChild()
    {
        OperationBaseItem zom = null;

        if (GlobeData._RightRaycaster._Result.gameObject != null)
        {
            if (GlobeData._RightRaycaster._Result.gameObject != gameObject)
            {
                zom = GlobeData._RightRaycaster._Result.gameObject.GetComponentInParent <OperationBaseItem>();
            }
        }
        return(zom);
    }
 /// <summary>
 /// transform类型递归查找子物体
 /// </summary>
 /// <returns>返回需要查找的子物体.</returns>
 /// <param name="parent">查找起点.</param>
 /// <param name="targetName">需要查找的子物体名字.</param>
 public void FindFunc(Transform parent, Type t)
 {
     //如果没有没有找到,说明没有在该子层级,则先遍历该层级所有transform,然后通过递归继续查找----再次调用该方法
     for (int i = 0; i < parent.childCount; i++)
     {
         Transform child = parent.GetChild(i);
         //找到T类型组件,不再递归下去,表示该对象所有的子节点作为一个整体
         if (child.GetComponent(t) != null)
         {
             if (t == typeof(OperationBaseItem))
             {
                 OperationBaseItem zoom = child.GetComponent(t) as OperationBaseItem;
                 zoom._Tran = _target.transform;
                 if (child.GetComponent <Collider>() == null)
                 {
                     child.gameObject.AddComponent <MeshCollider>();
                 }
             }
             FindFunc(child, typeof(Collider));
         }
         //该对像不存在T组件,添加T组件,遍历其子节点 添加T组件
         else
         {
             if (t == typeof(Collider))
             {
                 child.gameObject.AddComponent <MeshCollider>();
                 FindFunc(child, t);
             }
             else if (t == typeof(OperationBaseItem))
             {
                 OperationBaseItem zoom = child.gameObject.AddComponent(t) as OperationBaseItem;
                 zoom._Tran = _target.transform;
                 if (child.GetComponent <Collider>() == null)
                 {
                     child.gameObject.AddComponent <MeshCollider>();
                 }
                 FindFunc(child, t);
             }
         }
     }
 }
Exemple #5
0
    private void onRightRightPressDown()
    {
        // Debug.Log("onRightRightPressDown");
        OperationBaseItem zom = isCheckChild();
        bool isChild          = false;

        if (zom != null && zom == this)
        {
            isChild = true;
        }
        if (GlobeData._RightRaycaster._Result.gameObject == null)
        {
            validClick = false;
        }
        else if (GlobeData._RightRaycaster._Result.gameObject != gameObject)
        {
            validClick = isChild;
        }
        else
        {
            validClick = true;
        }
        if (!validClick)
        {
            return;
        }
        //记录触控笔的端点,用于计算下一帧 触控的端点移动的距离
        penPos   = GlobeData._RightRaycaster.BreakPoints[0];
        hoverDis = Vector3.Distance(GlobeData._RightRaycaster.BreakPoints[0], GlobeData._RightRaycaster.BreakPoints[1]);
        CheckAction();
        if (action == 1)
        {
            GlobeData._DragObj = _Tran;
        }
        else
        {
            GlobeData._DragObj = transform;
        }
    }
Exemple #6
0
    /// <summary>
    /// 监听左键按下
    /// </summary>
    private void OnRightLeftPressDown()
    {
        if (GlobeData._RightRaycaster._Result.gameObject == null)
        {
            validClick = false;
            return;
        }
        if (GlobeData._RightRaycaster._Result.gameObject.layer == 5)
        {
            validClick = false;
            return;
        }
        if (GlobeData._RightRaycaster._Result.gameObject == gameObject)
        {
            validClick = true;
        }
        else
        {
            OperationBaseItem zom = isCheckChild();
            bool isChild          = false;
            if (zom != null && zom == this)
            {
                isChild = true;
            }
            validClick = isChild;
        }
        if (!validClick)
        {
            return;
        }
        CheckAction();
        Vector3    rayDir = GlobeData._RightRaycaster.BreakPoints[1] - GlobeData._RightRaycaster.BreakPoints[0];
        RaycastHit hit;

        if (Physics.Raycast(GlobeData._RightRaycaster.BreakPoints[0], rayDir, out hit))
        {
            // If the front stylus button was pressed, initiate a grab.
            // Begin the grab.
            if (hit.collider.gameObject == gameObject)
            {
                // GlobeData._DragObj = transform;
                //if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
                //{
                BeginGrab(hit.collider.gameObject, hit.distance, GlobeData._RightRaycaster.BreakPoints[0], GlobeData._RightRaycaster.transform.rotation);
                //}
                // else if (PlateformData.GetCurrentPlatform() == PlatformType.PC)
                // {
                // BeginGrab(hit.collider.gameObject, hit.distance, GlobeData._RightRaycaster.BreakPoints[0], GlobeData._RightRaycaster.transform.rotation);
                //}
            }
            else
            {
                //点击对象是该对象的子节点
                // Debug.Log(name + "_:" + hit.collider.gameObject.GetComponentInParent<Zoom>().name);
                //if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
                // {
                BeginGrab(gameObject, hit.distance, GlobeData._RightRaycaster.BreakPoints[0], GlobeData._RightRaycaster.transform.rotation);
                // }
                // else if (PlateformData.GetCurrentPlatform() == PlatformType.PC)
                // {
                //BeginGrab(gameObject, hit.distance, GlobeData._RightRaycaster.BreakPoints[0], GlobeData._RightRaycaster.transform.rotation);
                // }
            }
        }
    }
Exemple #7
0
    /// <summary>
    /// 适配普通PC缩放
    /// </summary>
    private void PcScale()
    {
        bool isScale = false;

        if (GlobeData._RightRaycaster._Result.gameObject == null)
        {
            isScale = false;
        }
        else if (GlobeData._RightRaycaster._Result.gameObject == gameObject)
        {
            isScale = true;
        }
        else
        {
            OperationBaseItem zoom = isCheckChild();
            if (zoom != null && zoom == this)
            {
                isScale = true;
            }
            else
            {
                isScale = false;
            }
        }
        if (isScale)
        {
            CheckAction();
            int dir = 1;
            if (Input.GetAxis("Mouse ScrollWheel") > 0)
            {
                dir = 1;
            }
            else if (Input.GetAxis("Mouse ScrollWheel") < 0)
            {
                dir = -1;
            }
            else
            {
                dir = 0;
            }
            //Debug.Log("dir:" + dir);
            if (dir != 0)
            {
                if (action == -1)//协同缩放
                {
                    Vector3 v = transform.localScale + dir * Vector3.one * Time.deltaTime * _speed;
                    transform.localScale = ClampVec(_minScale, v, _maxScale);
                    if (_Tran != null)
                    {
                        v = _Tran.localScale + dir * Vector3.one * Time.deltaTime * _speed;
                        _Tran.localScale = ClampVec(_minScale, v, _maxScale);
                    }
                }
                else if (action == 0)//单体缩放
                {
                    Vector3 v = transform.localScale + dir * Vector3.one * Time.deltaTime * _speed;
                    transform.localScale = ClampVec(_minScale, v, _maxScale);
                }
                else if (action == 1)//分身缩放
                {
                    if (_Tran != null)
                    {
                        Vector3 v = _Tran.localScale + dir * Vector3.one * Time.deltaTime * _speed;
                        _Tran.localScale = ClampVec(_minScale, v, _maxScale);
                    }
                }
            }
        }
    }
Exemple #8
0
 private void PcRotate()
 {
     if (Input.GetMouseButtonDown(1))
     {
         lastMousePos = Input.mousePosition;
         if (GlobeData._RightRaycaster._Result.gameObject == gameObject)
         {
             CheckAction();
             validClick = true;
         }
         else
         {
             OperationBaseItem zoom = isCheckChild();
             if (zoom != null && zoom == this)
             {
                 CheckAction();
                 validClick = true;
             }
             else
             {
                 validClick = false;
             }
         }
         if (action == 1)
         {
             GlobeData._DragObj = _Tran;
         }
         else
         {
             GlobeData._DragObj = transform;
         }
     }
     if (Input.GetMouseButton(1) && validClick && _enableRotate)
     {
         Vector2 offset = lastMousePos - Input.mousePosition;
         if (action == 1 && _Tran != null)
         {
             if (_enableX & _enableY)
             {
                 _Tran.Rotate(-Vector3.right * offset.y * Time.deltaTime * _RotationSpeed, Space.World);
                 _Tran.Rotate(Vector3.up * offset.x * Time.deltaTime * _RotationSpeed, Space.World);
             }
             else
             {
                 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 & _enableY)
             {
                 transform.Rotate(-Vector3.right * offset.y * Time.deltaTime * _RotationSpeed, Space.World);
                 transform.Rotate(Vector3.up * offset.x * Time.deltaTime * _RotationSpeed, Space.World);
             }
             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);
                 }
             }
         }
         lastMousePos = Input.mousePosition;
     }
     if (Input.GetMouseButtonUp(1))
     {
         GlobeData._DragObj = null;
         validClick         = false;
     }
 }