TileSetInspector.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace DunGen.Editor
  5. {
  6. [CustomEditor(typeof(TileSet))]
  7. public sealed class TileSetInspector : UnityEditor.Editor
  8. {
  9. private readonly List<bool> tileShowWeights = new List<bool>();
  10. private readonly List<List<bool>> lockPrefabShowWeights = new List<List<bool>>();
  11. private bool showLockPrefabs = false;
  12. private void OnEnable()
  13. {
  14. TileSet tileSet = target as TileSet;
  15. for (int i = 0; i < tileSet.TileWeights.Weights.Count; i++)
  16. tileShowWeights.Add(false);
  17. for (int i = 0; i < tileSet.LockPrefabs.Count; i++)
  18. {
  19. lockPrefabShowWeights.Add(new List<bool>());
  20. for (int j = 0; j < tileSet.LockPrefabs[i].LockPrefabs.Weights.Count; j++)
  21. lockPrefabShowWeights[i].Add(false);
  22. }
  23. }
  24. public override void OnInspectorGUI()
  25. {
  26. TileSet tileSet = target as TileSet;
  27. if (tileSet == null)
  28. return;
  29. EditorUtil.DrawGameObjectChanceTableGUI("Tile", tileSet.TileWeights, tileShowWeights, false, true, target);
  30. EditorGUILayout.BeginVertical("box");
  31. showLockPrefabs = EditorGUILayout.Foldout(showLockPrefabs, "Locked Door Prefabs", true);
  32. if (showLockPrefabs)
  33. {
  34. int toDeleteIndex = -1;
  35. for (int i = 0; i < tileSet.LockPrefabs.Count; i++)
  36. {
  37. var l = tileSet.LockPrefabs[i];
  38. EditorGUILayout.BeginVertical("box");
  39. EditorGUILayout.BeginHorizontal();
  40. l.Socket = (DoorwaySocket)EditorGUILayout.ObjectField(new GUIContent("Socket Type", "The socket type that this locked door can be placed on. If left blank, the locked door can be placed on a doorway of any socket type"), l.Socket, typeof(DoorwaySocket), false);
  41. if (GUILayout.Button("x", EditorStyles.miniButton, InspectorConstants.SmallButtonWidth))
  42. toDeleteIndex = i;
  43. EditorGUILayout.EndHorizontal();
  44. if (i > lockPrefabShowWeights.Count - 1)
  45. lockPrefabShowWeights.Add(new List<bool>());
  46. EditorUtil.DrawGameObjectChanceTableGUI("Prefab", l.LockPrefabs, lockPrefabShowWeights[i], false, true, target);
  47. EditorGUILayout.EndVertical();
  48. }
  49. if (toDeleteIndex > -1)
  50. {
  51. Undo.RecordObject(target, "Remove Lock Prefab");
  52. tileSet.LockPrefabs.RemoveAt(toDeleteIndex);
  53. lockPrefabShowWeights.RemoveAt(toDeleteIndex);
  54. Undo.FlushUndoRecordObjects();
  55. }
  56. EditorGUILayout.Space();
  57. EditorGUILayout.Space();
  58. EditorGUILayout.Space();
  59. if (GUILayout.Button("Add"))
  60. {
  61. tileSet.LockPrefabs.Add(new LockedDoorwayAssociation());
  62. lockPrefabShowWeights.Add(new List<bool>());
  63. }
  64. }
  65. EditorGUILayout.EndVertical();
  66. if (GUI.changed)
  67. EditorUtility.SetDirty(tileSet);
  68. }
  69. }
  70. }