Thomas ICHÉ
6 年前
当前提交
f82f4663
共有 14 个文件被更改,包括 475 次插入 和 0 次删除
-
8Editor/EditorSceneSetup.meta
-
8Editor/HierarchyHints.meta
-
8Editor/SelectionHistory.meta
-
29Editor/EditorSceneSetup/EditorSceneSetup.cs
-
11Editor/EditorSceneSetup/EditorSceneSetup.cs.meta
-
84Editor/EditorSceneSetup/EditorSceneSetupEditor.cs
-
11Editor/EditorSceneSetup/EditorSceneSetupEditor.cs.meta
-
70Editor/HierarchyHints/HierarchyHints.cs
-
11Editor/HierarchyHints/HierarchyHints.cs.meta
-
224Editor/SelectionHistory/SelectionHistoryWindow.cs
-
11Editor/SelectionHistory/SelectionHistoryWindow.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: da253dff53554a5498211c4caae380cc |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: d5dcb83e338ada74c9a36ec453e5fa26 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 74683706205d7294c8af1bd860925e81 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.SceneManagement; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
public class EditorSceneSetup : ScriptableObject |
|||
{ |
|||
[MenuItem("Assets/Create/Editor Scene Setup", priority = 200)] |
|||
public static void CreateAsset() |
|||
{ |
|||
AssetDatabase.CreateAsset(CreateInstance<EditorSceneSetup>(), "Assets/New Editor Scene Setup.asset"); |
|||
} |
|||
|
|||
public int ActiveScene; |
|||
public EditorScene[] LoadedScenes; |
|||
|
|||
[System.Serializable] |
|||
public struct EditorScene |
|||
{ |
|||
public SceneAsset Scene; |
|||
public bool Loaded; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 8bf8857f1af056d4894bee553e091ceb |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditorInternal; |
|||
using System; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
[CustomEditor(typeof(EditorSceneSetup))] |
|||
public class EditorSceneSetupEditor : UnityEditor.Editor |
|||
{ |
|||
ReorderableList m_List; |
|||
|
|||
SerializedProperty m_LoadedScenes; |
|||
SerializedProperty m_ActiveScene; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
m_ActiveScene = serializedObject.FindProperty("ActiveScene"); |
|||
m_LoadedScenes = serializedObject.FindProperty("LoadedScenes"); |
|||
|
|||
m_List = new ReorderableList(serializedObject, m_LoadedScenes, true, true, true, true); |
|||
m_List.drawElementCallback = OnDrawElement; |
|||
m_List.drawHeaderCallback = OnDrawHeader; |
|||
|
|||
} |
|||
|
|||
private void OnDrawHeader(Rect rect) |
|||
{ |
|||
GUI.Label(rect, "Scene List"); |
|||
} |
|||
|
|||
private void OnDrawElement(Rect rect, int index, bool isActive, bool isFocused) |
|||
{ |
|||
var toggleRect = rect; |
|||
toggleRect.width = 16; |
|||
toggleRect.yMin += 2; |
|||
|
|||
var sceneRect = rect; |
|||
sceneRect.xMin += 24; |
|||
sceneRect.xMax -= 80; |
|||
sceneRect.yMin += 2; |
|||
sceneRect.height = 16; |
|||
|
|||
var loadedRect = rect; |
|||
loadedRect.xMin = rect.xMax - 80; |
|||
loadedRect.yMin += 2; |
|||
|
|||
bool active = m_ActiveScene.intValue == index; |
|||
bool newActive = GUI.Toggle(toggleRect, active, GUIContent.none); |
|||
if(GUI.changed && newActive != active) |
|||
{ |
|||
m_ActiveScene.intValue = index; |
|||
} |
|||
|
|||
var sceneAsset = (SceneAsset)EditorGUI.ObjectField(sceneRect, m_LoadedScenes.GetArrayElementAtIndex(index).FindPropertyRelative("Scene").objectReferenceValue, typeof(SceneAsset), false); |
|||
if (GUI.changed) |
|||
{ |
|||
m_LoadedScenes.GetArrayElementAtIndex(index).FindPropertyRelative("Scene").objectReferenceValue = sceneAsset; |
|||
} |
|||
|
|||
int visible = m_LoadedScenes.GetArrayElementAtIndex(index).FindPropertyRelative("Loaded").boolValue ? 1 : 0; |
|||
visible = EditorGUI.IntPopup(loadedRect, visible, kLoadedItems, kLoadedIndices); |
|||
|
|||
if(GUI.changed) |
|||
{ |
|||
m_LoadedScenes.GetArrayElementAtIndex(index).FindPropertyRelative("Loaded").boolValue = visible == 1 ? true : false; |
|||
} |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
static readonly int[] kLoadedIndices = new int[2] { 0, 1 }; |
|||
static readonly GUIContent[] kLoadedItems = new GUIContent[2] { new GUIContent("Not Loaded"), new GUIContent("Loaded") }; |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
m_List.DoLayoutList(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: a0875758aceaa3a4b96c65bf4fb85f50 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.VFX; |
|||
using UnityEditor; |
|||
using GameplayIngredients; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
|
|||
[InitializeOnLoad] |
|||
public static class HierarchyHints |
|||
{ |
|||
static HierarchyHints() |
|||
{ |
|||
EditorApplication.hierarchyWindowItemOnGUI -= HierarchyOnGUI; |
|||
EditorApplication.hierarchyWindowItemOnGUI += HierarchyOnGUI; |
|||
} |
|||
|
|||
static void HierarchyOnGUI(int instanceID, Rect selectionRect) |
|||
{ |
|||
GameObject o = EditorUtility.InstanceIDToObject(instanceID) as GameObject; |
|||
if (o == null) return; |
|||
|
|||
var c = GUI.color; |
|||
if (o.isStatic) selectionRect = DrawLabel(selectionRect, "#", Color.gray); |
|||
if (o.GetComponents<MonoBehaviour>().Length > 0) selectionRect = DrawLabel(selectionRect, "*", Colors.green); |
|||
if (o.GetComponents<Camera>().Length > 0) selectionRect = DrawLabel(selectionRect, "C", Colors.blue); |
|||
if (o.GetComponents<Light>().Length > 0) selectionRect = DrawLabel(selectionRect, "L", Colors.yellow); |
|||
if (o.GetComponents<MeshRenderer>().Length > 0) selectionRect = DrawLabel(selectionRect, "M", Colors.purple); |
|||
if (o.GetComponents<AudioSource>().Length > 0) selectionRect = DrawLabel(selectionRect, "S", Colors.orange); |
|||
if (o.GetComponents<VisualEffect>().Length > 0) selectionRect = DrawLabel(selectionRect, "fx", Colors.red, 16); |
|||
GUI.color = c; |
|||
} |
|||
|
|||
static Rect DrawLabel(Rect rect, string label, Color color, int size = 12) |
|||
{ |
|||
GUI.color = color; |
|||
GUI.Label(rect, label, Styles.rightLabel); |
|||
rect.width = rect.width - size; |
|||
return rect; |
|||
} |
|||
|
|||
static class Colors |
|||
{ |
|||
public static Color orange = new Color(1.0f, 0.7f, 0.1f); |
|||
public static Color red = new Color(1.0f, 0.4f, 0.3f); |
|||
public static Color yellow = new Color(0.8f, 1.0f, 0.1f); |
|||
public static Color green = new Color(0.2f, 1.0f, 0.1f); |
|||
public static Color blue = new Color(0.5f, 0.8f, 1.0f); |
|||
public static Color violet = new Color(0.8f, 0.5f, 1.0f); |
|||
public static Color purple = new Color(1.0f, 0.5f, 0.8f); |
|||
} |
|||
|
|||
static class Styles |
|||
{ |
|||
public static GUIStyle rightLabel; |
|||
static Styles() |
|||
{ |
|||
rightLabel = new GUIStyle(EditorStyles.label); |
|||
rightLabel.alignment = TextAnchor.MiddleRight; |
|||
rightLabel.normal.textColor = Color.white; |
|||
rightLabel.onNormal.textColor = Color.white; |
|||
|
|||
rightLabel.active.textColor = Color.white; |
|||
rightLabel.onActive.textColor = Color.white; |
|||
|
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a6ca563f0dba0814c804f2cdbef717d9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
public class SelectionHistoryWindow : EditorWindow |
|||
{ |
|||
[MenuItem("Window/Selection History")] |
|||
public static void OpenSelectionHistoryWindow() |
|||
{ |
|||
EditorWindow.GetWindow<SelectionHistoryWindow>(); |
|||
} |
|||
|
|||
Vector2 scrollPos = Vector2.zero; |
|||
|
|||
void OnGUI() |
|||
{ |
|||
titleContent = Contents.title; |
|||
|
|||
scrollPos = EditorGUILayout.BeginScrollView(scrollPos); |
|||
{ |
|||
Selection_OnGUI(); |
|||
} |
|||
EditorGUILayout.EndScrollView(); |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
lockedObjects = null; |
|||
selectionHistory = null; |
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
lockedObjects = null; |
|||
selectionHistory = null; |
|||
} |
|||
|
|||
List<GameObject[]> selectionHistory; |
|||
List<GameObject[]> lockedObjects; |
|||
|
|||
int maxHistoryCount = 32; |
|||
bool ignoreNextSelection = false; |
|||
|
|||
|
|||
|
|||
void OnSelectionChange() |
|||
{ |
|||
if (ignoreNextSelection) |
|||
{ |
|||
ignoreNextSelection = false; |
|||
return; |
|||
} |
|||
|
|||
if (selectionHistory == null) selectionHistory = new List<GameObject[]>(); |
|||
if (lockedObjects == null) lockedObjects = new List<GameObject[]>(); |
|||
|
|||
if (Selection.activeGameObject != null || Selection.gameObjects.Length > 0) |
|||
{ |
|||
if (selectionHistory.Count > maxHistoryCount) |
|||
selectionHistory.RemoveAt(0); |
|||
|
|||
if (selectionHistory.Count == 0 || CompareArray(selectionHistory[selectionHistory.Count - 1], Selection.gameObjects)) ; |
|||
selectionHistory.Add(Selection.gameObjects); |
|||
Repaint(); |
|||
} |
|||
|
|||
} |
|||
|
|||
public bool CompareArray(GameObject[] a, GameObject[] b) |
|||
{ |
|||
return a.SequenceEqual(b); |
|||
} |
|||
|
|||
private static bool CheckObjects(GameObject[] objs) |
|||
{ |
|||
if (objs == null) return false; |
|||
|
|||
foreach (var obj in objs) |
|||
{ |
|||
if (obj == null) return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
void Selection_OnGUI() |
|||
{ |
|||
if (selectionHistory == null) selectionHistory = new List<GameObject[]>(); |
|||
if (lockedObjects == null) lockedObjects = new List<GameObject[]>(); |
|||
int i = 0; |
|||
|
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
if (GUILayout.Button("Unselect All")) |
|||
{ |
|||
Selection.activeObject = null; |
|||
ignoreNextSelection = true; |
|||
Repaint(); |
|||
} |
|||
} |
|||
int toRemove = -1; |
|||
|
|||
if (lockedObjects.Count > 0) |
|||
{ |
|||
GUILayout.Label("Retained", EditorStyles.boldLabel); |
|||
i = 0; |
|||
toRemove = -1; |
|||
foreach (var obj in lockedObjects) |
|||
{ |
|||
if (obj == null || obj.Length == 0 || !CheckObjects(obj)) |
|||
{ |
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.Label("(object is either null or has been deleted)"); |
|||
if (GUILayout.Button("X", GUILayout.Width(24))) |
|||
{ |
|||
toRemove = i; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.Label(Contents.star, GUILayout.Width(24)); |
|||
string label = obj.Length > 1 ? "Multiple (" + obj.Length + ") : " + obj[0].name + " ..." : obj[0].name; |
|||
if (GUILayout.Button(label)) |
|||
{ |
|||
ignoreNextSelection = true; |
|||
Selection.objects = obj; |
|||
} |
|||
if (GUILayout.Button("F", GUILayout.Width(24))) |
|||
{ |
|||
ignoreNextSelection = true; |
|||
Selection.objects = obj; |
|||
SceneView.lastActiveSceneView.FrameSelected(); |
|||
} |
|||
if (GUILayout.Button("X", GUILayout.Width(24))) |
|||
{ |
|||
toRemove = i; |
|||
} |
|||
} |
|||
} |
|||
i++; |
|||
} |
|||
if (toRemove != -1) lockedObjects.RemoveAt(toRemove); |
|||
} |
|||
|
|||
int toAdd = -1; |
|||
toRemove = -1; |
|||
i = 0; |
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.Label("History", EditorStyles.boldLabel); |
|||
GUILayout.FlexibleSpace(); |
|||
if (GUILayout.Button("Clear")) |
|||
{ |
|||
selectionHistory.Clear(); |
|||
Repaint(); |
|||
} |
|||
|
|||
} |
|||
|
|||
var reversedHistory = selectionHistory.Reverse<GameObject[]>().ToArray(); |
|||
foreach (var obj in reversedHistory) |
|||
{ |
|||
if (obj == null || obj.Length == 0 || !CheckObjects(obj)) |
|||
{ |
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.Label("(object is either null or has been deleted)"); |
|||
if (GUILayout.Button("X", GUILayout.Width(24))) |
|||
{ |
|||
toRemove = i; |
|||
} |
|||
} |
|||
|
|||
} |
|||
else |
|||
{ |
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.Space(24); |
|||
string label = obj.Length > 1 ? "Multiple (" + obj.Length + ") : " + obj[0].name + " ..." : obj[0].name; |
|||
if (GUILayout.Button(label)) |
|||
{ |
|||
ignoreNextSelection = true; |
|||
Selection.objects = obj; |
|||
} |
|||
if (GUILayout.Button("F", GUILayout.Width(24))) |
|||
{ |
|||
ignoreNextSelection = true; |
|||
Selection.objects = obj; |
|||
SceneView.lastActiveSceneView.FrameSelected(); |
|||
} |
|||
if (GUILayout.Button("+", GUILayout.Width(24))) |
|||
{ |
|||
toAdd = i; |
|||
} |
|||
} |
|||
} |
|||
|
|||
i++; |
|||
} |
|||
if (toAdd != -1) |
|||
{ |
|||
lockedObjects.Add(reversedHistory[toAdd]); |
|||
Repaint(); |
|||
} |
|||
if (toRemove != -1) |
|||
{ |
|||
selectionHistory.RemoveAt(toRemove); |
|||
Repaint(); |
|||
} |
|||
|
|||
} |
|||
|
|||
static class Contents |
|||
{ |
|||
public static GUIContent title = new GUIContent("Select History"); |
|||
public static GUIContent star = EditorGUIUtility.IconContent("CustomSorting"); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 469c58d91c79ca34ea60c289f3cd53af |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue