Advertisement
Pro_Unit

AnimalSpawnMarkerEditor

Aug 13th, 2021
1,595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using UnityEditor;
  2.  
  3. using UnityEngine;
  4.  
  5. namespace AnimalSimulator.Gameplay.Editor
  6. {
  7.     [CustomEditor(typeof(AnimalSpawnMarker))]
  8.     public class AnimalSpawnMarkerEditor : UnityEditor.Editor
  9.     {
  10.         [DrawGizmo(GizmoType.Active | GizmoType.Pickable | GizmoType.NonSelected)]
  11.         public static void RenderCustomGizmo(AnimalSpawnMarker marker, GizmoType gizmo)
  12.         {
  13.             Vector3 position = marker.transform.position;
  14.  
  15.             bool haveType = marker.Type != null;
  16.             string typeName = haveType ? marker.Type.name : "UNDEFINED";
  17.             Color color = haveType ? Color.blue : Color.red;
  18.             Handles.color = color;
  19.             GUIStyle style = new GUIStyle(GUI.skin.label);
  20.             style.normal.textColor = color;
  21.             Handles.Label(position + Vector3.up * 1f, typeName, style);
  22.         }
  23.  
  24.         public override void OnInspectorGUI()
  25.         {
  26.             base.OnInspectorGUI();
  27.  
  28.             if (GUI.changed)
  29.             {
  30.                 bool haveType = Marker.Type != null;
  31.                 string typeName = haveType ? Marker.Type.name : "UNDEFINED";
  32.  
  33.                 Marker.name = $"{typeName} Spawner";
  34.  
  35.                 serializedObject.ApplyModifiedProperties();
  36.                 serializedObject.UpdateIfRequiredOrScript();
  37.             }
  38.         }
  39.  
  40.         private AnimalSpawnMarker Marker => (AnimalSpawnMarker)target;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement