Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

ByronMayne commented May 29, 2017

untiytipgif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.