Advertisement
LeoJansson

myClassEditor

Mar 2nd, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 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. public class myClassEditor : Editor
  9. {
  10.     public override void OnInspectorGUI()
  11.     {
  12.         myClass scriptToEdit = (myClass)target;
  13.  
  14.  
  15.         //Used to hide all variables instead of greying them out.
  16.         //scriptToEdit.showVariables = EditorGUILayout.Toggle("Show variables", scriptToEdit.showVariables);
  17.         //using (var showVariablesGroup = new EditorGUILayout.FadeGroupScope(Convert.ToSingle(scriptToEdit.showVariables)))
  18.         //{
  19.             //if (showVariablesGroup.visible == true)
  20.             //{
  21.             //}
  22.  
  23.         using (var showVariablesGroup = new EditorGUILayout.ToggleGroupScope("Show variables", scriptToEdit.showVariables))
  24.         {
  25.  
  26.             scriptToEdit.showVariables = showVariablesGroup.enabled;
  27.  
  28.             //Indents the text in the inspector 1 step.
  29.             EditorGUI.indentLevel++;
  30.  
  31.             //This creates a regular field that takes an integer, just like public or serializeable will do.
  32.             scriptToEdit.myInt = EditorGUILayout.IntField("Here you can add a label to your field", scriptToEdit.myInt);
  33.  
  34.             //This creates a slider for a floating point between 0 and 10
  35.             scriptToEdit.myFloat = EditorGUILayout.Slider("This is a slider", scriptToEdit.myFloat, 0.0f, 10.0f);
  36.                
  37.             //This creates a field that tales a game object
  38.             //the last "true" is a bool that allows/disallows objects from the scene to be used.
  39.             scriptToEdit.myGameobject =
  40.                 (GameObject)EditorGUILayout.ObjectField("This field lets you add a gameobject", scriptToEdit.myGameobject, typeof(GameObject), true);
  41.  
  42.             //Creates a small spacing between the last control and the next one.
  43.             EditorGUILayout.Space();
  44.  
  45.             //This provides a field where the user can select a color from the RGB spectrum.
  46.             scriptToEdit.myColor = EditorGUILayout.ColorField("Here there be colors", scriptToEdit.myColor);
  47.  
  48.             //Moves the indentation 1 step to the left.
  49.             EditorGUI.indentLevel--;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement