UnityEditor.CameraState.GetCameraDistance C# (CSharp) Method

GetCameraDistance() public method

public GetCameraDistance ( ) : float
return float
        public float GetCameraDistance()
        {
            float num = 90f;
            return (this.m_ViewSize.value / Mathf.Tan((num * 0.5f) * 0.01745329f));
        }

Usage Example

示例#1
0
        private void HandleCameraMouseDrag(CameraState cameraState, Camera cam)
        {
            Event evt = Event.current;

            switch (m_CurrentViewTool)
            {
            case ViewTool.Orbit:
            {
                OrbitCameraBehavior(cameraState, cam);
            }
            break;

            case ViewTool.FPS:
            {
                Vector3 camPos = cameraState.pivot.value - cameraState.rotation.value * Vector3.forward * cameraState.GetCameraDistance();

                // Normal FPS camera behavior
                Quaternion rotation = cameraState.rotation.value;
                rotation = Quaternion.AngleAxis(evt.delta.y * .003f * Mathf.Rad2Deg, rotation * Vector3.right) * rotation;
                rotation = Quaternion.AngleAxis(evt.delta.x * .003f * Mathf.Rad2Deg, Vector3.up) * rotation;
                cameraState.rotation.value = rotation;
                cameraState.pivot.value    = camPos + rotation * Vector3.forward * cameraState.GetCameraDistance();
            }
            break;

            case ViewTool.Pan:
            {
                cameraState.FixNegativeSize();
                Vector3 screenPos = cam.WorldToScreenPoint(cameraState.pivot.value);
                screenPos += new Vector3(-Event.current.delta.x, Event.current.delta.y, 0);
                Vector3 worldDelta = cam.ScreenToWorldPoint(screenPos) - cameraState.pivot.value;
                if (evt.shift)
                {
                    worldDelta *= 4;
                }
                cameraState.pivot.value += worldDelta;
            }
            break;

            case ViewTool.Zoom:
            {
                float zoomDelta = HandleUtility.niceMouseDeltaZoom * (evt.shift ? 9 : 3);
                m_TotalMotion += zoomDelta;
                if (m_TotalMotion < 0)
                {
                    cameraState.viewSize.value = m_StartZoom * (1 + m_TotalMotion * .001f);
                }
                else
                {
                    cameraState.viewSize.value = cameraState.viewSize.value + zoomDelta * m_ZoomSpeed * .003f;
                }
            }
            break;

            default:
                break;
            }
            evt.Use();
        }
All Usage Examples Of UnityEditor.CameraState::GetCameraDistance