예제 #1
0
        // Finds the ThirdPersonBrain and automatically sets up the required fields for the Cinemachine cameras
        void FindThirdPersonBrain(bool autoDisable)
        {
            if (m_ThirdPersonBrain == null)
            {
                ThirdPersonBrain[] thirdPersonBrainObjects = FindObjectsOfType <ThirdPersonBrain>();
                int  length = thirdPersonBrainObjects.Length;
                bool found  = true;
                if (length != 1)
                {
                    string errorMessage = "No ThirdPersonBrain in scene! Disabling Camera Controller";
                    if (length > 1)
                    {
                        errorMessage = "Too many ThirdPersonBrains in scene! Disabling Camera Controller";
                    }
                    else         // none found
                    {
                        found = false;
                    }

                    if (autoDisable)
                    {
                        Debug.LogError(errorMessage);
#if UNITY_EDITOR
                        EditorUtility.DisplayDialog("Error detecting ThirdPersonBrain", errorMessage, "Ok");
#endif
                        gameObject.SetActive(false);
                    }
                }

                if (found)
                {
                    m_ThirdPersonBrain = thirdPersonBrainObjects[0];
                }
                else
                {
                    return;
                }
            }

            //auto-set up the necessary state driven camera data
            m_SDC = GetComponent <CinemachineStateDrivenCamera>();
            if (m_SDC != null)
            {
                m_SDC.m_LookAt         = m_ThirdPersonBrain.vcamTarget;
                m_SDC.m_Follow         = m_ThirdPersonBrain.vcamTarget;
                m_SDC.m_AnimatedTarget = m_ThirdPersonBrain.GetComponent <Animator>();
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes the motor
        /// </summary>
        /// <param name="brain"><see cref="ThirdPersonBrain"/> calling the initialization</param>
        public void Init(ThirdPersonBrain brain)
        {
            m_MainCamera                     = Camera.main;
            m_GameObject                     = brain.gameObject;
            m_Transform                      = brain.transform;
            m_ThirdPersonBrain               = brain;
            m_CharacterInput                 = brain.thirdPersonInput;
            m_ControllerAdapter              = brain.controllerAdapter;
            m_Animator                       = m_GameObject.GetComponent <Animator>();
            m_AverageForwardVelocity         = new SlidingAverage(m_Configuration.jumpGroundVelocityWindowSize);
            m_ExplorationAverageForwardInput = new SlidingAverage(m_Configuration.forwardInputWindowSize);
            m_StrafeAverageForwardInput      = new SlidingAverage(m_Configuration.strafeInputWindowSize);
            m_StrafeAverageLateralInput      = new SlidingAverage(m_Configuration.strafeInputWindowSize);
            m_PreviousInputs                 = new SizedQueue <Vector2>(m_Configuration.bufferSizeInput);
            movementMode                     = ThirdPersonMotorMovementMode.Exploration;

            EndStrafe();
        }
 /// <inheritdoc/>
 public override void Init(ThirdPersonBrain brain)
 {
     m_Transform        = brain.transform;
     m_ThirdPersonBrain = brain;
 }
 /// <summary>
 /// Initializes the turn around behaviour.
 /// </summary>
 public abstract void Init(ThirdPersonBrain brain);
 /// <summary>
 /// Gives the <see cref="ThirdPersonMovementEventHandler"/> context of the <see cref="ThirdPersonBrain"/>
 /// </summary>
 /// <param name="brainToUse">The <see cref="ThirdPersonBrain"/> that called Init</param>
 public void Init(ThirdPersonBrain brainToUse)
 {
     base.Init(brainToUse);
     m_ThirdPersonBrain = brainToUse;
 }