浏览代码

Fixes for PR: Added Messages / Menu Items

/main
Thomas ICHÉ 5 年前
当前提交
34ef5a59
共有 4 个文件被更改,包括 192 次插入169 次删除
  1. 22
      Editor/CallTree/CallTreeWindow.cs
  2. 5
      Editor/MenuItems.cs
  3. 332
      Editor/SelectionHistory/SelectionHistoryWindow.cs
  4. 2
      Editor/WelcomeScreen/WelcomeScreen.cs

22
Editor/CallTree/CallTreeWindow.cs


using GameplayIngredients.StateMachines;
using UnityEngine.SceneManagement;
namespace GameplayIngredients
namespace GameplayIngredients.Editor
[MenuItem("Window/Callable Tree Explorer")]
[MenuItem("Window/Gameplay Ingredients/Callable Tree Explorer", priority = MenuItems.kWindowMenuPriority)]
static void OpenWindow()
{
GetWindow<CallTreeWindow>();

AddToCategory<EventBase>("Events");
AddToCategory<StateMachine>("State Machines");
AddToCategory<Factory>("Factories");
AddToCategory<SendMessageAction>("Messages");
m_TreeView.Reload();
}

if(typeof(T) == typeof(StateMachine))
{
listRoot.Add(GetStateMachineNode(item as StateMachine));
}
else if(typeof(T) == typeof(SendMessageAction))
{
listRoot.Add(GetMessageNode(item as SendMessageAction));
}
else
{

}
return rootNode;
}
CallTreeNode GetMessageNode(SendMessageAction sm)
{
var rootNode = new CallTreeNode(sm, CallTreeNodeType.Message, sm.MessageToSend);
var all = Resources.FindObjectsOfTypeAll<OnMessageEvent>().Where(o=> o.MessageName == sm.MessageToSend).ToList();
foreach(var evt in all)
{
rootNode.Children.Add(GetNode(evt));
}
return rootNode;
}
CallTreeNode GetStateMachineNode(StateMachine sm)
{

5
Editor/MenuItems.cs


{
public static class MenuItems
{
const int kPlayMenuPriority = 160;
const int kMenuPriority = 330;
public const int kWindowMenuPriority = 100;
public const int kPlayMenuPriority = 160;
public const int kMenuPriority = 330;
#region PLAY HERE

332
Editor/SelectionHistory/SelectionHistoryWindow.cs


using System.Reflection;
using UnityEngine;
using UnityEditor;
public class SelectionHistoryWindow : EditorWindow
namespace GameplayIngredients.Editor
[MenuItem("Window/Selection History")]
public static void OpenSelectionHistoryWindow()
public class SelectionHistoryWindow : EditorWindow
EditorWindow.GetWindow<SelectionHistoryWindow>();
}
Vector2 scrollPos = Vector2.zero;
void OnGUI()
{
titleContent = Contents.title;
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
[MenuItem("Window/General/Selection History")]
public static void OpenSelectionHistoryWindow()
Selection_OnGUI();
EditorWindow.GetWindow<SelectionHistoryWindow>();
EditorGUILayout.EndScrollView();
}
void OnEnable()
{
lockedObjects = null;
selectionHistory = null;
}
Vector2 scrollPos = Vector2.zero;
void OnDisable()
{
lockedObjects = null;
selectionHistory = null;
}
void OnGUI()
{
titleContent = Contents.title;
List<GameObject> selectionHistory;
List<GameObject> lockedObjects;
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
{
Selection_OnGUI();
}
EditorGUILayout.EndScrollView();
}
int maxHistoryCount = 32;
bool ignoreNextSelection = false;
void OnEnable()
{
lockedObjects = null;
selectionHistory = null;
}
void OnSelectionChange()
{
if (ignoreNextSelection)
void OnDisable()
ignoreNextSelection = false;
return;
lockedObjects = null;
selectionHistory = null;
if (selectionHistory == null) selectionHistory = new List<GameObject>();
if (lockedObjects == null) lockedObjects = new List<GameObject>();
List<GameObject> selectionHistory;
List<GameObject> lockedObjects;
int maxHistoryCount = 32;
bool ignoreNextSelection = false;
if (Selection.activeGameObject != null || Selection.gameObjects.Length > 0)
void OnSelectionChange()
foreach(var go in Selection.gameObjects)
if (ignoreNextSelection)
if (!selectionHistory.Contains(go))
selectionHistory.Add(go);
ignoreNextSelection = false;
return;
if (selectionHistory.Count > maxHistoryCount)
selectionHistory.Take(maxHistoryCount);
if (selectionHistory == null) selectionHistory = new List<GameObject>();
if (lockedObjects == null) lockedObjects = new List<GameObject>();
Repaint();
}
if (Selection.activeGameObject != null || Selection.gameObjects.Length > 0)
{
}
foreach(var go in Selection.gameObjects)
{
if (!selectionHistory.Contains(go))
selectionHistory.Add(go);
}
public bool CompareArray(GameObject[] a, GameObject[] b)
{
return a.SequenceEqual(b);
}
if (selectionHistory.Count > maxHistoryCount)
selectionHistory.Take(maxHistoryCount);
void Selection_OnGUI()
{
if (selectionHistory == null) selectionHistory = new List<GameObject>();
if (lockedObjects == null) lockedObjects = new List<GameObject>();
int i = 0;
int toRemove = -1;
Repaint();
}
if (lockedObjects.Count > 0)
}
public bool CompareArray(GameObject[] a, GameObject[] b)
GUILayout.Label("Favorites", EditorStyles.boldLabel);
i = 0;
toRemove = -1;
foreach (var obj in lockedObjects)
return a.SequenceEqual(b);
}
void Selection_OnGUI()
{
if (selectionHistory == null) selectionHistory = new List<GameObject>();
if (lockedObjects == null) lockedObjects = new List<GameObject>();
int i = 0;
int toRemove = -1;
if (lockedObjects.Count > 0)
if (obj == null)
GUILayout.Label("Favorites", EditorStyles.boldLabel);
i = 0;
toRemove = -1;
foreach (var obj in lockedObjects)
using (new EditorGUILayout.HorizontalScope())
if (obj == null)
GUILayout.Label("(object is either null or has been deleted)");
if (GUILayout.Button("X", GUILayout.Width(24)))
using (new EditorGUILayout.HorizontalScope())
toRemove = i;
GUILayout.Label("(object is either null or has been deleted)");
if (GUILayout.Button("X", GUILayout.Width(24)))
{
toRemove = i;
}
else
{
bool highlight = Selection.gameObjects.Contains(obj);
Color backup = GUI.color;
if (highlight)
GUI.color = Styles.highlightColor;
using (new EditorGUILayout.HorizontalScope())
{
var b = GUI.color;
GUI.color = Color.yellow * 3;
if (GUILayout.Button(Contents.star, Styles.icon, GUILayout.Width(24)))
{
toRemove = i;
}
GUI.color = b;
string label = obj.name;
if (GUILayout.Button(label, EditorStyles.foldout))
{
ignoreNextSelection = true;
Selection.activeObject = obj;
}
if (GUILayout.Button("Focus", EditorStyles.miniButton, GUILayout.Width(40)))
{
ignoreNextSelection = true;
Selection.activeObject = obj;
SceneView.lastActiveSceneView.FrameSelected();
}
}
GUI.color = backup;
}
i++;
else
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", EditorStyles.miniButton))
{
selectionHistory.Clear();
Repaint();
}
}
GUILayout.Space(8);
var reversedHistory = selectionHistory.Reverse<GameObject>().ToArray();
foreach (var obj in reversedHistory)
{
if (obj != null)
{
bool highlight = Selection.gameObjects.Contains(obj);
Color backup = GUI.color;

using (new EditorGUILayout.HorizontalScope())
{
var b = GUI.color;
GUI.color = Color.yellow * 3;
if (GUILayout.Button(Contents.star, Styles.icon, GUILayout.Width(24)))
if (GUILayout.Button(Contents.starDisabled, Styles.icon, GUILayout.Width(24)))
toRemove = i;
toAdd = i;
GUI.color = b;
if (GUILayout.Button("Focus", EditorStyles.miniButton, GUILayout.Width(40)))
if (GUILayout.Button("Focus", Styles.historyButton, GUILayout.Width(40)))
{
ignoreNextSelection = true;
Selection.activeObject = obj;

var rect = GUILayoutUtility.GetLastRect();
EditorGUI.DrawRect(rect, new Color(0.2f,0.2f,0.2f,0.5f));
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", EditorStyles.miniButton))
if (toAdd != -1)
{
lockedObjects.Add(reversedHistory[toAdd]);
Repaint();
}
if (toRemove != -1)
selectionHistory.Clear();
selectionHistory.RemoveAt(toRemove);
}
GUILayout.Space(8);
}
var reversedHistory = selectionHistory.Reverse<GameObject>().ToArray();
foreach (var obj in reversedHistory)
static class Styles
if (obj != null)
{
bool highlight = Selection.gameObjects.Contains(obj);
Color backup = GUI.color;
if (highlight)
GUI.color = Styles.highlightColor;
public static GUIStyle historyButton;
public static GUIStyle highlight;
public static Color highlightColor = new Color(2.0f, 2.0f, 2.0f);
using (new EditorGUILayout.HorizontalScope())
{
public static GUIStyle icon;
if (GUILayout.Button(Contents.starDisabled, Styles.icon, GUILayout.Width(24)))
{
toAdd = i;
}
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;
string label = obj.name;
if (GUILayout.Button(label, EditorStyles.foldout))
{
ignoreNextSelection = true;
Selection.activeObject = obj;
}
if (GUILayout.Button("Focus", Styles.historyButton, GUILayout.Width(40)))
{
ignoreNextSelection = true;
Selection.activeObject = obj;
SceneView.lastActiveSceneView.FrameSelected();
}
}
var rect = GUILayoutUtility.GetLastRect();
EditorGUI.DrawRect(rect, new Color(0.2f,0.2f,0.2f,0.5f));
icon = new GUIStyle(EditorStyles.label);
icon.fixedHeight = 16;
icon.padding = new RectOffset(8,2,2,0);
icon.margin = new RectOffset();
GUI.color = backup;
i++;
}
if (toAdd != -1)
{
lockedObjects.Add(reversedHistory[toAdd]);
Repaint();
}
if (toRemove != -1)
{
selectionHistory.RemoveAt(toRemove);
Repaint();
}
static class Styles
{
public static GUIStyle historyButton;
public static GUIStyle highlight;
public static Color highlightColor = new Color(2.0f, 2.0f, 2.0f);
public static GUIStyle icon;
static Styles()
static class Contents
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;
icon = new GUIStyle(EditorStyles.label);
icon.fixedHeight = 16;
icon.padding = new RectOffset(8,2,2,0);
icon.margin = new RectOffset();
public static GUIContent title = new GUIContent("Selection History");
public static GUIContent star = new GUIContent(EditorGUIUtility.IconContent("Favorite Icon").image);
public static GUIContent starDisabled = new GUIContent(EditorGUIUtility.IconContent("Favorite").image);
}
static class Contents
{
public static GUIContent title = new GUIContent("Selection History");
public static GUIContent star = new GUIContent(EditorGUIUtility.IconContent("Favorite Icon").image);
public static GUIContent starDisabled = new GUIContent(EditorGUIUtility.IconContent("Favorite").image);
}
}

2
Editor/WelcomeScreen/WelcomeScreen.cs


EditorApplication.update -= ShowAtStartup;
}
[MenuItem("Window/Gameplay Ingredients")]
[MenuItem("Window/Gameplay Ingredients/Welcome Screen", priority = MenuItems.kWindowMenuPriority)]
static void ShowFromMenu()
{
GetWindow<WelcomeScreen>(true, "Gameplay Ingredients");

正在加载...
取消
保存