Advertisement
LeoJansson

myClassEditorMultiple

Mar 2nd, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6.  
  7. [CustomEditor(typeof(myClass))]
  8. [CanEditMultipleObjects]
  9. public class myClassEditorMultiple : Editor
  10. {
  11.     SerializedProperty showVariables;
  12.     SerializedProperty myInt;
  13.     SerializedProperty myFloat;
  14.     SerializedProperty myGameobject;
  15.     SerializedProperty myColor;
  16.  
  17.  
  18.     private void OnEnable()
  19.     {
  20.         showVariables = serializedObject.FindProperty("showVariables");
  21.         myInt = serializedObject.FindProperty("myInt");
  22.         myFloat = serializedObject.FindProperty("myFloat");
  23.         myGameobject = serializedObject.FindProperty("myGameobject");
  24.         myColor = serializedObject.FindProperty("myColor");
  25.     }
  26.  
  27.     public override void OnInspectorGUI()
  28.     {
  29.         serializedObject.Update();
  30.  
  31.  
  32.         showVariables.boolValue = EditorGUILayout.Toggle("Show variables", showVariables.boolValue);
  33.  
  34.         using (var showVariablesGroup = new EditorGUILayout.FadeGroupScope(Convert.ToSingle(showVariables.boolValue)))
  35.         {
  36.             if (showVariablesGroup.visible == true)
  37.             {
  38.                 EditorGUILayout.DelayedIntField(myInt, new GUIContent("Integer"));
  39.  
  40.                 EditorGUILayout.Slider(myFloat, 0.0f, 10.0f, new GUIContent("Float slider"));
  41.  
  42.                 EditorGUILayout.ObjectField(myGameobject, new GUIContent("A gameobject"));
  43.  
  44.                 EditorGUILayout.ColorField(new GUIContent("Color"), myColor.colorValue);
  45.             }
  46.         }
  47.  
  48.         serializedObject.ApplyModifiedProperties();
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement