SpawnPointEditor.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. [CustomEditor(typeof(SpawnPoint))]
  5. public class SpawnPointEditor : Editor
  6. {
  7. public static List<int> addedNpcList = new List<int>();
  8. public static List<string> addedNpcStrList = new List<string>();
  9. SpawnPoint sp;
  10. private SerializedProperty typeProperty;
  11. private GUIContent typeLbl = new GUIContent("Type");
  12. private GUIContent npcIdLbl = new GUIContent("NpcId");
  13. private GUIContent bossCamPosLbl = new GUIContent("Boss战镜头位置");
  14. private GUIContent bossCamRotLbl = new GUIContent("Boss战镜头旋转");
  15. private GUIContent bossCamFarLbl = new GUIContent("Boss战镜头最远距离");
  16. private void OnEnable()
  17. {
  18. sp = target as SpawnPoint;
  19. }
  20. void Init()
  21. {
  22. typeProperty = serializedObject.FindProperty("type");
  23. }
  24. public override void OnInspectorGUI()
  25. {
  26. serializedObject.Update();
  27. SpawnPointType preType = sp.type;
  28. sp.type = (SpawnPointType)EditorGUILayout.EnumPopup(typeLbl,sp.type);
  29. if(sp.type == SpawnPointType.Boss)
  30. {
  31. if(sp.TransferGo == null)
  32. {
  33. if (GUILayout.Button("添加传送位置"))
  34. {
  35. sp.AddTransferPoint();
  36. }
  37. }
  38. sp.camPos = EditorGUILayout.Vector3Field(bossCamPosLbl, sp.camPos);
  39. sp.camRot = EditorGUILayout.Vector3Field(bossCamRotLbl, sp.camRot);
  40. sp.camFar = EditorGUILayout.FloatField(bossCamFarLbl, sp.camFar);
  41. }else if(sp.type == SpawnPointType.Monster && preType == SpawnPointType.Boss)
  42. {
  43. sp.DeleteTransferPoint();
  44. }
  45. if(sp.type == SpawnPointType.Monster)
  46. {
  47. sp.npcIds.Clear();
  48. for(int idx =0; idx < sp.spawnLocs.Count;idx++)
  49. {
  50. MonsterSpawnLoc loc = sp.spawnLocs[idx];
  51. EditorGUILayout.BeginHorizontal();
  52. loc.npcId = EditorGUILayout.IntField("NpcId" + (idx + 1), loc.npcId);
  53. AddNpc(loc.npcId);
  54. if(addedNpcList.Count > 0)
  55. {
  56. int temp = EditorGUILayout.IntPopup(loc.npcId, addedNpcStrList.ToArray(), addedNpcList.ToArray());
  57. if(temp > 0)
  58. {
  59. loc.npcId = temp;
  60. }
  61. }
  62. sp.spawnLocs[idx] = loc;
  63. sp.npcIds.Add(loc.npcId);
  64. EditorGUILayout.EndHorizontal();
  65. }
  66. }
  67. sp.fHorSpace = EditorGUILayout.FloatField("水平间隔", sp.fHorSpace);
  68. sp.fVerSpace = EditorGUILayout.FloatField("垂直间隔", sp.fVerSpace);
  69. sp.fActorReadyDist = EditorGUILayout.FloatField("角色出生距离", sp.fActorReadyDist);
  70. if(GUILayout.Button("保存位置"))
  71. {
  72. sp.CalcPointPos();
  73. }
  74. sp.fRandomValue = EditorGUILayout.FloatField("随机距离", sp.fRandomValue);
  75. if(GUILayout.Button("随机位置"))
  76. {
  77. sp.RandomPos();
  78. }
  79. }
  80. static void AddNpc(int npcId)
  81. {
  82. if (npcId == 0) return;
  83. if (addedNpcList.Contains(npcId)) return;
  84. addedNpcList.Add(npcId);
  85. addedNpcStrList.Add(npcId.ToString());
  86. }
  87. }