- Home /
Sprite changes that only apply in scene view
I'm making a brick breaker game with a twist, and one of the features that I'm implementing requires me to add a public flag (i.e. a bool) to the brick's script, and then to set that flag on a desired number of bricks. However, since they all look the same, the only way I can tell if said flag is set on a brick or not is to check them manually in the inspector.
What I would like is a way to add a visual change to the brick's sprite/object in the scene when that flag is set, such as a highlight or a border glow, that is only applied to object in the scene view. When the game is actually being played, that change should go away.
Is there any way to achieve this effect?
You can change the object icon, since you only want to see it on the Scene. Found this thread here: https://answers.unity.com/questions/213140/programmatically-assign-an-editor-icon-to-a-game-o.html
Answer by misher · Sep 05, 2018 at 12:24 PM
Let's say you have:
using UnityEngine;
public class TestScript : MonoBehaviour {
public bool myBool;
}
You can create custom editor for say, parent of all briks, to display in scene view some gizmos:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class TestScriptParent : MonoBehaviour {
public TestScript[] testScripts;
public TestScript[] TestScripts
{
get
{
return GetComponentsInChildren<TestScript>();
}
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(TestScriptParent))]
public class TestScriptParentEditor : Editor
{
float circleSize = 10f;
void OnSceneGUI()
{
TestScriptParent t = target as TestScriptParent;
foreach (var s in t.TestScripts)
{
if (s.myBool) Handles.DrawSolidDisc(s.transform.position, Vector3.forward, circleSize);
}
}
}
#endif
You still need to select parent object in order to run its custom inspector and draw gizmos. You also can create custom editor window, and when you open it, your custom editor script for it can find all objects of certain type in the scene and draw gizmos in the same way in them.
Not OP, but that's a pretty good starting template, will probably use in the future, thanks!
Thank you so much, this looks legit! I will try it out and will let you know the result or if I need more help.
It's been a while, but I finally tried your code sample, and it was a really good starting point, so thank you so much for your help! The effect was exactly what I was looking for, I will build on top of it to suit my particular needs.