Preview Main Component Icon In Hierachy

Hey guys,
I made a simple script that shows the icon of the first component (after transform of course) of the gameobject in hierarchy and also show a toggle to toggle the active state of the object.
It can also show custom component icons, you just need to put them in Assets/Editor/Icons.
Also, it has some “smart” icon showing that shows differently depending if the object has components or not and if it has childs or not, if it’s a prefab or not too:
Plus:
– Mass deactivate/activate gameobject and its children by holding alt and clicking on its toggle.
ps.: The children will inherit the toggled object’s active state, IT WILL NOT TOGGLE THE CHILD ACTIVE STATE.
– Choose to only show specific component types and etc.
– If custom component type was added to the specific component types and there is no icon for it, it will show a gameobject icon
Here is the code:
// Main Component Icon, Active State Toggling and "Smart Empty Object Icon Display"
using UnityEditor;
using UnityEngine;
using System;
using System.Collections.Generic;

[InitializeOnLoad]
class MainComponentIcon
{
// only show these types if showAllTypes is false
static Type[] componentTypes = new Type[]
{
typeof(Light),
typeof(BoxCollider),
typeof(Camera),
typeof(ParticleSystem),
typeof(TrailRenderer),
typeof(MeshRenderer),
typeof(MeshFilter),
typeof(SpriteRenderer),
typeof(AudioSource),
typeof(Canvas),
typeof(CanvasGroup),
typeof(UnityEngine.UI.Image),
typeof(UnityEngine.UI.Button),
typeof(UnityEngine.UI.Text),

// must add the custom types here if showAllTypes is false
//typeof(GameController),
//typeof(PlayerController),
//typeof(SpellScript)
};
static bool showActiveToggle = true;
static bool showIndentedActiveToggle = true;
static bool showAllTypes = true;
static bool useFallbackIconForExcludedComponents = false;
static bool prefabOverOthers = true; // don't show any component icon if the gameobject is a prefab, show the prefab icon instead
static bool alwaysShowCustom = false; // will show all custom, even if they don't have custom images (will show the little script page icon)
static bool alwaysShowPrefabContainer = true;
static IdleObjectsView showEmptyPrefabIconInIdleObjects = IdleObjectsView.TransformIcon; // // gameobjects with no child or components
static FallbackIcon fallbackIcon = FallbackIcon.GameObjectOrTransformsOrPrefab;

// UI exceptions
static bool canvasOverPrefab = true;

static List<GameObject> allChildGOsForToggle;
static bool toggleActiveAllChildInheritToggleObject = true; // Attention: if hold alt and clickin on object toggle, it will set all childs active state to the same of the clicked object

static MainComponentIcon()
{
// Init
EditorApplication.hierarchyWindowItemOnGUI += HierarchyItemCB;
}

static void HierarchyItemCB(int instanceID, Rect selectionRect)
{
GameObject obj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
var backupColor = GUI.color;

if (obj)
{
Rect r = new Rect(selectionRect);
if (showActiveToggle)
{
// Toggle active button
r.x = showIndentedActiveToggle ? selectionRect.x - 28 : 2;
r.width = 18;
r.height = 16;

EditorGUI.BeginChangeCheck();

backupColor = GUI.color;
if (!obj.activeInHierarchy && obj.transform.parent != null) GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.5f);
var toggleValue = GUI.Toggle(r, obj.activeSelf, "");
GUI.color = backupColor;
if (toggleActiveAllChildInheritToggleObject && Event.current.alt)
{
if (EditorGUI.EndChangeCheck())
{
if (allChildGOsForToggle == null) allChildGOsForToggle = new List<GameObject>();
allChildGOsForToggle.Clear();
allChildGOsForToggle.Add(obj);
FetchAllChildGameObjects(obj.transform);
Undo.RecordObjects(allChildGOsForToggle.ToArray(), "Toggle GameObjects Active");
allChildGOsForToggle.ForEach(child => child.SetActive(toggleValue));
}
}
else
{
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(obj, "Toggle " + obj.name + " Active");
obj.SetActive(toggleValue);
}
}
}

// Icon
r.x = EditorGUIUtility.currentViewWidth - 38;
r.width = 18;
r.height = 18;
backupColor = GUI.color;
if (!obj.activeInHierarchy) GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.5f);
var components = obj.GetComponents<Component>();
if (components != null)
{
// FIRST COMPONENT IS ALWAYS TRANSFORM OR RECT TRASNFORM
if (components.Length > 1)
{
// HAS COMPONENTS
Type type = components[1].GetType();
Texture image = EditorGUIUtility.ObjectContent(null, type).image;
bool isInComponentTypesList = Array.Exists(componentTypes, x => x == type);

if (image == null)
{
// put your custom components icons in Assets/Editor/Icons, name it the same name of your class and change the extension below as accordingly
image = AssetDatabase.LoadAssetAtPath("Assets/Editor/Icons/" + type.ToString() + ".psd", typeof(Texture)) as Texture;
}

if (canvasOverPrefab && type == typeof(Canvas))
{
GUI.Label(r, EditorGUIUtility.IconContent("Canvas Icon"));
}
else if (prefabOverOthers && CanShowAsPrefab(obj))
{
ShowFallbackIcon(obj, r);
}
else if (!image && alwaysShowCustom)
{
GUI.Label(r, EditorGUIUtility.IconContent("cs Script Icon"));
}
else if (showAllTypes || isInComponentTypesList)
{
if (image)
{
GUI.Label(r, image);
}
else
{
ShowFallbackIcon(obj, r);
}
}
else if (image && useFallbackIconForExcludedComponents || alwaysShowPrefabContainer && CanShowAsPrefab(obj))
{
ShowFallbackIcon(obj, r);
}
}
else
{
// IDLE OBJECTS
if (obj.transform.childCount == 0)
{
if (CanShowAsPrefab(obj))
GUI.Label(r, EditorGUIUtility.IconContent("PrefabNormal Icon"));
else if (showEmptyPrefabIconInIdleObjects == IdleObjectsView.WhitePrefabIcon) // no child nor components
GUI.Label(r, EditorGUIUtility.IconContent("Prefab Icon"));
else if (showEmptyPrefabIconInIdleObjects == IdleObjectsView.TransformIcon) // no child nor components
{
if (obj.GetComponent<RectTransform>())
GUI.Label(r, EditorGUIUtility.IconContent("RectTransform Icon"));
else
GUI.Label(r, EditorGUIUtility.IconContent("Transform Icon"));
}
}
// NO COMPONENTS BUT HAS CHILDREN
else if (obj.transform.childCount > 0)
{
if (CanShowAsPrefab(obj))
GUI.Label(r, EditorGUIUtility.IconContent("PrefabNormal Icon"));
else
GUI.Label(r, EditorGUIUtility.IconContent("Prefab Icon"));

GUI.Label(r, EditorGUIUtility.IconContent("Transform Icon"));
}

}
}

GUI.color = backupColor;
}
}

static void ShowFallbackIcon(GameObject obj, Rect r)
{
switch (fallbackIcon)
{
case FallbackIcon.TransformOrRect:

if (obj.GetComponent<RectTransform>())
GUI.Label(r, EditorGUIUtility.IconContent("RectTransform Icon"));
else
GUI.Label(r, EditorGUIUtility.IconContent("Transform Icon"));
break;

case FallbackIcon.GameObjectOrPrefab:
if (CanShowAsPrefab(obj))
GUI.Label(r, EditorGUIUtility.IconContent("PrefabNormal Icon"));
else
GUI.Label(r, EditorGUIUtility.IconContent("GameObject Icon"));
break;

case FallbackIcon.GameObjectOrTransformsOrPrefab:
if (CanShowAsPrefab(obj))
GUI.Label(r, EditorGUIUtility.IconContent("PrefabNormal Icon"));
else
{
if (obj.GetComponents<Component>().Length > 1)
{
GUI.Label(r, EditorGUIUtility.IconContent("GameObject Icon"));
}
else
{
GUI.Label(r, EditorGUIUtility.IconContent("Transform Icon"));
}
}
break;
}
}

static bool IsPartOfPrefab(GameObject prefab)
{
return PrefabUtility.GetPrefabParent(prefab) != null;
}

static bool IsPrefabParent(GameObject prefab)
{
return PrefabUtility.FindPrefabRoot(prefab) == prefab;
}

static bool CanShowAsPrefab(GameObject prefab)
{
if (IsPrefabParent(prefab) &&
IsPartOfPrefab(prefab) &&
PrefabUtility.GetPrefabType(prefab) == PrefabType.PrefabInstance ||
PrefabUtility.GetPrefabType(prefab) == PrefabType.ModelPrefabInstance)
{
return true;
}

return false;
}

public static void FetchAllChildGameObjects(Transform transform)
{
if (allChildGOsForToggle == null) allChildGOsForToggle = new List<GameObject>();
foreach (Transform t in transform)
{
if (!allChildGOsForToggle.Contains(t.gameObject)) allChildGOsForToggle.Add(t.gameObject);
FetchAllChildGameObjects(t);
}
}

//static bool
}

enum FallbackIcon
{
None,
GameObjectOrTransformsOrPrefab,
GameObjectOrPrefab,
TransformOrRect
}

enum IdleObjectsView
{
None,
TransformIcon,
WhitePrefabIcon
}

 

I hope you enjoy!

Creature #9 Model Done


Animation in Maya


Unity Render


Concept Art

Follow us in the social medias:
Facebook: http://bit.ly/yorkgsfb
Twitter: http://bit.ly/yorkgstw
Blog: http://bit.ly/yorkgs
Tumblr: http://bit.ly/yorkgstb
IndieDB: http://bit.ly/creacorpindiedb
Youtube: http://bit.ly/yorkgsYT
Steam Concept: http://bit.ly/creaSteamWIP

Video Log #2 Even more battle system

Hello guys, long time no see!!

It’s time for another devlog video!

So, in this video you can see how the map exploration and battle system is coming along, some improvements to the battle system and lots of bug fixes, by the way, the video has no sound, you can keep listening to your music!

Different types of movements (attacks) being used and their respective visual effect showing up, the creatures also reacts accordingly, you can also note that using moves that makes contact plays a different animation than special moves (moves that doesn’t make contact).

The temporary battle stats is also already working and works kinda like in the Pokémon games.

Also, as you could notice, some creatures flee from the player character when they see him, that’s the creature nature system, there are some that flee, others that doesn’t care about the player’s presence and others that goes towards the player when he gets too close, there will be more types of natures later like going towards just after spotting the player, also some that don’t care about the player presence but if he stays too much time close they will go towards the player anyway, engaging a battle.

You can also notice in the video that the battle arena is now different, each type of scenario will load a different type of battle arena when a battle starts, I also added some fancy to the camera. Oh, I also implemented a very nice feature in the battle system, when the player is in the “choose action” turn he can cycle through cameras, zoom in/out and orbit around the camera target which is very cool.

In summary, almost the entire battle system is done, just need to fix some bugs here and there and implements new items/moves usage and etc, things like experience gaining, level up, temporary stats, super effective and not very effective moves against certain creatures elements, all of this is already done.

Ah, another thing, the animations are very unpolished, be patient, they will get better as the projects follows.

Ok guys, that’s it for this video, I hope you liked it! I made lots of other stuff but unfortunately cannot be show because is just technical stuff, things from the engine.

What’s next? Now is time to model the rest of the creatures that will be available in the prototype!

See you guys/gals next time!

DevLog #16 Creature 6 and 7 done!

After a long time (again) here I am with something more to show, I’m working a lot doings lots of things that I don’t want to show until I finish with it… and I just did it, finished modelling/texturing/rigging 2 more creature, the creature 6 and 7 this time:

The creature #6
Its concept:

model:

rigging test animation:

And the creature #7:
concept:

model:

rig test animation:

I hope you guys like!

Have a nice weekend and until next time!

DevLog #15 First 20 Creatures Concept Done

Hello guys and gals!!

After so much time here I am again with some news, I just finished making the concepts for the 20 creatures that will be available in the game’s prototype that I will release when I also launch the crowdfunding campaign!

I will post a poster with all of them here (which you can right click and visualize it bigger) but you can also visit my other social medias for a bigger version of each creature.

Here are the links for the social medias where I posted them separated:
Facebook
Twitter
Tumblr
IndieDB
DeviantArt

BUT there will be another creature hidden in the game world that I will not post any images of it, it’s a legendary one.

Ok people, that’s it for today, now I will start modelling these creatures but I think that I will post one by one instead of all of them at once!

See you next time!