Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- namespace AnimalSimulator.Gameplay.Editor
- {
- [CustomEditor(typeof(AnimalSpawnMarker))]
- public class AnimalSpawnMarkerEditor : UnityEditor.Editor
- {
- [DrawGizmo(GizmoType.Active | GizmoType.Pickable | GizmoType.NonSelected)]
- public static void RenderCustomGizmo(AnimalSpawnMarker marker, GizmoType gizmo)
- {
- Vector3 position = marker.transform.position;
- bool haveType = marker.Type != null;
- string typeName = haveType ? marker.Type.name : "UNDEFINED";
- Color color = haveType ? Color.blue : Color.red;
- Handles.color = color;
- GUIStyle style = new GUIStyle(GUI.skin.label);
- style.normal.textColor = color;
- Handles.Label(position + Vector3.up * 1f, typeName, style);
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- if (GUI.changed)
- {
- bool haveType = Marker.Type != null;
- string typeName = haveType ? Marker.Type.name : "UNDEFINED";
- Marker.name = $"{typeName} Spawner";
- serializedObject.ApplyModifiedProperties();
- serializedObject.UpdateIfRequiredOrScript();
- }
- }
- private AnimalSpawnMarker Marker => (AnimalSpawnMarker)target;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement