Пример #1
0
 private void OnMouseUp()
 {
     if (PlateformData.GetCurrentPlatform() == PlatformType.PC)
     {
         GlobeData._DragObj = null;
     }
 }
Пример #2
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;
        }
    }
Пример #3
0
 public void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (PlateformData.GetCurrentPlatform() == PlatformType.PC)
         {
             if (GlobeData._RightRaycaster.FirstRaycastResult().gameObject != null)
             {
                 if (onClick != null)
                 {
                     onClick(GlobeData._RightRaycaster.FirstRaycastResult().gameObject);
                 }
             }
         }
     }
     if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger))
     {
         if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
         {
             if (onClick != null)
             {
                 onClick(GlobeData._RightRaycaster.FirstRaycastResult().gameObject);
             }
         }
     }
 }
Пример #4
0
    private void Awake()
    {
        selfDropDown = this.GetComponent <Dropdown>();
        Template     = selfDropDown.GetComponentInChildren <ScrollRect>(true).gameObject;

        ViveInput.AddPressUp(HandRole.RightHand, ControllerButton.Trigger, EmptyClick);
        UIEvent.Get(this.gameObject, ButtonKey.Left).OnHover += (go, bHover) =>
        {
            if (bHover == false)
            {
                return;
            }

            if (Template.GetComponent <CanvasRaycastTarget>() == null)
            {
                Template.gameObject.AddComponent <CanvasRaycastTarget>();
            }
            ;
        };
        for (int i = 0; i < selfDropDown.GetComponentsInChildren <Toggle>().Length; i++)
        {
            int      j          = i;
            Toggle[] allToggles = selfDropDown.GetComponentsInChildren <Toggle>();
            UIEvent.Get(allToggles[j].gameObject, ButtonKey.Left).onClick_ += (go, eventData) =>
            {
                if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
                {
                    selfDropDown.OnSelect(eventData);
                }
            };
        }
    }
Пример #5
0
 private void Awake()
 {
     UIEvent.Get(this.gameObject, ButtonKey.Left).OnHover += (go, bHover) =>
     {
         if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
         {
             return;
         }
         PlateformData.SetCoexistValue(bHover);
     };
 }
    void Update()
    {
        #region zspace

        #endregion
        if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
        {
            bool isButtonPressed = ViveInput.GetPress(HandRole.RightHand, ControllerButton.Trigger) ||
                                   ViveInput.GetPress(HandRole.RightHand, ControllerButton.Grip) ||
                                   ViveInput.GetPress(HandRole.RightHand, ControllerButton.PadTouch);
            Vector3 rayDir = raycaster.BreakPoints[1] - raycaster.BreakPoints[0];
            switch (StylusFunctionState)
            {
            case StylusState.Idle:
            {
                // Perform a raycast on the entire scene to determine what the
                // stylus is currently colliding with.
                RaycastHit hit;

                if (Physics.Raycast(raycaster.BreakPoints[0], rayDir, out hit))
                {
                    // If the front stylus button was pressed, initiate a grab.
                    if (isButtonPressed && !_wasButtonPressed)
                    {
                        // Begin the grab.
                        this.BeginGrab(hit.collider.gameObject, hit.distance, raycaster.BreakPoints[0], this.transform.rotation);

                        StylusFunctionState = StylusState.Grab;
                    }
                }
            }
            break;

            case StylusState.Grab:
            {
                // Update the grab.
                this.UpdateGrab(raycaster.BreakPoints[0], this.transform.rotation);

                // End the grab if the front stylus button was released.
                if (!isButtonPressed && _wasButtonPressed)
                {
                    StylusFunctionState = StylusState.Idle;
                }
            }
            break;

            default:
                break;
            }

            // Cache state for next frame.
            _wasButtonPressed = isButtonPressed;
        }
    }
Пример #7
0
    /// <summary>
    /// 更新拖拽物体的位置旋转信息
    /// </summary>
    /// <param name="inputPosition"></param>
    /// <param name="inputRotation"></param>
    private void UpdateGrab(Vector3 inputPosition, Quaternion inputRotation)
    {
        Vector3 inputEndPosition = inputPosition + (inputRotation * (Vector3.forward * _initialGrabDistance));
        // Update the grab object's rotation.
        Quaternion objectRotation = inputRotation * _initialGrabRotation;

        // Update the grab object's position.
        if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
        {
            if (action == 1 && _Tran != null)
            {
                Rotation(_Tran, objectRotation);
                if (_enableMove)
                {
                    Vector3 objectPosition = inputEndPosition + (objectRotation * _initialGrabOffset);
                    _Tran.position = objectPosition;
                }
            }
            else //如果等于-1不处理 直接拖拽
            {
                Rotation(transform, objectRotation);
                if (_enableMove)
                {
                    Vector3 objectPosition = inputEndPosition + (objectRotation * _initialGrabOffset);
                    transform.position = objectPosition;
                }
            }
        }
        else if (PlateformData.GetCurrentPlatform() == PlatformType.PC)
        {
            if (action == 1 && _Tran != null)
            {
                //Rotation(_Tran, objectRotation);
                if (_enableMove)
                {
                    Vector3 objectPosition = inputEndPosition + (objectRotation * _initialGrabOffset);
                    _Tran.position = objectPosition;
                }
            }
            else //如果等于-1不处理 直接拖拽
            {
                // Rotation(transform, objectRotation);
                if (_enableMove)
                {
                    Vector3 objectPosition = inputEndPosition + (objectRotation * _initialGrabOffset);
                    transform.position = objectPosition;
                }
            }
        }
    }
Пример #8
0
    /// <summary>
    /// 更新拖拽物体的位置旋转信息
    /// </summary>
    /// <param name="inputPosition"></param>
    /// <param name="inputRotation"></param>
    private void UpdateGrab(Vector3 inputPosition, Quaternion inputRotation)
    {
        float d = _initialGrabDistance;

        //if (GlobeData._RightRaycaster._Result.isValid)
        //{

        //    //d = GlobeData._RightRaycaster.FirstRaycastResult().distance;
        //    float newDis = GlobeData._RightRaycaster.FirstRaycastResult().distance;
        //    d = newDis;
        //}
        Vector3    rayDir = GlobeData._RightRaycaster.BreakPoints[1] - GlobeData._RightRaycaster.BreakPoints[0];
        RaycastHit hit;

        if (Physics.Raycast(GlobeData._RightRaycaster.BreakPoints[0], rayDir, out hit))
        {
            d = hit.distance;
        }
        _ViveRaycaster.FarDistance = d;

        if (PlateformData.GetCurrentPlatform() == PlatformType.zSpace)
        {
            Vector3 inputEndPosition = inputPosition + (inputRotation * (Vector3.forward * d));
            Debug.DrawLine(inputPosition, inputEndPosition, Color.black);
            // Update the grab object's rotation.
            Quaternion objectRotation = inputRotation * _initialGrabRotation;
            // Vector3 objectPosition = inputEndPosition + (objectRotation * _initialGrabOffset);
            // Debug.DrawLine(inputPosition, objectPosition, Color.green);
            transform.position = inputEndPosition;
            transform.rotation = objectRotation;
        }
        else if (PlateformData.GetCurrentPlatform() == PlatformType.PC)
        {
            Vector3 inputEndPosition = inputPosition + (inputRotation * (Vector3.forward * d));
            Debug.DrawLine(inputPosition, inputEndPosition, Color.black);
            // Update the grab object's rotation.
            Quaternion objectRotation = inputRotation * _initialGrabRotation;
            // Vector3 objectPosition = inputEndPosition + (objectRotation * _initialGrabOffset);
            // Debug.DrawLine(inputPosition, objectPosition, Color.green);
            transform.position = inputEndPosition;
            //transform.rotation = objectRotation;
        }
    }
Пример #9
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;
     }
 }
Пример #10
0
    /// <summary>
    /// 获取不同屏幕的事件相机,zspace屏默认一定为1屏
    /// </summary>
    /// <returns></returns>
    public static Camera GetCurrentEventCamera()
    {
        Camera current;
        bool   isFirstDisplay  = MultiDisplayUtil.GetCurrentDisplay() == DisplayIndex.Display1;
        bool   isSecondDisplay = MultiDisplayUtil.GetCurrentDisplay() == DisplayIndex.Display2;
        bool   isZspaceDisplay = PlateformData.GetCurrentPlatform() == PlatformType.zSpace;

        if (isFirstDisplay)
        {
            current = isZspaceDisplay ? PlateformData.zCore._screenPointToRayCamera : Camera.main;
        }
        //else if (isSecondDisplay)
        //{
        //    current = GameObject.Find("SecondCamera").GetComponent<Camera>();
        //}
        else
        {
            current = Camera.main;
        }
        return(current);
    }
Пример #11
0
 private void Update()
 {
     if (PlateformData.GetCurrentPlatform() == PlatformType.PC)//鼠标移入时
     {
         if (_enbaleZoom)
         {
             PcScale();
         }
         if (_enableRotate)
         {
             PcRotate();
         }
         if (_enableMove)
         {
             //DragOther();
         }
         if (Input.GetMouseButtonDown(1))
         {
             // OnRightRest();
         }
     }
 }