duck

duck

Jun 14th, 2010
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. ///// The MonoBehaviour:
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7.  
  8. public class MyMonoBehaviour : MonoBehaviour
  9. {
  10.     public enum MyEnum { ValueA, ValueB, ValueC };
  11.  
  12.     private Dictionary<MyEnum, bool> m_MyEnumToggles = new Dictionary<MyEnum, bool> ();
  13.  
  14.     public bool m_MyBool;
  15.     public string m_MyString;
  16.  
  17.     public bool GetEnumToggle (MyEnum key)
  18.     {
  19.         if (!m_MyEnumToggles.ContainsKey (key))
  20.         {
  21.             return false;
  22.         }
  23.  
  24.         return m_MyEnumToggles[key];
  25.     }
  26.  
  27.     public void SetEnumToggle (MyEnum key, bool value)
  28.     {
  29.         m_MyEnumToggles[key] = value;
  30.     }
  31. }
  32.  
  33.  
  34.  
  35. ///// The editor:
  36.  
  37. using UnityEngine;
  38. using UnityEditor;
  39. using System;
  40.  
  41. [CustomEditor (typeof (MyMonoBehaviour))]
  42. public class MyEditor : Editor
  43. {
  44.     void OnInspectorGUI ()
  45.     {
  46.         MyMonoBehaviour myMonoBehaviour = target as MyMonoBehaviour;
  47.         if (myMonoBehaviour == null)
  48.         {
  49.             GUILayout.Label ("No target");
  50.             return;
  51.         }
  52.  
  53.         foreach (int i in Enum.GetValues (typeof (MyMonoBehaviour.MyEnum)))
  54.         {
  55.             myMonoBehaviour.SetEnumToggle ((MyMonoBehaviour.MyEnum)i, EditorGUILayout.Toggle (Enum.GetName (typeof (MyMonoBehaviour.MyEnum), i), myMonoBehaviour.GetEnumToggle ((MyMonoBehaviour.MyEnum)i)));
  56.         }
  57.  
  58.         DrawDefaultInspector ();
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment