Created
May 29, 2017 11:17
-
-
Save ByronMayne/36c48a13b5c9c396d406014049b5b30e to your computer and use it in GitHub Desktop.
The source code behind my Unity tip.
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 UnityEngine; | |
using System.Collections; | |
// This is not need but I just wanted to make the point clear. | |
public class AnimatedComponent : MonoBehaviour | |
{ | |
} |
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 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(); | |
} | |
} |
Author
ByronMayne
commented
May 29, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment