浏览代码

Added custom inspector for GameScene ScriptableObjects

It improves workflow and minimizes user error by allowing a designer to pick scenes from a list instead of typing their name manually
/main
Carlos Eduardo Pérez 4 年前
当前提交
3bea7874
共有 6 个文件被更改,包括 99 次插入16 次删除
  1. 8
      UOP1_Project/Assets/Scripts/Editor.meta
  2. 80
      UOP1_Project/Assets/Scripts/Editor/GameSceneEditor.cs
  3. 11
      UOP1_Project/Assets/Scripts/Editor/GameSceneEditor.cs.meta
  4. 8
      UOP1_Project/Assets/Polybrush Data/Brush Settings.meta
  5. 8
      UOP1_Project/Assets/Polybrush Data/Color Palette.meta

8
UOP1_Project/Assets/Scripts/Editor.meta


fileFormatVersion: 2
guid: daf107c3391096e4e832d9da83346d30
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

80
UOP1_Project/Assets/Scripts/Editor/GameSceneEditor.cs


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 string noScenesWarning = "There are no scenes set for this level yet! Add a new scene with the dropdown above";
#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;
}
public override void OnInspectorGUI()
{
PopulateScenePicker();
EditorGUILayout.LabelField("Scene information", new GUIStyle(EditorStyles.largeLabel) {fontStyle = FontStyle.Bold,
fontSize = 18, fixedHeight = 70.0f});
EditorGUILayout.Space();
DrawScenePicker();
DrawPropertiesExcluding(serializedObject, ExcludedProperties);
}
private void DrawScenePicker()
{
var sceneName = gameSceneTarget.sceneName;
EditorGUI.BeginChangeCheck();
var selectedScene = sceneList.ToList().IndexOf(sceneName);
selectedScene = EditorGUILayout.Popup("Scene", selectedScene, sceneList);
if (selectedScene > -1)
{
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(target, "Changed selected scene");
gameSceneTarget.sceneName = sceneList[selectedScene];
MarkAllDirty();
}
}
else
{
EditorGUILayout.HelpBox(noScenesWarning, MessageType.Warning);
}
}
/// <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();
}
}

11
UOP1_Project/Assets/Scripts/Editor/GameSceneEditor.cs.meta


fileFormatVersion: 2
guid: a9133d1c8803ac04e8b40219b69b76b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Polybrush Data/Brush Settings.meta


fileFormatVersion: 2
guid: de5c57e7db463f74a91926f18b81eb2e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Polybrush Data/Color Palette.meta


fileFormatVersion: 2
guid: 613b861868aeee34685034884790feaa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存