Пример #1
0
            private void ResetCameraState()
            {
                AnimatedCamera camera = (AnimatedCamera)target;

                if (camera != null)
                {
                    camera.SetState(_cameraOrigState);
                }
            }
Пример #2
0
            private void UpdateCameraFromSnapshot()
            {
                AnimatedCamera camera = (AnimatedCamera)target;

                if (_currentSnapshot != null)
                {
                    camera.SetState(_currentSnapshot.GetState());
                }
            }
Пример #3
0
            private void UpdateSnapshotFromCamera(IAnimatedCameraStateSource snapshot)
            {
                AnimatedCamera camera = (AnimatedCamera)target;

                if (snapshot != null)
                {
                    snapshot.SetState(camera.GetState());
                }
            }
Пример #4
0
            private void UpdateKeys()
            {
                if (AllowFreeCam())
                {
                    Vector3 movement = Vector3.zero;
                    bool    held     = false;

                    if (_buttonPressed.TryGetValue(KeyCode.A, out held) && held)
                    {
                        movement.x -= 1.0f;
                    }
                    if (_buttonPressed.TryGetValue(KeyCode.D, out held) && held)
                    {
                        movement.x += 1.0f;
                    }
                    if (_buttonPressed.TryGetValue(KeyCode.W, out held) && held)
                    {
                        if (_buttonPressed.TryGetValue(KeyCode.CapsLock, out held) && held)
                        {
                            movement.y += 1.0f;
                        }
                        else
                        {
                            movement.z += 1.0f;
                        }
                    }
                    if (_buttonPressed.TryGetValue(KeyCode.S, out held) && held)
                    {
                        if (_buttonPressed.TryGetValue(KeyCode.CapsLock, out held) && held)
                        {
                            movement.y -= 1.0f;
                        }
                        else
                        {
                            movement.z -= 1.0f;
                        }
                    }

                    AnimatedCamera camera = (AnimatedCamera)target;

                    float speed = kMovementSpeed;

                    if (_buttonPressed.TryGetValue(KeyCode.Space, out held) && held)
                    {
                        speed = kFastMovementSpeed;
                    }

                    camera.transform.Translate(movement * speed, Space.Self);

                    UpdateSnapshotFromCamera(_currentSnapshot);
                }

                if (_currentSnapshot == null)
                {
                    CacheCameraState();
                }
            }
Пример #5
0
            public virtual AnimatedCameraState InterpolateTo(AnimatedCamera camera, AnimatedCameraState to, eInterpolation ease, float t)
            {
                AnimatedCameraState state = new AnimatedCameraState();

                state._position    = MathUtils.Interpolate(ease, _position, to._position, t);
                state._rotation    = MathUtils.Interpolate(ease, _rotation, to._rotation, t);
                state._fieldOfView = MathUtils.Interpolate(ease, _fieldOfView, to._fieldOfView, t);
                state._cameraRect  = MathUtils.Interpolate(ease, _cameraRect, to._cameraRect, t);

                return(state);
            }
            public eEventTriggerReturn Trigger(StateMachineComponent stateMachine)
            {
                AnimatedCamera camera = _camera;

                if (camera != null)
                {
                    AnimatedCamera.Animation animation = new AnimatedCamera.Animation(_snapshot.GetComponent().GetState());
                    camera.SetAnimation(animation, _blendEaseType, _blendTime);
                }

                return(eEventTriggerReturn.EventFinished);
            }
Пример #7
0
            public override void ProcessFrame(Playable playable, FrameData info, object playerData)
            {
                _trackBinding = playerData as AnimatedCamera;

                if (_trackBinding == null)
                {
                    return;
                }

                if (!_firstFrameHappened)
                {
                    _defaultState       = _trackBinding.GetState();
                    _firstFrameHappened = true;
                }

                AnimatedCameraState blendedState = _defaultState;

                int inputPort = 0;

                foreach (TimelineClip clip in _clips)
                {
                    ScriptPlayable <AnimatedCameraPlayableBehaviour> scriptPlayable = (ScriptPlayable <AnimatedCameraPlayableBehaviour>)playable.GetInput(inputPort);
                    AnimatedCameraPlayableBehaviour inputBehaviour = scriptPlayable.GetBehaviour();

                    if (inputBehaviour != null)
                    {
                        double clipStart    = clip.hasPreExtrapolation ? clip.extrapolatedStart : clip.start;
                        double clipDuration = clip.hasPreExtrapolation || clip.hasPostExtrapolation ? clip.extrapolatedDuration : clip.duration;

                        //If currently playing
                        if (_director.time >= clipStart && _director.time <= clipStart + clipDuration)
                        {
                            float inputWeight = playable.GetInputWeight(inputPort);

                            AnimatedCameraState behaviourState = inputBehaviour._snapshot.GetState();

                            //Interpolated behavior
                            if (inputBehaviour._snapshotTo != null)
                            {
                                double clipT = Math.Min(Math.Max(_director.time - clip.start, 0.0) / clip.duration, 1.0);
                                behaviourState = behaviourState.InterpolateTo(_trackBinding, inputBehaviour._snapshotTo.GetState(), inputBehaviour._easeType, (float)clipT);
                            }

                            //Fade playable over current state using its weight
                            blendedState = blendedState.InterpolateTo(_trackBinding, behaviourState, eInterpolation.Linear, inputWeight);
                        }
                    }

                    ++inputPort;
                }

                _trackBinding.SetState(blendedState);
            }
Пример #8
0
            private void HandleMouseDrag(Event evnt)
            {
                if (AllowFreeCam())
                {
                    AnimatedCamera camera      = (AnimatedCamera)target;
                    Vector3        eulerAngles = camera.transform.eulerAngles;
                    eulerAngles += new Vector3(evnt.delta.y / Camera.current.pixelRect.height, evnt.delta.x / Camera.current.pixelRect.width, 0.0f) * kMouseLookSpeed;
                    camera.transform.eulerAngles = eulerAngles;

                    if (_currentSnapshot != null)
                    {
                        UpdateSnapshotFromCamera(_currentSnapshot);
                    }
                }

                Event.current.Use();
            }
            public eEventTriggerReturn Trigger(StateMachineComponent stateMachine)
            {
                AnimatedCamera camera = _camera;

                if (camera != null)
                {
                    AnimatedCamera.Animation animation = new AnimatedCamera.Animation();
                    animation._states = new AnimatedCameraState[_animationSnapshots.Length];
                    for (int i = 0; i < _animationSnapshots.Length; i++)
                    {
                        animation._states[i] = _animationSnapshots[i].GetComponent().GetState();
                    }
                    animation._duration = _animationDuration;
                    animation._easeType = _animationEaseType;
                    animation._wrapMode = _animationWrapMode;

                    camera.SetAnimation(animation, _blendEaseType, _blendTime);
                }

                return(eEventTriggerReturn.EventFinished);
            }
Пример #10
0
    void Start()
    {
        /* For All Cameras */
        foreach (AnimatedCamera animtedCam in animatedCameras)
        {
            /* If Main Camera NOT Assigned */
            if (mainCam == null)
            {
                /* Assign Main Camera and Enable This Camera */
                mainCam             = animtedCam;
                mainCam.cam         = mainCam.animControl.GetComponent <Camera>();
                mainCam.cam.enabled = true;
            }

            /* Else, Disable This Camera */
            else
            {
                animtedCam.cam         = animtedCam.animControl.GetComponent <Camera>();
                animtedCam.cam.enabled = false;
            }
        }
    }
Пример #11
0
            protected void DrawCameraProperties()
            {
                AnimatedCamera camera = (AnimatedCamera)target;

                EditorGUI.BeginChangeCheck();
                float fieldOfView = EditorGUILayout.Slider("Field of View", camera.GetCamera().fieldOfView, 1.0f, 180.0f);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(camera.GetCamera(), "Changed Field of View");
                    camera.GetCamera().fieldOfView = fieldOfView;
                }

                EditorGUI.BeginChangeCheck();
                Rect rect = EditorGUILayout.RectField("Viewport Rect", camera.GetCamera().rect);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(camera.GetCamera(), "Changed Viewport Rect");
                    camera.GetCamera().rect = rect;
                }
            }
Пример #12
0
            private void CacheCameraState()
            {
                AnimatedCamera camera = (AnimatedCamera)target;

                _cameraOrigState = camera.GetState();
            }
Пример #13
0
            private bool DrawSnapshotDropdown()
            {
                AnimatedCamera camera = (AnimatedCamera)target;

                IAnimatedCameraStateSource[] snapshots = SceneUtils.FindAllComponentInferfacesInScene <IAnimatedCameraStateSource>(camera.gameObject.scene);

                int index        = 0;
                int currentIndex = -1;

                string[] snapshotNames = new string[snapshots.Length + 2];
                snapshotNames[index++] = "(None)";

                foreach (IAnimatedCameraStateSource snapshot in snapshots)
                {
                    snapshotNames[index] = snapshot.GetName();

                    if (snapshot == _currentSnapshot)
                    {
                        currentIndex = index;
                    }

                    index++;
                }

                snapshotNames[index++] = "(New Snapshot)";

                int newIndex = EditorGUILayout.Popup("Edit Snapshot", currentIndex == -1 ? 0 : currentIndex, snapshotNames);

                if (currentIndex != newIndex)
                {
                    if (newIndex == 0)
                    {
                        SetCurrentSnapshot(null);
                    }
                    else if (newIndex == snapshotNames.Length - 1)
                    {
                        //Add new snapshot!
                        GameObject newObj = new GameObject("Snapshot" + newIndex);
                        newObj.transform.parent   = camera.transform.parent;
                        newObj.transform.position = camera.transform.position;
                        newObj.transform.rotation = camera.transform.rotation;

                        IAnimatedCameraStateSource newSnapShot = newObj.AddComponent(camera.GetAnimatedCameraStateSourceType()) as IAnimatedCameraStateSource;
                        if (newSnapShot != null)
                        {
                            UpdateSnapshotFromCamera(newSnapShot);
                            SetCurrentSnapshot(newSnapShot);
                        }

                        return(true);
                    }
                    else
                    {
                        SetCurrentSnapshot(snapshots[newIndex - 1]);
                    }
                }

                DrawCameraProperties();

                return(false);
            }
Пример #14
0
            private void RenderGamePreview(Event evnt)
            {
                if (_currentSnapshot != null)
                {
                    AnimatedCamera camera = (AnimatedCamera)target;

                    Rect sceneViewRect = Camera.current.pixelRect;
                    int  viewWidth     = (int)sceneViewRect.width;
                    int  viewHeight    = (int)sceneViewRect.height;

                    //If at this height the width is to big, need to make height less
                    if (viewHeight * kAspectRatio > viewWidth)
                    {
                        viewHeight = (int)(sceneViewRect.width * (1f / kAspectRatio));
                    }
                    //If at this height the height is to big, need to make width less
                    if (viewWidth * (1f / kAspectRatio) > viewHeight)
                    {
                        viewWidth = (int)(sceneViewRect.height * kAspectRatio);
                    }

                    if (_targetTexture == null || viewWidth != _targetTexture.width || viewHeight != _targetTexture.height)
                    {
                        if (_targetTexture == null)
                        {
                            _targetTexture = new RenderTexture(viewWidth, viewHeight, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                        }
                        else
                        {
                            _targetTexture.Release();
                        }

                        _targetTexture.width        = viewWidth;
                        _targetTexture.height       = viewHeight;
                        _targetTexture.antiAliasing = 1;
                        _targetTexture.Create();
                    }

                    if (_targetTexture.IsCreated())
                    {
                        //Render scene - need better way of grabbng post fx
                        RenderTexture active = RenderTexture.active;
                        RenderTexture.active = _targetTexture;
                        GL.Clear(true, true, Color.clear);
                        RenderTexture.active = active;

                        RenderCameras();

                        //Render on screen
                        GUI.BeginGroup(sceneViewRect);

                        //Clear screen to black
                        Color guiColor = GUI.color;
                        GUI.color = Color.black;
                        GUI.DrawTexture(sceneViewRect, EditorUtils.OnePixelTexture);
                        GUI.color = guiColor;

                        //Render game texture to screen
                        Rect viewRect = new Rect();
                        viewRect.width  = viewWidth;
                        viewRect.height = viewHeight;
                        viewRect.x      = (sceneViewRect.width - viewRect.width) * 0.5f;
                        viewRect.y      = (sceneViewRect.height - viewRect.height) * 0.5f;
                        GUI.DrawTexture(GetFlippedRect(viewRect), _targetTexture, ScaleMode.StretchToFill, false);

                        GUI.EndGroup();
                    }
                }
            }