HarshNarayanJha
4 年前
当前提交
4e2ef8cc
共有 12 个文件被更改,包括 76 次插入 和 118 次删除
-
4UOP1_Project/Assets/ScriptableObjects/SceneData/Initialization.asset
-
3UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Beach.asset
-
3UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Forest.asset
-
3UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/TestingGround.asset
-
6UOP1_Project/Assets/ScriptableObjects/SceneData/Menus/MainMenu.asset
-
4UOP1_Project/Assets/Scripts/SceneManagement/EditorInitialisationLoader.cs
-
23UOP1_Project/Assets/Scripts/SceneManagement/LocationLoader.cs
-
9UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSO.cs
-
2UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSOEditor.cs.meta
-
44UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSOEditor.cs
-
93UOP1_Project/Assets/Scripts/Editor/GameSceneSOEditor.cs
-
0/UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/GameSceneSOEditor.cs.meta
|
|||
#if UNITY_EDITOR
|
|||
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 |
|||
{ |
|||
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(); |
|||
} |
|||
|
|||
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
|
|
|||
using System.IO; |
|||
using System.Linq; |
|||
using UnityEditor; |
|||
using UnityEditor.SceneManagement; |
|||
using UnityEngine; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
[CustomEditor(typeof(GameSceneSO), true)] |
|||
public class GameSceneSOEditor : Editor |
|||
{ |
|||
private const string NO_SCENES_WARNING = "There is no Scene associated to this location yet. Add a new scene with the dropdown below"; |
|||
private GUIStyle _headerLabelStyle; |
|||
private static readonly string[] _excludedProperties = { "m_Script", "sceneName" }; //m_script is a reference to the script being edited but it'll result an editable object field.
|
|||
|
|||
private string[] _sceneList; |
|||
private GameSceneSO _gameSceneInspected; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
_gameSceneInspected = target as GameSceneSO; |
|||
PopulateScenePicker(); |
|||
InitializeGuiStyles(); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
//Make GUI not editable.
|
|||
GUI.enabled = false; |
|||
//Draw reference information about script being edited.
|
|||
EditorGUILayout.ObjectField("Script", MonoScript.FromScriptableObject((GameSceneSO)target), typeof(GameSceneSO), false); |
|||
//Make GUI editable.
|
|||
GUI.enabled = true; |
|||
|
|||
serializedObject.Update(); |
|||
EditorGUILayout.LabelField("Scene information", _headerLabelStyle); |
|||
EditorGUILayout.Space(); |
|||
DrawScenePicker(); |
|||
DrawPropertiesExcluding(serializedObject, _excludedProperties); |
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
private void DrawScenePicker() |
|||
{ |
|||
var sceneName = _gameSceneInspected.sceneName; |
|||
EditorGUI.BeginChangeCheck(); |
|||
var selectedScene = _sceneList.ToList().IndexOf(sceneName); |
|||
|
|||
if (selectedScene < 0) |
|||
{ |
|||
EditorGUILayout.HelpBox(NO_SCENES_WARNING, MessageType.Warning); |
|||
} |
|||
|
|||
selectedScene = EditorGUILayout.Popup("Scene", selectedScene, _sceneList); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
Undo.RecordObject(target, "Changed selected scene"); |
|||
_gameSceneInspected.sceneName = _sceneList[selectedScene]; |
|||
MarkAllDirty(); |
|||
} |
|||
} |
|||
|
|||
private void InitializeGuiStyles() |
|||
{ |
|||
_headerLabelStyle = new GUIStyle(EditorStyles.largeLabel) |
|||
{ |
|||
fontStyle = FontStyle.Bold, |
|||
fontSize = 18, |
|||
fixedHeight = 70.0f |
|||
}; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Populates the Scene picker with Scenes included in the game's build index
|
|||
/// </summary>
|
|||
private void PopulateScenePicker() |
|||
{ |
|||
var sceneCount = SceneManager.sceneCountInBuildSettings; |
|||
_sceneList = new string[sceneCount]; |
|||
for (int i = 0; i < sceneCount; i++) |
|||
{ |
|||
_sceneList[i] = Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i)); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Marks scenes as dirty so data can be saved
|
|||
/// </summary>
|
|||
private void MarkAllDirty() |
|||
{ |
|||
EditorUtility.SetDirty(target); |
|||
EditorSceneManager.MarkAllScenesDirty(); |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue