[unity] Don't process icons in play mode.

This commit is contained in:
John 2017-06-28 16:03:23 +08:00 committed by GitHub
parent 2567339fa6
commit 7f367dd496

View File

@ -228,12 +228,10 @@ namespace Spine.Unity.Editor {
EditorApplication.hierarchyWindowItemOnGUI += HierarchyDragAndDrop; EditorApplication.hierarchyWindowItemOnGUI += HierarchyDragAndDrop;
// Hierarchy Icons // Hierarchy Icons
EditorApplication.hierarchyWindowChanged -= HierarchyIconsOnChanged; EditorApplication.playmodeStateChanged -= HierarchyIconsOnPlaymodeStateChanged;
EditorApplication.hierarchyWindowChanged += HierarchyIconsOnChanged; EditorApplication.playmodeStateChanged += HierarchyIconsOnPlaymodeStateChanged;
EditorApplication.hierarchyWindowItemOnGUI -= HierarchyIconsOnGUI; HierarchyIconsOnPlaymodeStateChanged();
EditorApplication.hierarchyWindowItemOnGUI += HierarchyIconsOnGUI;
HierarchyIconsOnChanged();
initialized = true; initialized = true;
} }
@ -496,58 +494,68 @@ namespace Spine.Unity.Editor {
#endregion #endregion
#region Hierarchy #region Hierarchy
static void HierarchyIconsOnChanged () { static void HierarchyIconsOnPlaymodeStateChanged () {
if (showHierarchyIcons) { skeletonRendererTable.Clear();
skeletonRendererTable.Clear(); skeletonUtilityBoneTable.Clear();
skeletonUtilityBoneTable.Clear(); boundingBoxFollowerTable.Clear();
boundingBoxFollowerTable.Clear();
SkeletonRenderer[] arr = Object.FindObjectsOfType<SkeletonRenderer>(); EditorApplication.hierarchyWindowChanged -= HierarchyIconsOnChanged;
foreach (SkeletonRenderer r in arr) EditorApplication.hierarchyWindowItemOnGUI -= HierarchyIconsOnGUI;
skeletonRendererTable.Add(r.gameObject.GetInstanceID(), r.gameObject);
SkeletonUtilityBone[] boneArr = Object.FindObjectsOfType<SkeletonUtilityBone>(); if (!Application.isPlaying && showHierarchyIcons) {
foreach (SkeletonUtilityBone b in boneArr) EditorApplication.hierarchyWindowChanged += HierarchyIconsOnChanged;
skeletonUtilityBoneTable.Add(b.gameObject.GetInstanceID(), b); EditorApplication.hierarchyWindowItemOnGUI += HierarchyIconsOnGUI;
HierarchyIconsOnChanged();
BoundingBoxFollower[] bbfArr = Object.FindObjectsOfType<BoundingBoxFollower>();
foreach (BoundingBoxFollower bbf in bbfArr)
boundingBoxFollowerTable.Add(bbf.gameObject.GetInstanceID(), bbf);
} }
} }
static void HierarchyIconsOnGUI (int instanceId, Rect selectionRect) { static void HierarchyIconsOnChanged () {
if (showHierarchyIcons) { skeletonRendererTable.Clear();
Rect r = new Rect(selectionRect); skeletonUtilityBoneTable.Clear();
if (skeletonRendererTable.ContainsKey(instanceId)) { boundingBoxFollowerTable.Clear();
r.x = r.width - 15;
r.width = 15;
GUI.Label(r, Icons.spine);
} else if (skeletonUtilityBoneTable.ContainsKey(instanceId)) {
r.x -= 26;
if (skeletonUtilityBoneTable[instanceId] != null) {
if (skeletonUtilityBoneTable[instanceId].transform.childCount == 0)
r.x += 13;
r.y += 2;
r.width = 13;
r.height = 13;
if (skeletonUtilityBoneTable[instanceId].mode == SkeletonUtilityBone.Mode.Follow)
GUI.DrawTexture(r, Icons.bone);
else
GUI.DrawTexture(r, Icons.poseBones);
}
} else if (boundingBoxFollowerTable.ContainsKey(instanceId)) {
r.x -= 26;
if (boundingBoxFollowerTable[instanceId] != null) {
if (boundingBoxFollowerTable[instanceId].transform.childCount == 0)
r.x += 13;
r.y += 2;
r.width = 13;
r.height = 13;
GUI.DrawTexture(r, Icons.boundingBox);
}
}
SkeletonRenderer[] arr = Object.FindObjectsOfType<SkeletonRenderer>();
foreach (SkeletonRenderer r in arr)
skeletonRendererTable.Add(r.gameObject.GetInstanceID(), r.gameObject);
SkeletonUtilityBone[] boneArr = Object.FindObjectsOfType<SkeletonUtilityBone>();
foreach (SkeletonUtilityBone b in boneArr)
skeletonUtilityBoneTable.Add(b.gameObject.GetInstanceID(), b);
BoundingBoxFollower[] bbfArr = Object.FindObjectsOfType<BoundingBoxFollower>();
foreach (BoundingBoxFollower bbf in bbfArr)
boundingBoxFollowerTable.Add(bbf.gameObject.GetInstanceID(), bbf);
}
static void HierarchyIconsOnGUI (int instanceId, Rect selectionRect) {
Rect r = new Rect(selectionRect);
if (skeletonRendererTable.ContainsKey(instanceId)) {
r.x = r.width - 15;
r.width = 15;
GUI.Label(r, Icons.spine);
} else if (skeletonUtilityBoneTable.ContainsKey(instanceId)) {
r.x -= 26;
if (skeletonUtilityBoneTable[instanceId] != null) {
if (skeletonUtilityBoneTable[instanceId].transform.childCount == 0)
r.x += 13;
r.y += 2;
r.width = 13;
r.height = 13;
if (skeletonUtilityBoneTable[instanceId].mode == SkeletonUtilityBone.Mode.Follow)
GUI.DrawTexture(r, Icons.bone);
else
GUI.DrawTexture(r, Icons.poseBones);
}
} else if (boundingBoxFollowerTable.ContainsKey(instanceId)) {
r.x -= 26;
if (boundingBoxFollowerTable[instanceId] != null) {
if (boundingBoxFollowerTable[instanceId].transform.childCount == 0)
r.x += 13;
r.y += 2;
r.width = 13;
r.height = 13;
GUI.DrawTexture(r, Icons.boundingBox);
}
} }
} }
#endregion #endregion