浏览代码
Merge pull request #31 from CharlExMachina/Scene-Loading
Merge pull request #31 from CharlExMachina/Scene-Loading
Added custom inspector for GameScene ScriptableObjects/main
GitHub
4 年前
当前提交
2c21f5a9
共有 4 个文件被更改,包括 113 次插入 和 0 次删除
-
8UOP1_Project/Assets/Scripts/Editor.meta
-
11UOP1_Project/Assets/Scripts/Editor/GameSceneEditor.cs.meta
-
94UOP1_Project/Assets/Scripts/Editor/GameSceneEditor.cs
|
|||
fileFormatVersion: 2 |
|||
guid: daf107c3391096e4e832d9da83346d30 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a9133d1c8803ac04e8b40219b69b76b0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.IO; |
|||
using System.Linq; |
|||
using UnityEditor; |
|||
using UnityEditor.SceneManagement; |
|||
using UnityEngine; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
[CustomEditor(typeof(GameScene), true)] |
|||
public class GameSceneEditor : Editor |
|||
{ |
|||
#region UI_Warnings
|
|||
|
|||
private const string noScenesWarning = "There are no scenes set for this level yet! Add a new scene with the dropdown below"; |
|||
|
|||
#endregion
|
|||
|
|||
#region GUI_Styles
|
|||
|
|||
private GUIStyle headerLabelStyle; |
|||
|
|||
#endregion
|
|||
|
|||
// it holds a list of properties to hide from basic inspector
|
|||
private static readonly string[] ExcludedProperties = {"m_Script", "sceneName"}; |
|||
|
|||
private string[] sceneList; |
|||
private GameScene gameSceneTarget; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
gameSceneTarget = target as GameScene; |
|||
PopulateScenePicker(); |
|||
InitializeGuiStyles(); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
EditorGUILayout.LabelField("Scene information", headerLabelStyle); |
|||
EditorGUILayout.Space(); |
|||
DrawScenePicker(); |
|||
DrawPropertiesExcluding(serializedObject, ExcludedProperties); |
|||
} |
|||
|
|||
private void DrawScenePicker() |
|||
{ |
|||
var sceneName = gameSceneTarget.sceneName; |
|||
EditorGUI.BeginChangeCheck(); |
|||
var selectedScene = sceneList.ToList().IndexOf(sceneName); |
|||
|
|||
if (selectedScene < 0) |
|||
{ |
|||
EditorGUILayout.HelpBox(noScenesWarning, MessageType.Warning); |
|||
} |
|||
|
|||
selectedScene = EditorGUILayout.Popup("Scene", selectedScene, sceneList); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
Undo.RecordObject(target, "Changed selected scene"); |
|||
gameSceneTarget.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