Browse Source

Added script to show fungus icon in the hierarchy

master
desktop-maesty/steve 7 years ago
parent
commit
d32c31aa74
  1. 60
      Assets/Fungus/Scripts/Editor/HierarchyIcons.cs
  2. 12
      Assets/Fungus/Scripts/Editor/HierarchyIcons.cs.meta

60
Assets/Fungus/Scripts/Editor/HierarchyIcons.cs

@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
namespace Fungus
{
/// <summary>
/// Static class that hooks into the hierachy changed and item gui callbacks to put
/// a fungus icon infront of all GOs that have a flowchart on them
///
/// Reference; http://answers.unity3d.com/questions/431952/how-to-show-an-icon-in-hierarchy-view.html
/// </summary>
[InitializeOnLoad]
public class HierarchyIcons
{
// the fungus mushroom icon
static Texture2D textureIcon;
//sorted list of the GO instance IDs that have flowcharts on them
static List<int> flowchartIDs = new List<int>();
static HierarchyIcons()
{
//please don't move the fungus icon :(
textureIcon = AssetDatabase.LoadAssetAtPath("Assets/Fungus/Textures/ScriptIcon.png", typeof(Texture2D)) as Texture2D;
EditorApplication.hierarchyWindowItemOnGUI += HierarchyIconCallback;
EditorApplication.hierarchyWindowChanged += HierarchyChanged;
}
//track all gameobjectIds that have flowcharts on them
static void HierarchyChanged()
{
flowchartIDs.Clear();
var flowcharts = GameObject.FindObjectsOfType<Flowchart>();
flowchartIDs = flowcharts.Select(x => x.gameObject.GetInstanceID()).Distinct().ToList();
flowchartIDs.Sort();
}
//Draw icon if the isntance id is in our cached list
static void HierarchyIconCallback(int instanceID, Rect selectionRect)
{
// place the icon to the left of the element
Rect r = new Rect(selectionRect);
r.x = 0;
r.width = r.height;
//GameObject go = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
//binary search as it is much faster to cache and int bin search than GetComponent
// should be less GC too
if (flowchartIDs.BinarySearch(instanceID) >= 0)
GUI.Label(r, textureIcon);
}
}
}

12
Assets/Fungus/Scripts/Editor/HierarchyIcons.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a347e274da09aa44dbb68f1375508d11
timeCreated: 1500115754
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save