Advertisement
hybrid-dragon

HybridSpawnerEditor

Jan 30th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.85 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. [CustomEditor(typeof(HybridSpawner))]
  5. public class HybridSpawnerEditor : Editor
  6. {
  7.  
  8.     public override void OnInspectorGUI()
  9.     {
  10.         serializedObject.Update();
  11.         HybridSpawner spawner = (HybridSpawner)target;
  12.         SerializedProperty array = serializedObject.FindProperty("arrayChildren");
  13.         EditorGUI.BeginChangeCheck();
  14.         EditorGUILayout.PropertyField(array, true);
  15.         if (EditorGUI.EndChangeCheck())
  16.             serializedObject.ApplyModifiedProperties();
  17.         EditorGUILayout.BeginHorizontal();
  18.         EditorGUILayout.LabelField("Spawn Mode");
  19.         spawner.SpawnShape = (HybridSpawner.SpawnMode)EditorGUILayout.EnumPopup(spawner.SpawnShape);
  20.         EditorGUILayout.EndHorizontal();
  21.         spawner.cloneCount = EditorGUILayout.IntField("Spawn Count", spawner.cloneCount);
  22.         EditorGUILayout.BeginHorizontal();
  23.         EditorGUILayout.LabelField("Alignment Mode");
  24.         spawner.LookAtMode = (HybridSpawner.LookAt)EditorGUILayout.EnumPopup(spawner.LookAtMode);
  25.         EditorGUILayout.EndHorizontal();
  26.         EditorGUILayout.LabelField("Tip: You can rotate the spawner without rotating the children.");
  27.         switch (spawner.LookAtMode)
  28.         {
  29.             case HybridSpawner.LookAt.customRotation:
  30.                 break;
  31.             case HybridSpawner.LookAt.lookAtCentre:
  32.                 EditorGUILayout.BeginHorizontal();
  33.                 EditorGUILayout.LabelField("Lock Look Rotation");
  34.                 GUILayout.Label("X", GUILayout.Width(12));
  35.                 spawner.dontLookX = GUILayout.Toggle(spawner.dontLookX, "");
  36.                 GUILayout.Label("Y", GUILayout.Width(12));
  37.                 spawner.dontLookY = GUILayout.Toggle(spawner.dontLookY, "");
  38.                 GUILayout.Label("Z", GUILayout.Width(12));
  39.                 spawner.dontLookZ = GUILayout.Toggle(spawner.dontLookZ, "");
  40.                 EditorGUILayout.EndHorizontal();
  41.                 break;
  42.             case HybridSpawner.LookAt.lookAtSpawner:
  43.                 EditorGUILayout.BeginHorizontal();
  44.                 EditorGUILayout.LabelField("Lock Look Rotation");
  45.                 GUILayout.Label("X", GUILayout.Width(12));
  46.                 spawner.dontLookX = GUILayout.Toggle(spawner.dontLookX, "");
  47.                 GUILayout.Label("Y", GUILayout.Width(12));
  48.                 spawner.dontLookY = GUILayout.Toggle(spawner.dontLookY, "");
  49.                 GUILayout.Label("Z", GUILayout.Width(12));
  50.                 spawner.dontLookZ = GUILayout.Toggle(spawner.dontLookZ, "");
  51.                 EditorGUILayout.EndHorizontal();
  52.                 break;
  53.         }
  54.  
  55.         switch (spawner.SpawnShape)
  56.         {
  57.             case HybridSpawner.SpawnMode.staticPoint:
  58.                 spawner.setRotation = EditorGUILayout.Vector3Field(new GUIContent("Rotation Offset", "If left as zero in a custom rotation, it will be changed to the object's forward vector."), spawner.setRotation);
  59.                 spawner.setPosition = EditorGUILayout.Vector3Field("Spawn Position Offset", spawner.setPosition);
  60.                 break;
  61.             case HybridSpawner.SpawnMode.staticLine:
  62.                 spawner.setRotation = EditorGUILayout.Vector3Field(new GUIContent("Rotation Offset", "If left as zero in a custom rotation, it will be changed to the object's forward vector."), spawner.setRotation);
  63.                 spawner.setPosition = EditorGUILayout.Vector3Field(new GUIContent("Spawn Position Offset", "This offset position children spawn from each other starting from the spawner."), spawner.setPosition);
  64.                 spawner.staticCircleY = EditorGUILayout.FloatField("Y Position Offset", spawner.staticCircleY);
  65.                 break;
  66.             case HybridSpawner.SpawnMode.staticCircle:
  67.                 spawner.setRotation = EditorGUILayout.Vector3Field(new GUIContent("Rotation Offset", "If left as zero in a custom rotation, it will be changed to the object's forward vector."), spawner.setRotation);
  68.                 spawner.spawnRadiusScale = EditorGUILayout.FloatField(new GUIContent("Circle Radius", "Circle default radius is 1."), spawner.spawnRadiusScale);
  69.                 spawner.staticCircleY = EditorGUILayout.FloatField("Y Position Offset", spawner.staticCircleY);
  70.                 break;
  71.             case HybridSpawner.SpawnMode.randomCircle:
  72.                 spawner.setRotation = EditorGUILayout.Vector3Field(new GUIContent("Rotation Offset", "If left as zero in a custom rotation, it will be changed to the object's forward vector."), spawner.setRotation);
  73.                 spawner.randomRotMax = EditorGUILayout.Vector3Field(new GUIContent("Max Rotation", "Independent X, Y, and Z values ranging from 0 to infinity. Acts as upper bounds. If left as 0, it will be set to 360."), spawner.randomRotMax);
  74.                 spawner.spawnRadiusScale = EditorGUILayout.FloatField(new GUIContent("Circle Radius", "Circle default radius is 1."), spawner.spawnRadiusScale);
  75.                 spawner.staticCircleY = EditorGUILayout.FloatField("Y Position Offset", spawner.staticCircleY);
  76.                 break;
  77.             case HybridSpawner.SpawnMode.randomSphere:
  78.  
  79.                 spawner.setRotation = EditorGUILayout.Vector3Field(new GUIContent("Rotation Offset", "If left as zero in a custom rotation, it will be changed to the object's forward vector."), spawner.setRotation);
  80.                 spawner.randomRotMax = EditorGUILayout.Vector3Field(new GUIContent("Max Rotation", "Independent X, Y, and Z values ranging from 0 to infinity. Acts as upper bounds. If left as 0, it will be set to 360."), spawner.randomRotMax);
  81.                 spawner.spawnRadiusScale = EditorGUILayout.FloatField(new GUIContent("Sphere Radius", "Sphere default radius is 1."), spawner.spawnRadiusScale);
  82.                 spawner.staticCircleY = EditorGUILayout.FloatField("Y Position Offset", spawner.staticCircleY);
  83.                 break;
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement