/// <summary> /// Serialize all of the view tyoes to the ViewTypeData array. /// </summary> private void SerializeViewTypes() { ViewTypeBuilder.SerializeViewTypes(m_CameraController); // Update the default first and third person view types based off of the new view type list. UpdateDefaultViewTypes(); Shared.Editor.Utility.EditorUtility.SetDirty(target); }
/// <summary> /// Adds the view type with the specified type. /// </summary> private void AddViewType(object obj) { var viewType = ViewTypeBuilder.AddViewType(m_CameraController, obj as Type); m_ReorderableViewTypeList.displayRemove = m_CameraController.ViewTypes.Length > 1; // Select the newly added view type. m_ReorderableViewTypeList.index = m_CameraController.ViewTypes.Length - 1; EditorPrefs.SetInt(SelectedViewTypeIndexKey, m_ReorderableViewTypeList.index); // The view type's state list should start out fresh to prevent the old view type states from being shown. m_ReorderableViewTypeStateList = null; // Allow the view type to perform any initialization. var inspectorDrawer = Shared.Editor.Inspectors.Utility.InspectorDrawerUtility.InspectorDrawerForType(viewType.GetType()) as ViewTypeInspectorDrawer; if (inspectorDrawer != null) { inspectorDrawer.ViewTypeAdded(viewType, target); } }
/// <summary> /// Sets up the camera if it hasn't already been setup. /// </summary> private void SetupCamera() { // Setup the camera. GameObject cameraGameObject; var addedCameraController = false; var camera = UnityEngine.Camera.main; if (camera == null) { // If the main camera can't be found then use the first available camera. var cameras = UnityEngine.Camera.allCameras; if (cameras != null && cameras.Length > 0) { // Prefer cameras that are at the root level. for (int i = 0; i < cameras.Length; ++i) { if (cameras[i].transform.parent == null) { camera = cameras[i]; break; } } // No cameras are at the root level. Set the first available camera. if (camera == null) { camera = cameras[0]; } } // A new camera should be created if there isn't a valid camera. if (camera == null) { cameraGameObject = new GameObject("Camera"); cameraGameObject.tag = "MainCamera"; camera = cameraGameObject.AddComponent <UnityEngine.Camera>(); cameraGameObject.AddComponent <AudioListener>(); } } // The near clip plane should adjusted for viewing close objects. camera.nearClipPlane = 0.01f; // Add the CameraController if it isn't already added. cameraGameObject = camera.gameObject; if (cameraGameObject.GetComponent <CameraController>() == null) { var cameraController = cameraGameObject.AddComponent <CameraController>(); if (m_Perspective == Perspective.Both) { ViewTypeBuilder.AddViewType(cameraController, typeof(UltimateCharacterController.Camera.ViewTypes.Transition)); } if (m_StartFirstPersonPerspective) { if (!string.IsNullOrEmpty(m_ThirdPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, Shared.Utility.TypeUtility.GetType(m_ThirdPersonViewType)); } if (!string.IsNullOrEmpty(m_FirstPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, Shared.Utility.TypeUtility.GetType(m_FirstPersonViewType)); } } else { if (!string.IsNullOrEmpty(m_FirstPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, Shared.Utility.TypeUtility.GetType(m_FirstPersonViewType)); } if (!string.IsNullOrEmpty(m_ThirdPersonViewType)) { ViewTypeBuilder.AddViewType(cameraController, Shared.Utility.TypeUtility.GetType(m_ThirdPersonViewType)); } } // Detect if a character exists in the scene. Automatically add the character if it does. var characters = UnityEngine.Object.FindObjectsOfType <UltimateCharacterController.Character.CharacterLocomotion>(); if (characters != null && characters.Length == 1) { cameraController.InitCharacterOnAwake = true; cameraController.Character = characters[0].gameObject; } // Setup the components which help the Camera Controller. Shared.Editor.Inspectors.Utility.InspectorUtility.AddComponent <CameraControllerHandler>(cameraGameObject); #if THIRD_PERSON_CONTROLLER if (m_Perspective != Perspective.First) { Shared.Editor.Inspectors.Utility.InspectorUtility.AddComponent <ThirdPersonController.Camera.ObjectFader>(cameraGameObject); } #endif addedCameraController = true; if (m_StateConfiguration != null) { if (m_ProfileIndex > 0) { m_StateConfiguration.AddStatesToGameObject(m_ProfileName, cameraGameObject); Shared.Editor.Utility.EditorUtility.SetDirty(cameraGameObject); } } } if (addedCameraController) { Debug.Log("The Camera Controller has been added."); } else { Debug.LogWarning("Warning: No action was performed, the Camera Controller component has already been added."); } }