Skip to content

Instantly share code, notes, and snippets.

@fishtopher
Last active November 28, 2023 04:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fishtopher/f0caa8bd2c5cc5ed825c7c348dbe8908 to your computer and use it in GitHub Desktop.
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.
// Do NOT put me in an /Editor/ folder
// Questions/bugs: chris@vitei.com
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);
}
}
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 };
}
// Put me in an /Editor/ folder
// Questions/bugs: chris@vitei.com
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