浏览代码

Simplified GameSceneSO and SceneSelector

/UI
Ciro Continisio 4 年前
当前提交
48f41150
共有 5 个文件被更改,包括 4 次插入81 次删除
  1. 10
      UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.Helper.cs
  2. 8
      UOP1_Project/Assets/Scripts/Editor/SceneSelector/SceneSelector.cs
  3. 8
      UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSO.cs
  4. 48
      UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSOEditor.cs
  5. 11
      UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSOEditor.cs.meta

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


return Color.red;
}
public static void RunOnNextUpdate(Action action)
{
void Run()
{
action?.Invoke();
EditorApplication.update -= Run;
}
EditorApplication.update += Run;
}
public static int FindAssetsByType<T>(List<T> assets) where T : UnityEngine.Object
{
int foundAssetsCount = 0;

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


wantsMouseMove = true;
LoadStorage();
PopulateItems();
GameSceneSO.onEnabled += OnGameSceneSOCreated;
}
private void OnDisable()

SaveStorage();
GameSceneSO.onEnabled -= OnGameSceneSOCreated;
}
private void OnGUI()

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

_hasEmptyItems = false;
}
private void OnGameSceneSOCreated(GameSceneSO _)
{
Helper.RunOnNextUpdate(PopulateItems);
}
private void EnsureStyles()
{

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


/// This class is a base class which contains what is common to all game scenes (Locations or Menus)
/// </summary>
public abstract partial class GameSceneSO : ScriptableObject
public class GameSceneSO : ScriptableObject
#if UNITY_EDITOR // See GameSceneSOEditor.cs
public UnityEditor.SceneAsset sceneAsset; //Just used in editor in the SceneLoading tool for the purpose of quickly opening scenes
#endif
[HideInInspector] public string scenePath;
public string scenePath;
[TextArea] public string shortDescription;

48
UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSOEditor.cs


#if UNITY_EDITOR
using System;
using UnityEngine;
using UnityEditor;
// This is second part of implementation of GameSceneSO
// This part is reponsible for the editor-related functionality
public abstract partial class GameSceneSO : ScriptableObject, ISerializationCallbackReceiver
{
public static Action<GameSceneSO> onEnabled;
private SceneAsset prevSceneAsset;
void ISerializationCallbackReceiver.OnBeforeSerialize()
{
PopulateScenePath();
}
void ISerializationCallbackReceiver.OnAfterDeserialize()
{ }
private void OnEnable()
{
// In case domain was not reloaded after entering play mode
prevSceneAsset = null;
PopulateScenePath();
onEnabled?.Invoke(this);
}
private void PopulateScenePath()
{
if (sceneAsset != null)
{
// To prevent constant invocation of AssetDatabase API
// when this SO is opened in the Inspector.
if (prevSceneAsset != sceneAsset)
{
prevSceneAsset = sceneAsset;
scenePath = AssetDatabase.GetAssetPath(sceneAsset);
}
}
else
{
scenePath = string.Empty;
}
}
}
#endif

11
UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSOEditor.cs.meta


fileFormatVersion: 2
guid: 1c16d46359a2ac443892febbf5d270cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存