public override void Update(CameraState cameraState, Camera cam)
        {
            Event current = Event.current;
            if (current.type == EventType.MouseUp)
            {
                this.m_CurrentViewTool = ViewTool.None;
            }
            if (current.type == EventType.MouseDown)
            {
                int button = current.button;
                bool flag = current.control && (Application.platform == RuntimePlatform.OSXEditor);
                if (button == 2)
                {
                    this.m_CurrentViewTool = ViewTool.Pan;
                }
                else if (((button <= 0) && flag) || ((button == 1) && current.alt))
                {
                    this.m_CurrentViewTool = ViewTool.Zoom;
                    this.m_StartZoom = cameraState.viewSize.value;
                    this.m_ZoomSpeed = Mathf.Max(Mathf.Abs(this.m_StartZoom), 0.3f);
                    this.m_TotalMotion = 0f;
                }
                else if (button <= 0)
                {
                    this.m_CurrentViewTool = ViewTool.Orbit;
                }
                else if ((button == 1) && !current.alt)
                {
                    this.m_CurrentViewTool = ViewTool.FPS;
                }
            }
            switch (current.type)
            {
                case EventType.MouseUp:
                    this.HandleCameraMouseUp();
                    break;

                case EventType.MouseDrag:
                    this.HandleCameraMouseDrag(cameraState, cam);
                    break;

                case EventType.KeyDown:
                    this.HandleCameraKeyDown();
                    break;

                case EventType.KeyUp:
                    this.HandleCameraKeyUp();
                    break;

                case EventType.ScrollWheel:
                    this.HandleCameraScrollWheel(cameraState);
                    break;

                case EventType.Layout:
                {
                    Vector3 movementDirection = this.GetMovementDirection();
                    if (movementDirection.sqrMagnitude != 0f)
                    {
                        cameraState.pivot.value += cameraState.rotation.value * movementDirection;
                    }
                    break;
                }
            }
        }
 private void OrbitCameraBehavior(CameraState cameraState, Camera cam)
 {
     Event current = Event.current;
     cameraState.FixNegativeSize();
     Quaternion target = cameraState.rotation.target;
     target = Quaternion.AngleAxis((current.delta.y * 0.003f) * 57.29578f, (Vector3) (target * Vector3.right)) * target;
     target = Quaternion.AngleAxis((current.delta.x * 0.003f) * 57.29578f, Vector3.up) * target;
     if (cameraState.viewSize.value < 0f)
     {
         cameraState.pivot.value = cam.transform.position;
         cameraState.viewSize.value = 0f;
     }
     cameraState.rotation.value = target;
 }
 private void HandleCameraScrollWheel(CameraState cameraState)
 {
     float y = Event.current.delta.y;
     float num2 = (Mathf.Abs(cameraState.viewSize.value) * y) * 0.015f;
     if ((num2 > 0f) && (num2 < 0.3f))
     {
         num2 = 0.3f;
     }
     else if ((num2 < 0f) && (num2 > -0.3f))
     {
         num2 = -0.3f;
     }
     AnimFloat viewSize = cameraState.viewSize;
     viewSize.value += num2;
     Event.current.Use();
 }
        private void HandleCameraMouseDrag(CameraState cameraState, Camera cam)
        {
            Event current = Event.current;
            switch (this.m_CurrentViewTool)
            {
                case ViewTool.Orbit:
                    this.OrbitCameraBehavior(cameraState, cam);
                    break;

                case ViewTool.Pan:
                {
                    cameraState.FixNegativeSize();
                    Vector3 position = cam.WorldToScreenPoint(cameraState.pivot.value) + new Vector3(-Event.current.delta.x, Event.current.delta.y, 0f);
                    Vector3 vector7 = cam.ScreenToWorldPoint(position) - cameraState.pivot.value;
                    if (current.shift)
                    {
                        vector7 = (Vector3) (vector7 * 4f);
                    }
                    AnimVector3 pivot = cameraState.pivot;
                    pivot.value += vector7;
                    break;
                }
                case ViewTool.Zoom:
                {
                    float num = HandleUtility.niceMouseDeltaZoom * (!current.shift ? ((float) 3) : ((float) 9));
                    this.m_TotalMotion += num;
                    if (this.m_TotalMotion >= 0f)
                    {
                        cameraState.viewSize.value += (num * this.m_ZoomSpeed) * 0.003f;
                        break;
                    }
                    cameraState.viewSize.value = this.m_StartZoom * (1f + (this.m_TotalMotion * 0.001f));
                    break;
                }
                case ViewTool.FPS:
                {
                    Vector3 vector = cameraState.pivot.value - ((Vector3) ((cameraState.rotation.value * Vector3.forward) * cameraState.GetCameraDistance()));
                    Quaternion quaternion = cameraState.rotation.value;
                    quaternion = Quaternion.AngleAxis((current.delta.y * 0.003f) * 57.29578f, (Vector3) (quaternion * Vector3.right)) * quaternion;
                    quaternion = Quaternion.AngleAxis((current.delta.x * 0.003f) * 57.29578f, Vector3.up) * quaternion;
                    cameraState.rotation.value = quaternion;
                    cameraState.pivot.value = vector + ((Vector3) ((quaternion * Vector3.forward) * cameraState.GetCameraDistance()));
                    break;
                }
            }
            current.Use();
        }
 public abstract void Update(CameraState cameraState, Camera cam);
示例#6
0
 public void Copy(CameraState cameraStateIn)
 {
     this.pivot.value = cameraStateIn.pivot.value;
     this.rotation.value = cameraStateIn.rotation.value;
     this.viewSize.value = cameraStateIn.viewSize.value;
 }