/// <summary> /// Sets the starting perspective on the character. /// </summary> /// <param name="firstPersonPerspective">Should the character start in a first person perspective?</param> /// <param name="teleport">Should the character be teleported to the demo zone?</param> protected void SelectStartingPerspective(bool firstPersonPerspective, bool teleport) { m_CharacterLocomotion.SetActive(true, true); // Set the starting position. m_LastZoneIndex = -1; ActiveDemoZone(m_DemoZones[0], teleport); // Set the perspective on the camera. var camera = UnityEngineUtility.FindCamera(null); var cameraController = camera.GetComponent <Camera.CameraController>(); // Ensure the camera starts with the correct view type. cameraController.FirstPersonViewTypeFullName = GetViewTypeFullName(true); cameraController.ThirdPersonViewTypeFullName = GetViewTypeFullName(false); cameraController.SetPerspective(firstPersonPerspective, true); cameraController.Character = m_Character; // The cursor should be hidden to start the demo. Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; enabled = false; // The character and camera are ready to go - disable the perspective selection panel. if (m_PerspectiveSelection != null) { m_PerspectiveSelection.SetActive(false); } }
/// <summary> /// Initialize the default values. /// </summary> private void Start() { #if !FIRST_PERSON_CONTROLLER || !THIRD_PERSON_CONTROLLER var demoZones = new List <DemoZone>(m_DemoZones); for (int i = demoZones.Count - 1; i > -1; --i) { // The demo zone may belong to the other perspective. if (demoZones[i].DemoZoneTrigger == null) { demoZones.RemoveAt(i); } } m_DemoZones = demoZones.ToArray(); #endif for (int i = 0; i < m_DemoZones.Length; ++i) { if (m_DemoZones[i].TeleportLocation == null) { continue; } m_DemoZones[i].Initialize(i); m_DemoZoneTriggerDemoZoneMap.Add(m_DemoZones[i].DemoZoneTrigger, m_DemoZones[i]); } // Enable the UI after the character has spawned. m_TextPanel.SetActive(false); m_PreviousZoneArrow.SetActive(false); m_NextZoneArrow.SetActive(false); m_Action.enabled = false; m_CharacterLocomotion = m_Character.GetComponent <UltimateCharacterLocomotion>(); m_CharacterHealth = m_Character.GetComponent <Health>(); m_CharacterRespawner = m_Character.GetComponent <Respawner>(); // Disable the demo components if the character is null. This allows for free roaming within the demo scene. if (m_FreeRoam) { m_FullAccess = true; if (m_PerspectiveSelection != null) { m_PerspectiveSelection.SetActive(false); } var uiZones = GetComponentsInChildren <UIZone>(); for (int i = 0; i < uiZones.Length; ++i) { uiZones[i].enabled = false; } // All of the doors should be opened with free roam. for (int i = 0; i < m_Doors.Count; ++i) { m_Doors[i].CloseOnTriggerExit = false; m_Doors[i].OpenClose(true, true, false); } // The enable objects should be enabled. for (int i = 0; i < m_DemoZones.Length; ++i) { for (int j = 0; j < m_DemoZones[i].EnableObjects.Length; ++j) { m_DemoZones[i].EnableObjects[j].enabled = true; } } // The character needs to be assigned to the camera. var camera = UnityEngineUtility.FindCamera(null); var cameraController = camera.GetComponent <Camera.CameraController>(); cameraController.Character = m_Character; // The character doesn't start out with any items. if (m_FreeRoamItemTypeCounts != null && m_FreeRoamPickupItemTypes) { var inventory = m_Character.GetComponent <InventoryBase>(); if (inventory != null) { for (int i = 0; i < m_FreeRoamItemTypeCounts.Length; ++i) { if (m_FreeRoamItemTypeCounts[i].ItemType == null) { continue; } inventory.PickupItemType(m_FreeRoamItemTypeCounts[i].ItemType, m_FreeRoamItemTypeCounts[i].Count, -1, true, false); } } } EventHandler.ExecuteEvent(m_Character, "OnCharacterSnapAnimator"); enabled = false; return; } // The cursor needs to be visible. Cursor.lockState = CursorLockMode.None; Cursor.visible = true; #if FIRST_PERSON_CONTROLLER && THIRD_PERSON_CONTROLLER // Show the perspective selection menu. if (m_PerspectiveSelection != null) { // The character should be disabled until the perspective is set. m_CharacterLocomotion.SetActive(false, true); m_PerspectiveSelection.SetActive(true); } else { // Determine if the character is a first or third person character. var firstPersonPerspective = m_CharacterLocomotion.MovementTypeFullName.Contains("FirstPerson"); SelectStartingPerspective(firstPersonPerspective); } #elif FIRST_PERSON_CONTROLLER SelectStartingPerspective(true); #else SelectStartingPerspective(false); #endif }
/// <summary> /// Initializes the Demo Manager with the specified character. /// </summary> /// <param name="character">The character that should be initialized/</param> /// <param name="selectStartingPerspective">Should the starting perspective be selected?</param> /// <param name="teleport">Should the character be teleported to the first demo zone?</param> protected void InitializeCharacter(GameObject character, bool selectStartingPerspective, bool teleport) { m_Character = character; if (m_Character == null) { return; } m_CharacterLocomotion = m_Character.GetComponent <UltimateCharacterLocomotion>(); m_CharacterHealth = m_Character.GetComponent <Health>(); m_CharacterRespawner = m_Character.GetComponent <Respawner>(); // Disable the demo components if the character is null. This allows for free roaming within the demo scene. if (m_FreeRoam) { m_FullAccess = true; if (m_PerspectiveSelection != null) { m_PerspectiveSelection.SetActive(false); } var uiZones = GetComponentsInChildren <UIZone>(); for (int i = 0; i < uiZones.Length; ++i) { uiZones[i].enabled = false; } // All of the doors should be opened with free roam. for (int i = 0; i < m_Doors.Count; ++i) { m_Doors[i].CloseOnTriggerExit = false; m_Doors[i].OpenClose(true, true, false); } // The enable objects should be enabled. for (int i = 0; i < m_DemoZones.Length; ++i) { for (int j = 0; j < m_DemoZones[i].EnableObjects.Length; ++j) { m_DemoZones[i].EnableObjects[j].enabled = true; } } // The character needs to be assigned to the camera. var camera = UnityEngineUtility.FindCamera(null); var cameraController = camera.GetComponent <Camera.CameraController>(); cameraController.SetPerspective(m_CharacterLocomotion.FirstPersonPerspective, true); cameraController.Character = m_Character; // The character doesn't start out with any items. if (m_FreeRoamItemTypeCounts != null && m_FreeRoamPickupItemTypes) { var inventory = m_Character.GetComponent <InventoryBase>(); if (inventory != null) { for (int i = 0; i < m_FreeRoamItemTypeCounts.Length; ++i) { if (m_FreeRoamItemTypeCounts[i].ItemType == null) { continue; } inventory.PickupItemType(m_FreeRoamItemTypeCounts[i].ItemType, m_FreeRoamItemTypeCounts[i].Count, -1, true, false); } } } if (m_Character.activeInHierarchy) { EventHandler.ExecuteEvent(m_Character, "OnCharacterSnapAnimator"); } enabled = false; return; } // The cursor needs to be visible. Cursor.lockState = CursorLockMode.None; Cursor.visible = true; if (!selectStartingPerspective) { return; } #if FIRST_PERSON_CONTROLLER && THIRD_PERSON_CONTROLLER // Show the perspective selection menu. if (m_PerspectiveSelection != null) { // The character should be disabled until the perspective is set. m_CharacterLocomotion.SetActive(false, true); m_PerspectiveSelection.SetActive(true); } else { SelectStartingPerspective(m_DefaultFirstPersonStart, teleport); } #elif FIRST_PERSON_CONTROLLER SelectStartingPerspective(true, teleport); #else SelectStartingPerspective(false, teleport); #endif }
private void SetActiveRPC(bool active, bool uiEvent) { m_CharacterLocomotion.SetActive(active, uiEvent); }