コード例 #1
0
    private BlendedCameraBehavior AddNewBehavior(GameCameraBehavior newGameCamera, CameraLerp lerp)
    {
        if (GetNewestRunningBehaviorIndex() >= 0)                                                                                       // if there are any behaviors currently
        {
            if (GameCameraBehavior.AreInputParametersEqual(_runningBehaviors[GetNewestRunningBehaviorIndex()].behavior, newGameCamera)) // are we trying to add an exact same behavior?
            {
                return(null);                                                                                                           // no need to add a duplicate
            }

            if (BlendedCameraBehavior.IsTransitionImmediate(lerp)) // if it is a cut
            {
                _runningBehaviors.Clear();                         // can remove everything currently in the list as it will not effect output after cutting to new camera
            }
        }

        BlendedCameraBehavior newRunningBehavior = new BlendedCameraBehavior(lerp, newGameCamera);

        _runningBehaviors.Add(newRunningBehavior);

#if UNITY_EDITOR
        if (null != theEditor)
        {
            theEditor.Repaint();
        }
#endif
        return(newRunningBehavior);
    }
コード例 #2
0
    // are the input parameters to the two cameras the same, meaning the two cameras will have the same behavior
    static public bool AreInputParametersEqual(GameCameraBehavior behaviorOne, GameCameraBehavior behaviorTwo)
    {
        if (behaviorOne == behaviorTwo)         // the camera instances are the same (could both be null)
        {
            return(true);
        }
        else if (null == behaviorOne || null == behaviorTwo)         // one is null
        {
            return(false);
        }

        if (!AreInputParametersEquivalent(behaviorOne, behaviorTwo))
        {
            return(false);
        }
        return(AreInputTargetListsEquivalent(behaviorOne, behaviorTwo));
    }
コード例 #3
0
    protected void UpdateCameraBehaviors(float delatTime)
    {
        //if (Application.isPlaying) // we only want the output from the running behaviors if we're playing
        //{
        for (int running = GetOldestRunningBehaviorIndex(); running <= GetNewestRunningBehaviorIndex(); ++running)
        {
            if (_gameCamera != _runningBehaviors[running].behavior)                     // we don't tick the game camera here, as that is already ticked in the update function
            {
                _runningBehaviors[running].behavior.Update(this, delatTime);
            }

            if (!_runningBehaviors[running].HasLerpStyleBeenSet())
            {
                GameCameraBehavior olderBehavior = (GetOldestRunningBehaviorIndex() == running) ? null : _runningBehaviors[running - 1].behavior;
                _runningBehaviors[running].lerpStyle = CameraLerp.DetermineBestLerpStyle(olderBehavior, _runningBehaviors[running].behavior);
            }

            _runningBehaviors[running].behavior.GetLookAt(ref _runningBehaviorResult.lookAt);
            _runningBehaviors[running].behavior.GetRotation(ref _runningBehaviorResult.rotation);
            _runningBehaviorResult.distFromLookAt = _runningBehaviors[running].behavior.GetDistFromLookAt();

            // oldest camera is always fully blended in
            float lerp = 1f;
            if (NeedCalculateLerp(running))
            {
                lerp = Mathf.Clamp01(_runningBehaviors[running].CalculateLerpValue());
            }
            float smoothedLerp      = 1f;
            float smoothedLerpPitch = 1f;
            float smoothedLerpYaw   = 1f;
            if (NeedSmoothRunningBehavior(running))                     // not the oldest running cam and not fully blended in
            {
                smoothedLerp      = Cinematic.Smooth(lerp, _runningBehaviors[running].lerp.dialogueCameraLerpSmoothing, _runningBehaviors[running].lerp.animationCurve);
                smoothedLerpPitch = Cinematic.Smooth(lerp, _runningBehaviors[running].lerp.pitchLerpSmoothing, _runningBehaviors[running].lerp.curvePitchLerp);
                smoothedLerpYaw   = Cinematic.Smooth(lerp, _runningBehaviors[running].lerp.yawLerpSmoothing, _runningBehaviors[running].lerp.curveYawLerp);
            }
            BlendedCameraBehavior.BlendedCameraOutput.Lerp(ref _blendedResult, ref _blendedResult, ref _runningBehaviorResult,
                                                           _runningBehaviors[running].lerpStyle, smoothedLerp, smoothedLerpPitch, smoothedLerpYaw);
            _gameCameraPosition = _blendedResult.CalculatePosition();
            _gameCameraRotation = _blendedResult.rotation;
        }
        //}
        RemoveRunningBehaviors();
    }
コード例 #4
0
 // check the target lists are the same
 private static bool AreInputTargetListsEquivalent(GameCameraBehavior behaviorOne, GameCameraBehavior behaviorTwo)
 {
     if (behaviorOne._targets == behaviorTwo._targets)         // the camera target instances are the same
     {
         return(true);
     }
     if (null != behaviorOne._targets && null != behaviorTwo._targets && behaviorOne._targets.Count == behaviorTwo._targets.Count)         // target lists are the same length
     {
         for (int singleTarget = 0; singleTarget < behaviorOne._targets.Count; ++singleTarget)
         {
             if (!behaviorTwo._targets.Contains(behaviorOne._targets[singleTarget]))                 // if a target is in one list but not the other
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
コード例 #5
0
    // check the conversations are equivalent
    static private bool AreInputParametersEquivalent(GameCameraBehavior behaviorOne, GameCameraBehavior behaviorTwo)
    {
        if (null == behaviorOne._params && null == behaviorTwo._params)      // both null
        {
            return(true);                                                    // the same
        }
        else if (null != behaviorOne._params && null != behaviorTwo._params) // are both non null
        {
            return(behaviorOne._params == behaviorTwo._params);              // the same
        }

        // one is null and one is not null
        if (null == behaviorOne._params)
        {
            return(behaviorTwo._params.gameCamera);            // null is equivalent to game camera
        }
        // null == conversationtwo
        return(behaviorOne._params.gameCamera);        // null is equivalent to game camera
    }
コード例 #6
0
    static public LerpStyle DetermineBestLerpStyle(GameCameraBehavior from, GameCameraBehavior to)
    {
        if (null != from && null != to)
        {
            Vector3 fromLookAt = Vector3.zero;
            from.GetLookAt(ref fromLookAt);

            Vector3 toLookAt = Vector3.zero;
            to.GetLookAt(ref toLookAt);

            const float CloseTol = 0.5f;
            // if the look at points are close to one and other we should try and keep them on screen throughout
            if (GameUtils.GetDistSqXZ(fromLookAt, toLookAt) < GameUtils.Square(CloseTol))
            {
                return(LerpStyle.keepTargetOnScreen);
            }
        }
        return(LerpStyle.positionToPosition);
    }
コード例 #7
0
        public BlendedCameraBehavior(CameraLerp lerp, GameCameraBehavior behavior)
        {
            if (Application.isPlaying)
            {
                transitionStartTime = Time.time;
            }
            else
            {
                transitionStartTime = Time.realtimeSinceStartup;
            }
            this.lerp = lerp;

            if (null != lerp)
            {
                lerpStyle = lerp.lerpStyle;
            }
            else
            {
                lerpStyle = CameraLerp.LerpStyle.positionToPosition;
            }
            this.behavior = behavior;
        }
コード例 #8
0
    public virtual BlendedCameraBehavior EnterInteractionCamera(ref List <GameObject> targets, ref GameCameraParams gameCamParams, CameraLerp lerp)
    {
        GameCameraBehavior newGameCamera = new GameCameraBehavior(ref targets, ref gameCamParams, this);

        return(AddNewBehavior(newGameCamera, lerp));
    }