浏览代码

Selection History Improements + Toolbar UI / UX

/main
Thomas ICHÉ 6 年前
当前提交
2ad02e1b
共有 3 个文件被更改,包括 125 次插入56 次删除
  1. 15
      Editor/HierarchyHints/HierarchyHints.cs
  2. 38
      Editor/SceneViewToolbar.cs
  3. 128
      Editor/SelectionHistory/SelectionHistoryWindow.cs

15
Editor/HierarchyHints/HierarchyHints.cs


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<Camera>().Length > 0) selectionRect = DrawContent(selectionRect, Contents.cameraIcon, Color.white);
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);

GUI.Label(rect, label, Styles.rightLabel);
rect.width = rect.width - size;
return rect;
}
static Rect DrawContent(Rect rect, GUIContent content, Color color, int size = 12)
{
GUI.color = color;
GUI.Label(rect, content, Styles.rightLabel);
rect.width = rect.width - size;
return rect;
}
static class Contents
{
public static GUIContent cameraIcon = EditorGUIUtility.IconContent("Camera Icon");
}
static class Colors

38
Editor/SceneViewToolbar.cs


{
using (new GUILayout.HorizontalScope(EditorStyles.toolbar))
{
bool play = GUILayout.Toggle(EditorApplication.isPlaying, "Play from Here", EditorStyles.toolbarButton);
bool play = GUILayout.Toggle(EditorApplication.isPlaying, Contents.playFromHere, EditorStyles.toolbarButton);
if(GUI.changed)
{

EditorApplication.isPlaying = false;
}
GUILayout.Space(24);
bool isLinked = LinkGameView.Active;
isLinked = GUILayout.Toggle(isLinked, Contents.linkGameView, EditorStyles.toolbarButton, GUILayout.Width(48));
if (GUI.changed)
{
LinkGameView.Active = isLinked;
}
isLocked = GUILayout.Toggle(isLocked, "Lock LinkSceneView", EditorStyles.toolbarButton);
isLocked = GUILayout.Toggle(isLocked, Contents.lockLinkGameView, EditorStyles.toolbarButton);
{
}
{
}
}
GUILayout.FlexibleSpace();

GUILayout.Space(96);
}
}
}
static class Contents
{
public static GUIContent playFromHere;
public static GUIContent lockLinkGameView;
public static GUIContent linkGameView;
static Contents()
{
lockLinkGameView = new GUIContent(EditorGUIUtility.IconContent("IN LockButton"));
linkGameView = new GUIContent(EditorGUIUtility.IconContent("Camera Icon").image);
linkGameView.text = "Link";
playFromHere = new GUIContent(EditorGUIUtility.IconContent("Animation.Play"));
playFromHere.text = "Here";
}
}

128
Editor/SelectionHistory/SelectionHistoryWindow.cs


selectionHistory = null;
}
List<GameObject[]> selectionHistory;
List<GameObject[]> lockedObjects;
List<GameObject> selectionHistory;
List<GameObject> lockedObjects;
void OnSelectionChange()
{

return;
}
if (selectionHistory == null) selectionHistory = new List<GameObject[]>();
if (lockedObjects == null) lockedObjects = new List<GameObject[]>();
if (selectionHistory == null) selectionHistory = new List<GameObject>();
if (lockedObjects == null) lockedObjects = new List<GameObject>();
foreach(var go in Selection.gameObjects)
{
if (!selectionHistory.Contains(go))
selectionHistory.Add(go);
}
selectionHistory.RemoveAt(0);
selectionHistory.Take(maxHistoryCount);
if (selectionHistory.Count == 0 || CompareArray(selectionHistory[selectionHistory.Count - 1], Selection.gameObjects)) ;
selectionHistory.Add(Selection.gameObjects);
Repaint();
}

{
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;
if (selectionHistory == null) selectionHistory = new List<GameObject[]>();
if (lockedObjects == null) lockedObjects = new List<GameObject[]>();
if (selectionHistory == null) selectionHistory = new List<GameObject>();
if (lockedObjects == null) lockedObjects = new List<GameObject>();
using (new EditorGUILayout.HorizontalScope())
{
if (GUILayout.Button("Unselect All"))
{
Selection.activeObject = null;
ignoreNextSelection = true;
Repaint();
}
}
GUILayout.Label("Retained", EditorStyles.boldLabel);
GUILayout.Label("Favorites", EditorStyles.boldLabel);
if (obj == null || obj.Length == 0 || !CheckObjects(obj))
if (obj == null)
{
using (new EditorGUILayout.HorizontalScope())
{

}
else
{
bool highlight = Selection.gameObjects.Contains(obj);
Color backup = GUI.color;
if (highlight)
GUI.color = Styles.highlightColor;
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))
GUILayout.Label(Contents.star, EditorStyles.miniLabel, GUILayout.Width(24));
string label = obj.name;
if (GUILayout.Button(label, EditorStyles.foldout))
Selection.objects = obj;
Selection.activeObject = obj;
if (GUILayout.Button("F", GUILayout.Width(24)))
if (GUILayout.Button("Focus", EditorStyles.miniButton, GUILayout.Width(40)))
Selection.objects = obj;
Selection.activeObject = obj;
if (GUILayout.Button("X", GUILayout.Width(24)))
if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(24)))
var rect = GUILayoutUtility.GetLastRect();
EditorGUI.DrawRect(rect, new Color(0.2f, 0.2f, 0.2f, 0.5f));
GUI.color = backup;
}
i++;
}

selectionHistory.Clear();
Repaint();
}
}
}
GUILayout.Space(8);
var reversedHistory = selectionHistory.Reverse<GameObject[]>().ToArray();
var reversedHistory = selectionHistory.Reverse<GameObject>().ToArray();
if (obj == null || obj.Length == 0 || !CheckObjects(obj))
if (obj == null)
{
using (new EditorGUILayout.HorizontalScope())
{

}
else
{
bool highlight = Selection.gameObjects.Contains(obj);
Color backup = GUI.color;
if (highlight)
GUI.color = Styles.highlightColor;
GUILayout.Space(24);
string label = obj.Length > 1 ? "Multiple (" + obj.Length + ") : " + obj[0].name + " ..." : obj[0].name;
if (GUILayout.Button(label))
GUILayout.Space(16);
string label = obj.name;
if (GUILayout.Button(label, EditorStyles.foldout))
Selection.objects = obj;
Selection.activeObject = obj;
if (GUILayout.Button("F", GUILayout.Width(24)))
if (GUILayout.Button("Focus", Styles.historyButton, GUILayout.Width(40)))
Selection.objects = obj;
Selection.activeObject = obj;
if (GUILayout.Button("+", GUILayout.Width(24)))
if (GUILayout.Button(Contents.star, Styles.historyButton, GUILayout.Width(24)))
var rect = GUILayoutUtility.GetLastRect();
EditorGUI.DrawRect(rect, new Color(0.2f,0.2f,0.2f,0.5f));
GUI.color = backup;
}
i++;

}
static class Styles
{
public static GUIStyle historyButton;
public static GUIStyle highlight;
public static Color highlightColor = new Color(2.0f, 2.0f, 2.0f);
static Styles()
{
historyButton = new GUIStyle(EditorStyles.miniButton);
historyButton.alignment = TextAnchor.MiddleLeft;
highlight = new GUIStyle(EditorStyles.miniLabel);
highlight.onNormal.background = Texture2D.whiteTexture;
highlight.onHover.background = Texture2D.whiteTexture;
highlight.onActive.background = Texture2D.whiteTexture;
highlight.onFocused.background = Texture2D.whiteTexture;
}
}
public static GUIContent title = new GUIContent("Select History");
public static GUIContent title = new GUIContent("Selection History");
public static GUIContent star = EditorGUIUtility.IconContent("CustomSorting");
}
}
正在加载...
取消
保存