浏览代码

Loading tool refactor

Scenes load in groups in the editor. It's now possible to start from an arbitrary scene but not move between scenes afterwards
/UI
Ciro Continisio 3 年前
当前提交
8fec9425
共有 12 个文件被更改,包括 85 次插入60 次删除
  1. 2
      UOP1_Project/Assets/ScriptableObjects/SceneData/Gameplay.asset
  2. 2
      UOP1_Project/Assets/ScriptableObjects/SceneData/Initialization.asset
  3. 2
      UOP1_Project/Assets/ScriptableObjects/SceneData/Menus/MainMenu.asset
  4. 2
      UOP1_Project/Assets/ScriptableObjects/SceneData/PersistentManagers.asset
  5. 2
      UOP1_Project/Assets/ScriptableObjects/SceneData/WIP/ArtShowcase.asset
  6. 2
      UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.Data.cs
  7. 9
      UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.Helper.cs
  8. 2
      UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.PreferencesWindow.cs
  9. 67
      UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.cs
  10. 31
      UOP1_Project/Assets/Scripts/SceneManagement/EditorInitialisationLoader.cs
  11. 2
      UOP1_Project/Assets/Scripts/SceneManagement/SceneReadyBroadcaster.cs
  12. 22
      UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSO.cs

2
UOP1_Project/Assets/ScriptableObjects/SceneData/Gameplay.asset


m_Name: Gameplay
m_EditorClassIdentifier:
description: Gameplay elements including UI and inventory manager
sceneType: 4
shortDescription:

2
UOP1_Project/Assets/ScriptableObjects/SceneData/Initialization.asset


m_EditorClassIdentifier:
description: The scene from where the game starts and it is responsible for loading
PersistentManagers scene and raises the event to load the main menu.
sceneType: 2
shortDescription:

2
UOP1_Project/Assets/ScriptableObjects/SceneData/Menus/MainMenu.asset


m_Name: MainMenu
m_EditorClassIdentifier:
description: Main/title menu, the only menu that exists as a standalone scene
sceneType: 1
shortDescription:

2
UOP1_Project/Assets/ScriptableObjects/SceneData/PersistentManagers.asset


m_EditorClassIdentifier:
description: The scene that contains all the persistent managers in the game like
scene loader and Audio manager etc...
sceneType: 3
shortDescription:

2
UOP1_Project/Assets/ScriptableObjects/SceneData/WIP/ArtShowcase.asset


m_Name: ArtShowcase
m_EditorClassIdentifier:
description: Just a demo scene to see art assets, not used in the game
sceneType: 5
shortDescription:

2
UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.Data.cs


public Color color = Color.clear;
[NonSerialized]
public GameSceneSO gameScene;
public GameSceneSO gameSceneSO;
}
private class Styles

9
UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.Helper.cs


private static readonly Dictionary<Type, Color> kDefaultMarkerColors = new Dictionary<Type, Color>()
{
{ typeof(PersistentManagersSO), Color.magenta },
{ typeof(GameplaySO), Color.magenta },
{ typeof(LocationSO), Color.green },
{ typeof(MenuSO), Color.cyan },
};

GUIUtility.RotateAroundPivot(-45.0f, rect.center);
return isClicked;
}
public static void OpenSceneSafe(string path)
{
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
EditorSceneManager.OpenScene(path);
}
}
public static Color GetDefaultColor(GameSceneSO gameScene)

2
UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.PreferencesWindow.cs


private void DrawItem(Rect rect, int index, bool isActive, bool isFocused)
{
var item = items[index];
var gameScene = item.gameScene;
var gameScene = item.gameSceneSO;
if (gameScene != null)
{
var colorMarkerRect = rect;

67
UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.cs


using UnityEditor;
using UnityEngine;
using SceneSelectorInternal;
using UnityEditor.SceneManagement;
using SceneType = GameSceneSO.GameSceneType;
public partial class SceneSelector : EditorWindow, IHasCustomMenu
{

private List<Item> items => _storage.items;
private Dictionary<string, Item> itemsMap => _storage.itemsMap;
private GameSceneSO persistentManagerSceneSO, gameplaySceneSO;
[MenuItem("ChopChop/Scene Selector")]
private static void Open()

private void DrawWindow()
{
if(GUILayout.Button("Refresh scenes"))
{
//Forcing deletion of the storage, which will search the project and populate the scene list again
_storage = new Storage();
EditorPrefs.SetString(kPreferencesKey, "");
OnEnable();
}
using (var scrollScope = new EditorGUILayout.ScrollViewScope(_windowScrollPosition))
{
GUILayout.Space(4.0f);

{
if (item.isVisible)
{
var gameScene = item.gameScene;
if (gameScene != null)
var gameSceneSO = item.gameSceneSO;
if (gameSceneSO != null)
if (GUILayout.Button(gameScene.name, _styles.item))
if (GUILayout.Button(gameSceneSO.name, _styles.item))
Helper.OpenSceneSafe(AssetDatabase.GetAssetPath(gameScene.sceneReference.editorAsset));
OpenSceneSafe(gameSceneSO);
}
var colorMarkerRect = GUILayoutUtility.GetLastRect();

private void PopulateItems()
{
var gameScenes = new List<GameSceneSO>();
Helper.FindAssetsByType(gameScenes);
var gameSceneSOs = new List<GameSceneSO>();
Helper.FindAssetsByType(gameSceneSOs);
foreach (var gameScene in gameScenes)
foreach (var gameSceneSO in gameSceneSOs)
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(gameScene, out var guid, out long _))
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(gameSceneSO, out var guid, out long _))
item.gameScene = gameScene;
item.gameSceneSO = gameSceneSO;
gameScene = gameScene,
gameSceneSO = gameSceneSO,
color = Helper.GetDefaultColor(gameScene)
color = Helper.GetDefaultColor(gameSceneSO)
switch (item.gameSceneSO.sceneType)
{
case SceneType.PersistentManagers:
persistentManagerSceneSO = item.gameSceneSO;
break;
case SceneType.Gameplay:
gameplaySceneSO = item.gameSceneSO;
break;
}
items.Add(item);
itemsMap.Add(guid, item);
}

for (int i = items.Count - 1; i >= 0; --i)
{
var sceneItem = items[i];
if (sceneItem == null || sceneItem.gameScene == null)
if (sceneItem == null || sceneItem.gameSceneSO == null)
{
items.RemoveAt(i);
itemsMap.Remove(sceneItem.guid);

void IHasCustomMenu.AddItemsToMenu(GenericMenu menu)
{
menu.AddItem(kOpenPreferencesItemContent, false, OpenPreferences);
}
private void OpenSceneSafe(GameSceneSO gameSceneSO)
{
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(gameSceneSO.sceneReference.editorAsset));
//Check if it's a Location or Menu scene, load additional managers
if (gameSceneSO.sceneType == SceneType.Location)
{
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(persistentManagerSceneSO.sceneReference.editorAsset), OpenSceneMode.Additive);
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(gameplaySceneSO.sceneReference.editorAsset), OpenSceneMode.Additive);
}
else if (gameSceneSO.sceneType == SceneType.Menu)
{
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(persistentManagerSceneSO.sceneReference.editorAsset), OpenSceneMode.Additive);
}
}
}
}

31
UOP1_Project/Assets/Scripts/SceneManagement/EditorInitialisationLoader.cs


public class EditorInitialisationLoader : MonoBehaviour
{
#if UNITY_EDITOR
public GameSceneSO[] scenesToLoad;
[HideInInspector] public bool _isEditorInitializerMode = false;
/*
private void Start()
{
Application.targetFrameRate = targetFramerate; // For debugging purposes
for (int i = 0; i < SceneManager.sceneCount; ++i)
{
Scene scene = SceneManager.GetSceneAt(i);
for (int j = 0; j < scenesToLoad.Length; ++j)
if (scene.path == scenesToLoad[j].scenePath)
{
return;
}
else
{
//TODO: Make it work again
//SceneManager.LoadSceneAsync(scenesToLoad[j].scenePath, LoadSceneMode.Additive);
//Inform that we are pressing play from a location or menu
_isEditorInitializerMode = true;
}
}
}
*/
[HideInInspector] public bool _shootEvent = true;
#endif
}

2
UOP1_Project/Assets/Scripts/SceneManagement/SceneReadyBroadcaster.cs


private void Start()
{
if(GetComponent<EditorInitialisationLoader>()._isEditorInitializerMode == true)
if(GetComponent<EditorInitialisationLoader>()._shootEvent == true)
{
_OnSceneReady.RaiseEvent();
}

22
UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSO.cs


using UnityEngine.AddressableAssets;
/// <summary>
/// This class is a base class which contains what is common to all game scenes (Locations or Menus)
/// This class is a base class which contains what is common to all game scenes (Locations, Menus, Managers)
public GameSceneType sceneType;
/// <summary>
/// Used by the SceneSelector tool to discern what type of scene it needs to load
/// </summary>
public enum GameSceneType
{
//Playable scenes
Location, //SceneSelector tool will also load PersistentManagers and Gameplay
Menu, //SceneSelector tool will also load Gameplay
//Special scenes
Initialisation,
PersistentManagers,
Gameplay,
//Work in progress scenes that don't need to be played
Art,
}
}
正在加载...
取消
保存