Advertisement
Pro_Unit

EnemySpawnerStaticDataPropertyDrawer

May 4th, 2023
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System.Linq;
  2.  
  3. using Game.Logic;
  4. using Game.Logic.EnemySpawners;
  5. using Game.Utilities;
  6.  
  7. using UnityEditor;
  8.  
  9. using UnityEngine;
  10.  
  11. namespace Game.StaticData
  12. {
  13.     [CustomPropertyDrawer(typeof(EnemySpawnerStaticData))]
  14.     public class EnemySpawnerStaticDataPropertyDrawer : PropertyDrawer
  15.     {
  16.         private RectDrawer _drawer;
  17.  
  18.         public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  19.         {
  20.             EditorGUI.BeginProperty(position, label, property);
  21.  
  22.             SerializedProperty idProperty = property.FindPropertyRelative("Id");
  23.             SerializedProperty monsterTypeIdProperty = property.FindPropertyRelative("MonsterTypeId");
  24.             SerializedProperty positionProperty = property.FindPropertyRelative("Position");
  25.  
  26.             _drawer ??= new RectDrawer(
  27.                 new PropertyLineDrawer(idProperty),
  28.                 new PropertyLineDrawer(positionProperty),
  29.                 new PropertyLineDrawer(monsterTypeIdProperty),
  30.                 new ButtonLineDrawer(nameof(Ping), () => Ping(idProperty.stringValue)));
  31.  
  32.             _drawer.Draw(position);
  33.  
  34.             EditorGUI.EndProperty();
  35.         }
  36.  
  37.         private static void Ping(string id) =>
  38.             Selection.activeGameObject = Object.FindObjectsOfType<SpawnMarker>()
  39.                 .Select(maker => maker.GetComponent<UniqueId>())
  40.                 .First(uniqueId1 => uniqueId1.Id == id)
  41.                 .gameObject;
  42.  
  43.         public override float GetPropertyHeight(SerializedProperty property, GUIContent label) =>
  44.             _drawer?.Height ?? EditorGUIUtility.singleLineHeight;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement