Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Stats class
- using UnityEngine;
- public class Stats : MonoBehaviour
- {
- [SerializeField]
- private int health;
- }
- // Editor Class
- using UnityEditor;
- // Note the use of CustomEditor.
- [CustomEditor(typeof(Stats))]
- public class StatsEditor : Editor // Note that we inherit from Editor.
- {
- private static bool showGeneralSettings = true;
- public override void OnInspectorGUI()
- {
- // Create the foldout, and link it to our bool.
- showGeneralSettings = EditorGUILayout.Foldout(showGeneralSettings, "General Settings");
- // Create a space to separate this foldout from the other potential variables
- EditorGUILayout.Space();
- // This would make more sense as a switch when you add more settings.
- // If the foldout is opened.
- if (showGeneralSettings)
- {
- DisplayGeneralInfo();
- }
- // Apply changes made in the editor.
- serializedObject.ApplyModifiedProperties();
- }
- private void DisplayGeneralInfo()
- {
- // Find the health property for display.
- EditorGUILayout.PropertyField(serializedObject.FindProperty("health"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement