/// <summary> /// Add the current opened level to the end of data /// </summary> private void AddCurrentLevel() { var loadedScenePath = LevelSceneManagement.GetLoadedLevelScenePath(); if (string.IsNullOrEmpty(loadedScenePath)) { return; } var guid = AssetDatabase.AssetPathToGUID(loadedScenePath); var settings = AddressableAssetSettingsDefaultObject.Settings; var assetReference = settings.CreateAssetReference(guid); var playerTransform = LevelSceneManagement.GetPlayerTransform(); var respawnPosition = playerTransform == null ? Vector3.zero : playerTransform.position; // Unselect the item to make it added at the end of data _listView.selectedIndex = -1; AddLevelItem(); var levelID = _listView.selectedIndex; serializedObject.Update(); _levelData.ModifyLevelScene(levelID, assetReference); _levelData.ModifyPlayerSpawnPoint(levelID, respawnPosition); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Update the player spawn point to the opened level /// </summary> private void UpdatePlayerSpawnPoint() { var levelID = LevelSceneManagement.GetLoadedLevelID(_levelData); if (levelID == -1) { return; } var playerTransform = LevelSceneManagement.GetPlayerTransform(); var respawnPosition = playerTransform == null ? Vector3.zero : playerTransform.position; _levelData.ModifyPlayerSpawnPoint(levelID, respawnPosition); serializedObject.ApplyModifiedProperties(); SelectLevelItem(levelID); }