Esempio n. 1
0
        /// <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>
        /// Attaches the monitor to the specified character.
        /// </summary>
        /// <param name="character">The character to attach the monitor to.</param>
        protected override void OnAttachCharacter(GameObject character)
        {
            if (m_Character != null)
            {
                EventHandler.UnregisterEvent <float, Vector3, Vector3, GameObject, Collider>(m_Character, "OnHealthDamage", OnDamage);
                EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
                m_CameraTransform = null;
            }

            base.OnAttachCharacter(character);

            if (m_Character == null)
            {
                return;
            }

            // A camera must exist.
            var camera = UnityEngineUtility.FindCamera(m_Character);

            if (camera != null)
            {
                m_CameraTransform = camera.transform;
            }
            if (m_CameraTransform == null)
            {
                Debug.LogError("Error: The Damage Indicator Monitor must have a camera attached to the character.");
                return;
            }

            m_CharacterTransform  = m_Character.transform;
            m_CharacterLocomotion = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            EventHandler.RegisterEvent <float, Vector3, Vector3, GameObject, Collider>(m_Character, "OnHealthDamage", OnDamage);
            EventHandler.RegisterEvent(m_Character, "OnRespawn", OnRespawn);
        }
        /// <summary>
        /// The character has entered from the zone.
        /// </summary>
        /// <param name="characterLocomotion">The character that entered the zone.</param>
        protected override void CharacterEnter(UltimateCharacterLocomotion characterLocomotion)
        {
            // The other collider is the main character.
            m_Character = characterLocomotion.gameObject;
            m_CameraController = UnityEngineUtility.FindCamera(m_Character).GetComponent<CameraController>();

            // The character must have the primary item in order for it to be equipped.
            var inventory = m_Character.GetCachedComponent<InventoryBase>();
            for (int i = 0; i < m_ItemTypes.Length; ++i) {
                if (m_ItemTypes[i] == null) {
                    continue;
                }
                inventory.PickupItemType(m_ItemTypes[i], 1, 0, false, false);
            }

            // Ensure the primary weapon is equipped.
            var equipUnequipAbilities = characterLocomotion.GetAbilities<EquipUnequip>();
            for (int i = 0; i < equipUnequipAbilities.Length; ++i) {
                if (equipUnequipAbilities[i].ItemSetCategoryIndex == m_CategoryIndex) {
                    equipUnequipAbilities[i].StartEquipUnequip(m_ItemSetIndex, true);
                    break;
                }
            }

            // Setup the character for the zone.
            StateManager.SetState(m_Character, "FirstPersonSpringZone", true);
            EventHandler.ExecuteEvent(m_Character, "OnShowUI", false);

            // First person perspective is required...
            m_CameraController.SetPerspective(true);
            // With the combat movement type.
            m_MovementTypeSwitcher.UpdateMovementType(true, (int)MovementTypesZone.MovementType.FirstPersonCombat);
        }
        /// <summary>
        /// Initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            var camera = UnityEngineUtility.FindCamera(m_Character);

            if (camera != null)
            {
                m_CameraGameObject = camera.gameObject;
                if (m_Character == null)
                {
                    m_Character = m_CameraGameObject.GetCachedComponent <Camera.CameraController>().Character;
                }
                EventHandler.RegisterEvent <GameObject>(m_CameraGameObject, "OnCameraAttachCharacter", OnAttachCharacter);
            }

            // Start disabled - attaching the character will enabe the component.
            enabled = false;

            if (m_Character != null)
            {
                var character = m_Character;
                m_Character = null;
                OnAttachCharacter(character);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Attaches the monitor to the specified character.
        /// </summary>
        /// <param name="character">The character to attach the monitor to.</param>
        protected override void OnAttachCharacter(GameObject character)
        {
            if (m_Character != null)
            {
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnAbilityWillEquipItem", OnEquipItem);
                EventHandler.UnregisterEvent <Item, bool>(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem);
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnAbilityUnequipItemComplete", OnUnequipItem);
                EventHandler.UnregisterEvent <Item, int>(m_Character, "OnInventoryRemoveItem", OnUnequipItem);
                EventHandler.UnregisterEvent <bool, bool>(m_Character, "OnAddCrosshairsSpread", OnAddCrosshairsSpread);
                EventHandler.UnregisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
                EventHandler.UnregisterEvent <Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
                EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
                ResetMonitor();
            }

            base.OnAttachCharacter(character);

            if (m_Character == null)
            {
                return;
            }

            m_Camera           = UnityEngineUtility.FindCamera(m_Character);
            m_CameraController = m_Camera.gameObject.GetCachedComponent <CameraController>();
            m_CameraController.SetCrosshairs(transform);

            m_AimAssist             = m_Camera.GetComponent <AimAssist>();
            m_CharacterTransform    = m_Character.transform;
            m_CharacterLayerManager = m_Character.GetCachedComponent <CharacterLayerManager>();
            m_CharacterLocomotion   = m_Character.GetCachedComponent <UltimateCharacterLocomotion>();
            m_EnableImage           = false;
            gameObject.SetActive(CanShowUI());

            EventHandler.RegisterEvent <Item, int>(m_Character, "OnAbilityWillEquipItem", OnEquipItem);
            EventHandler.RegisterEvent <Item, bool>(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem);
            EventHandler.RegisterEvent <Item, int>(m_Character, "OnAbilityUnequipItemComplete", OnUnequipItem);
            EventHandler.RegisterEvent <Item, int>(m_Character, "OnInventoryRemoveItem", OnUnequipItem);
            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAddCrosshairsSpread", OnAddCrosshairsSpread);
            EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim);
            EventHandler.RegisterEvent <Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
            EventHandler.RegisterEvent(m_Character, "OnRespawn", OnRespawn);

            // An item may already be equipped.
            var inventory = m_Character.GetCachedComponent <Inventory.InventoryBase>();

            if (inventory != null)
            {
                for (int i = 0; i < inventory.SlotCount; ++i)
                {
                    var item = inventory.GetActiveItem(i);
                    if (item != null)
                    {
                        OnEquipItem(item, i);
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Assigns the camera to the UI Monitor.
        /// </summary>
        private void AssignCamera()
        {
            var camera = UnityEngineUtility.FindCamera(m_Character);

            if (camera != null)
            {
                m_CameraGameObject = camera.gameObject;
                if (m_Character == null)
                {
                    m_Character = m_CameraGameObject.GetCachedComponent <UltimateCharacterController.Camera.CameraController>().Character;
                }
                EventHandler.RegisterEvent <GameObject>(m_CameraGameObject, "OnCameraAttachCharacter", OnAttachCharacter);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// An object has entered the trigger.
        /// </summary>
        /// <param name="other">The object that entered the trigger.</param>
        private void OnTriggerEnter(Collider other)
        {
            if (!MathUtility.InLayerMask(other.gameObject.layer, 1 << LayerManager.Character))
            {
                return;
            }

            var characterLocomotion = other.GetComponentInParent <UltimateCharacterLocomotion>();

            if (characterLocomotion == null)
            {
                return;
            }

            var cameraController = UnityEngineUtility.FindCamera(characterLocomotion.gameObject).GetComponent <Camera.CameraController>();

            cameraController.SetPerspective(m_FirstPersonPerspective);
        }
Esempio n. 8
0
 /// <summary>
 /// Initialize the default values.
 /// </summary>
 protected virtual void Awake()
 {
     m_GameObject = gameObject;
     if (m_Character == null)
     {
         var camera = UnityEngineUtility.FindCamera(null);
         if (camera != null)
         {
             m_CameraGameObject = camera.gameObject;
             EventHandler.RegisterEvent <GameObject>(m_CameraGameObject, "OnCameraAttachCharacter", OnAttachCharacter);
         }
     }
     else
     {
         var character = m_Character;
         m_Character = null; // Set the character to null so the assignment will occur.
         OnAttachCharacter(character);
     }
 }
Esempio n. 9
0
        /// <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
        }
Esempio n. 10
0
        /// <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
        }
Esempio n. 11
0
        public override string RecordData()
        {
            if (data == null)
            {
                data = new Data();
            }

            // Save position:
            var currentScene = SceneManager.GetActiveScene().buildIndex;
            var found        = false;

            for (int i = 0; i < data.positions.Count; i++)
            {
                if (data.positions[i].scene == currentScene)
                {
                    found = true;
                    data.positions[i].position = transform.position;
                    data.positions[i].rotation = transform.rotation;
                    break;
                }
            }
            if (!found)
            {
                data.positions.Add(new PositionData(currentScene, transform.position, transform.rotation));
            }

            // Save perspective:
            if (savePerspective)
            {
                var camera           = UnityEngineUtility.FindCamera(null);
                var cameraController = camera.GetComponent <Opsive.UltimateCharacterController.Camera.CameraController>();
                if (cameraController != null && cameraController.CanChangePerspectives)
                {
                    data.firstPerson = (cameraController.ActiveViewType.GetType().FullName == cameraController.FirstPersonViewTypeFullName);
                }
            }

            // Save attributes:
            if (saveAttributes)
            {
                data.attributes.Clear();
                var attributeManager = GetComponent <AttributeManager>();
                if (attributeManager == null)
                {
                    if (Debug.isDebugBuild)
                    {
                        Debug.LogWarning("UCC Saver can't save attributes. " + name + " doesn't have an Attribute Manager.", this);
                    }
                }
                else
                {
                    for (int i = 0; i < attributeManager.Attributes.Length; i++)
                    {
                        data.attributes.Add(attributeManager.Attributes[i].Value);
                    }
                }
            }

            // Save inventory:
            if (saveInventory)
            {
                data.items.Clear();
                var inventory = GetComponent <InventoryBase>();
                if (inventory == null)
                {
                    if (Debug.isDebugBuild)
                    {
                        Debug.LogWarning("UCC Saver can't save inventory. " + name + " doesn't have an Inventory component.", this);
                    }
                }
                else
                {
                    // Record equipped items:
                    var equipped = new ItemType[inventory.SlotCount];
                    for (int i = 0; i < inventory.SlotCount; i++)
                    {
                        var equippedItem = inventory.GetItem(i);
                        equipped[i] = (equippedItem != null) ? equippedItem.ItemType : null;
                    }

                    // Save items:
                    var items = inventory.GetAllItems();
                    for (int i = 0; i < items.Count; i++)
                    {
                        var item = items[i];
                        if (item == null || item.ItemType == null)
                        {
                            continue;
                        }
                        var itemCount = inventory.GetItemTypeCount(item.ItemType);
                        if (itemCount <= 0)
                        {
                            continue;
                        }
                        var isDuplicateItem = data.items.Find(x => x.itemID == item.ItemType.ID) != null;
                        var itemData        = new ItemData();
                        itemData.itemID   = item.ItemType.ID;
                        itemData.slot     = item.SlotID;
                        itemData.count    = 1;
                        itemData.equipped = item.ItemType == equipped[item.SlotID];
                        for (int j = 0; j < item.ItemActions.Length; j++)
                        {
                            var usableItem = item.ItemActions[j] as UsableItem;
                            if (usableItem == null)
                            {
                                continue;
                            }
                            var itemActionData = new ItemActionData();
                            itemData.itemActionData.Add(itemActionData);
                            itemActionData.id              = usableItem.ID;
                            itemActionData.count           = isDuplicateItem ? 0 : inventory.GetItemTypeCount(usableItem.GetConsumableItemType());
                            itemActionData.consumableCount = usableItem.GetConsumableItemTypeCount();
                        }
                        data.items.Add(itemData);
                    }
                }
            }

            if (debug)
            {
                Debug.Log(JsonUtility.ToJson(data, true));        // [DEBUG]
            }
            var s = SaveSystem.Serialize(data);

            if (debug)
            {
                Debug.Log("UCC Saver on " + name + " saving: " + s, this);
            }
            return(s);
        }
Esempio n. 12
0
        public override void ApplyData(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return;
            }
            var newData = SaveSystem.Deserialize <Data>(s);

            if (newData == null)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("UCC Saver on " + name + " received invalid data. Can't apply: " + s, this);
                }
                return;
            }
            data = newData;
            var character = GetComponent <UltimateCharacterLocomotion>();

            // Restore attributes:
            if (saveAttributes)
            {
                var attributeManager = GetComponent <AttributeManager>();
                if (attributeManager == null)
                {
                    if (Debug.isDebugBuild)
                    {
                        Debug.LogWarning("UCC Saver can't load attributes. " + name + " doesn't have an Attribute Manager.", this);
                    }
                }
                else
                {
                    if (debug)
                    {
                        Debug.Log("UCC Saver on " + name + " restoring attributes", this);
                    }
                    var count = Mathf.Min(attributeManager.Attributes.Length, data.attributes.Count);
                    for (int i = 0; i < count; i++)
                    {
                        attributeManager.Attributes[i].Value = data.attributes[i];
                    }
                }
            }

            // Restore inventory:
            if (saveInventory)
            {
                var inventory = GetComponent <InventoryBase>();
                if (inventory == null)
                {
                    if (Debug.isDebugBuild)
                    {
                        Debug.LogWarning("UCC Saver can't load inventory. " + name + " doesn't have an Inventory component.", this);
                    }
                }
                else
                {
                    // Clear inventory:
                    var items = inventory.GetAllItems();
                    for (int i = 0; i < items.Count; i++)
                    {
                        var item = items[i];
                        if (item != null && item.ItemType != null)
                        {
                            for (int j = 0; j < item.ItemActions.Length; j++)
                            {
                                var usableItem = item.ItemActions[j] as UsableItem;
                                if (usableItem != null)
                                {
                                    var consumableItemType = usableItem.GetConsumableItemType();
                                    if (consumableItemType != null)
                                    {
                                        var count = (int)inventory.GetItemTypeCount(consumableItemType);
                                        if (count > 0)
                                        {
                                            inventory.RemoveItem(consumableItemType, count, false);
                                        }
                                    }
                                }
                            }
                            inventory.RemoveItem(item.ItemType, item.SlotID, false);
                        }
                    }

                    var itemCollection = UCCUtility.FindItemCollection(character.gameObject);
                    if (itemCollection == null)
                    {
                        Debug.LogError("Error: Unable to find ItemCollection.");
                        return;
                    }

                    // Add saved items: (restore equipped items last so they end up equipped)
                    HashSet <ItemType> alreadyAddedItemTypes = new HashSet <ItemType>();
                    RestoreItems(false, itemCollection, inventory, alreadyAddedItemTypes);
                    RestoreItems(true, itemCollection, inventory, alreadyAddedItemTypes);
                }
            }

            // Restore position:
            if (savePosition)
            {
                if (CompareTag("Player") && SaveSystem.playerSpawnpoint != null)
                {
                    if (debug)
                    {
                        Debug.Log("UCC Saver on " + name + " moving character to spawnpoint " + SaveSystem.playerSpawnpoint, this);
                    }
                    character.SetPositionAndRotation(SaveSystem.playerSpawnpoint.transform.position, SaveSystem.playerSpawnpoint.transform.rotation);
                }
                else
                {
                    var currentScene = SceneManager.GetActiveScene().buildIndex;
                    for (int i = 0; i < data.positions.Count; i++)
                    {
                        if (data.positions[i].scene == currentScene)
                        {
                            if (debug)
                            {
                                Debug.Log("UCC Saver on " + name + " (tag=" + tag + ") restoring saved position " + data.positions[i].position, this);
                            }
                            character.SetPositionAndRotation(data.positions[i].position, data.positions[i].rotation);
                            break;
                        }
                    }
                }
            }

            // Restore perspective:
            if (savePerspective)
            {
                var camera           = UnityEngineUtility.FindCamera(null);
                var cameraController = camera.GetComponent <Opsive.UltimateCharacterController.Camera.CameraController>();
                if (cameraController != null && cameraController.CanChangePerspectives)
                {
                    cameraController.SetPerspective(data.firstPerson, true);
                }
            }

            // Hide cursor: (In editor, UnityInput makes cursor visible when paused during scene transition.)
            var unityInput = GetComponent <UnityInput>();

            if (unityInput != null)
            {
                unityInput.DisableCursor = true;
            }
        }