Skip to content

Instantly share code, notes, and snippets.

@ByronMayne
Created May 29, 2017 11:17
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ByronMayne/36c48a13b5c9c396d406014049b5b30e to your computer and use it in GitHub Desktop.
Save ByronMayne/36c48a13b5c9c396d406014049b5b30e to your computer and use it in GitHub Desktop.
The source code behind my Unity tip.
using UnityEngine;
using System.Collections;
// This is not need but I just wanted to make the point clear.
public class AnimatedComponent : MonoBehaviour
{
}
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
[CustomEditor(typeof(AnimatedComponent))]
public class AnimatedEditor : Editor
{
private class Styles
{
public readonly GUIStyle lennyFaceStyle;
public readonly GUIStyle lennyTextStyle;
public readonly GUIStyle messageStyle;
public Styles()
{
lennyFaceStyle = new GUIStyle(EditorStyles.boldLabel);
lennyFaceStyle.fontSize = 40;
lennyFaceStyle.stretchWidth = false;
messageStyle = new GUIStyle(EditorStyles.boldLabel);
messageStyle.alignment = TextAnchor.MiddleLeft;
messageStyle.fontSize = 14;
}
}
private AnimBool m_FoldoutOpen;
private GUIContent m_LennyFace;
private GUIContent m_LennyText;
private Styles m_Styles;
public void OnEnable()
{
m_FoldoutOpen = new AnimBool();
m_FoldoutOpen.target = false; // Default to not open
m_FoldoutOpen.valueChanged.AddListener(Repaint);
m_LennyFace = new GUIContent("( ͡° ͜ʖ ͡°)");
m_LennyText = new GUIContent("oh hai");
}
public void OnDisable()
{
m_FoldoutOpen.valueChanged.RemoveListener(Repaint);
}
public override void OnInspectorGUI()
{
if (m_Styles == null)
{
m_Styles = new Styles();
}
// Target is where it's going to
m_FoldoutOpen.target = EditorGUILayout.Toggle("Open", m_FoldoutOpen.target);
// Do our fade group
if (EditorGUILayout.BeginFadeGroup(m_FoldoutOpen.faded))
{
GUILayout.BeginHorizontal(GUI.skin.box);
{
GUILayout.Label(m_LennyFace, m_Styles.lennyFaceStyle);
GUILayout.Label(m_LennyText, m_Styles.messageStyle);
}
GUILayout.EndHorizontal();
}
EditorGUILayout.EndFadeGroup();
}
}
@ByronMayne
Copy link
Author

untiytipgif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment