// Finds the FirstPersonBrain and automatically sets up the required fields for the Cinemachine cameras
        void FindFirstPersonBrain(bool autoDisable)
        {
            if (m_FirstPersonBrain == null)
            {
                FirstPersonBrain[] firstPersonBrains = FindObjectsOfType <FirstPersonBrain>();
                int  length = firstPersonBrains.Length;
                bool found  = true;
                if (length != 1)
                {
                    string errorMessage = "No FirstPersonBrain in scene! Disabling Camera Controller";
                    if (length > 1)
                    {
                        errorMessage = "Too many FirstPersonBrain in scene! Disabling Camera Controller";
                    }
                    else // none found
                    {
                        found = false;
                    }

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

                if (found)
                {
                    m_FirstPersonBrain = firstPersonBrains[0];
                }
                else
                {
                    return;
                }

                var rootSdc = GetComponent <CinemachineStateDrivenCamera>();
                if (rootSdc != null)
                {
                    rootSdc.m_Follow = m_FirstPersonBrain.transform;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Initializes the handler with the correct character brain and sets up the transform and previousPosition needed to calculate distance travelled
 /// </summary>
 /// <param name="brainToUse"></param>
 public void Init(FirstPersonBrain brainToUse)
 {
     base.Init(brainToUse);
     m_Transform        = brainToUse.transform;
     m_PreviousPosition = m_Transform.position;
 }