Last active
November 28, 2023 04:23
-
-
Save fishtopher/f0caa8bd2c5cc5ed825c7c348dbe8908 to your computer and use it in GitHub Desktop.
Highlight Property Drawer - Simply sets the text/background colour of a field in the inspector.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do NOT put me in an /Editor/ folder | |
// Questions/bugs: [email protected] | |
using UnityEngine; | |
public class HighlightAttribute : PropertyAttribute { | |
public Color col; | |
public HighlightAttribute(float r=1, float g=0, float b=0) { | |
this.col = new Color(r,g,b,1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class HighlightDemo : MonoBehaviour { | |
[Highlight(1, .5f, .5f)] | |
public int Int = 1; | |
[Highlight(1, 1, .2f)] | |
public float Float = 1.23f; | |
[Highlight(1, .5f, 0)] | |
public float[] Array = new float[] { 1, 2, 3, 4, 5 }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put me in an /Editor/ folder | |
// Questions/bugs: [email protected] | |
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
[CustomPropertyDrawer(typeof(HighlightAttribute))] | |
public class HighlightPropertyDrawer : PropertyDrawer { | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { | |
var col = (attribute as HighlightAttribute).col; | |
Color prev = GUI.color; | |
GUI.color = col; | |
EditorGUI.PropertyField(position, property, label, true); | |
GUI.color = prev; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment