Exemple #1
0
    /// <summary>
    /// Plays a camera animation asset. Camera animation assets can be found in the asset menu.
    /// Animation will automatically accomadate for character size and orientation and follow the character.
    /// </summary>
    /// <param name="target"> The target of the animation. Its bounds are used to determine certain paramters. </param>
    /// <param name="camAnim"> Camera animation asset to play. </param>
    public void PlayAnimation(Collider target, CameraAnimation camAnim)
    {
        /* Disable Animator */
        Animator.enabled = false;

        /* De-Parent the Camera */
        transform.parent = null;

        /* Determine If The Camera Should Be Mirrored.
         * The camera should be mirrored if the angle between the arena's designated foward direction
         * and the targets right direction are more than 90 degrees apart. */
        float m = Vector3.Dot(BattleManager.instance.center.transform.right, target.transform.forward) < 0 ? -1 : 1;

        /* Offset The Camera's Position From Targets Center By Starting Offset */
        transform.position = new Vector3(
            camAnim.startOffset.x * m,
            camAnim.startOffset.y,
            camAnim.startOffset.z) +
                             target.bounds.center;

        /* Locally Rotate The Camera By Starting Angle */
        transform.rotation = Quaternion.Euler(new Vector3(
                                                  camAnim.startAngle.x,
                                                  camAnim.startAngle.y * m,
                                                  camAnim.startAngle.z));

        /* Start Animating The Camera */
        this.StartInterruptableCoroutine(camAnim.Animate(target, cam, m), ref currentRoutine);
    }