PageRenderTime 211ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/Assets/Editor/ToonEditor.cs

https://gitlab.com/RunningFromLions/CombatSyatem
C# | 378 lines | 300 code | 63 blank | 15 comment | 35 complexity | a5e430a26d4cb8a50ba223981a560c64 MD5 | raw file
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. [CustomEditor(typeof(CreateNewCharacter))]
  5. public class ToonEditor : Editor
  6. {
  7. #region Foldout bools
  8. public bool Basic;
  9. public bool Evo;
  10. public bool Type;
  11. public bool Resources;
  12. public bool Appearance;
  13. public bool Stats;
  14. public bool Regen;
  15. public bool Audio;
  16. public bool Abilities;
  17. #endregion
  18. public override void OnInspectorGUI()
  19. {
  20. CreateNewCharacter Toon = (CreateNewCharacter)target;
  21. #region method invocation order
  22. #region Basic Info
  23. Basic = EditorGUILayout.Foldout(Basic, "Basic Information");
  24. if (Basic)
  25. {
  26. BasicInfo();
  27. }
  28. #endregion
  29. #region Evolution Info
  30. Evo = EditorGUILayout.Foldout(Evo, "Evolution Information");
  31. if (Evo)
  32. {
  33. EvolutionInfo();
  34. }
  35. #endregion
  36. #region Type Information
  37. Type = EditorGUILayout.Foldout(Type, "Elemental Type Selection");
  38. if (Type)
  39. {
  40. ElementalInfo();
  41. }
  42. #endregion
  43. #region Recource Information
  44. Resources = EditorGUILayout.Foldout(Resources, "Resource Information");
  45. if (Resources)
  46. {
  47. ResourceInfo();
  48. }
  49. #endregion
  50. #region Appearance information
  51. Appearance = EditorGUILayout.Foldout(Appearance, "Appearance Information");
  52. if (Appearance)
  53. {
  54. AppearanceInfo();
  55. }
  56. #endregion
  57. #region Stats
  58. Stats = EditorGUILayout.Foldout(Stats, "View/Edit Stats");
  59. if (Stats)
  60. {
  61. StatsInfo();
  62. }
  63. #endregion
  64. #region Regen Info
  65. Regen = EditorGUILayout.Foldout(Regen, "Stat Regen Information");
  66. if (Regen)
  67. {
  68. RegenInfo();
  69. }
  70. #endregion
  71. #region Audio Information
  72. Audio = EditorGUILayout.Foldout(Audio, "Audio Clip Selection");
  73. if (Audio)
  74. {
  75. AudioInfo();
  76. }
  77. #endregion
  78. #region Abilities
  79. Abilities = EditorGUILayout.Foldout(Abilities, "Ability Selection");
  80. if (Abilities)
  81. {
  82. AbilityInfo();
  83. }
  84. #endregion
  85. #endregion
  86. #region guichange
  87. //base.OnInspectorGUI();
  88. if (GUI.changed)
  89. {
  90. EditorUtility.SetDirty(Toon);
  91. }
  92. #endregion
  93. }
  94. public void BasicInfo()
  95. {
  96. CreateNewCharacter Toon = (CreateNewCharacter)target;
  97. #region Basic Info
  98. EditorGUILayout.HelpBox("Basic Info", MessageType.None);
  99. Toon.ToonID = EditorGUILayout.TextField("Toon ID", Toon.ToonID);
  100. Toon.Toon_Name = EditorGUILayout.TextField("Toon Name", Toon.Toon_Name);
  101. Toon.Toon_Description = EditorGUILayout.TextField("Toon Description", Toon.Toon_Description);
  102. #endregion
  103. }
  104. public void EvolutionInfo()
  105. {
  106. CreateNewCharacter Toon = (CreateNewCharacter)target;
  107. #region Evolution Info
  108. EditorGUILayout.Space();
  109. EditorGUILayout.HelpBox("Evolution Info", MessageType.None);
  110. #region if levelinfo is empty, ass a new CreateNewCharacter.LevelUp class so the editor doesnt bug out
  111. if (Toon.LevelInfo == null)
  112. {
  113. Toon.LevelInfo = new CreateNewCharacter.LevelUp();
  114. }
  115. #endregion
  116. #region Populate previous and next evolution so the editor doesnt yell at you
  117. if (Toon.LevelInfo.PreviousEvolution == null)
  118. {
  119. Toon.LevelInfo.PreviousEvolution = new CreateNewCharacter();
  120. }
  121. if (Toon.LevelInfo.PreviousEvolution == null)
  122. {
  123. Toon.LevelInfo.NextEvolution = new CreateNewCharacter();
  124. }
  125. #endregion
  126. // this is set up with an animation curve so we can try out having a dynamic leveling curve
  127. Toon.LevelInfo.XPCurve = EditorGUILayout.CurveField("XP Leveling Curve", Toon.LevelInfo.XPCurve);
  128. Toon.LevelInfo.PreviousEvolution = (CreateNewCharacter)EditorGUILayout.ObjectField("Previous Evolution", Toon.LevelInfo.PreviousEvolution, typeof(CreateNewCharacter), true);
  129. Toon.LevelInfo.NextEvolution = (CreateNewCharacter)EditorGUILayout.ObjectField("Next Evolution", Toon.LevelInfo.NextEvolution, typeof(CreateNewCharacter), true);
  130. Toon.LevelInfo.NextEvolutionLevel = EditorGUILayout.IntField("Next Evolution Level", Toon.LevelInfo.NextEvolutionLevel);
  131. #endregion
  132. }
  133. public void ElementalInfo()
  134. {
  135. CreateNewCharacter Toon = (CreateNewCharacter)target;
  136. #region Elemental Type
  137. EditorGUILayout.Space();
  138. EditorGUILayout.HelpBox("Elemental Type", MessageType.None);
  139. Toon.Type = (CreateNewDamageType)EditorGUILayout.ObjectField("Type", Toon.Type, typeof(CreateNewDamageType), false);
  140. #endregion
  141. }
  142. public void ResourceInfo()
  143. {
  144. CreateNewCharacter Toon = (CreateNewCharacter)target;
  145. #region Resource Info
  146. EditorGUILayout.Space();
  147. EditorGUILayout.HelpBox("Resource Type/Color", MessageType.None);
  148. EditorGUILayout.BeginHorizontal();
  149. Toon.ResourceType = (CreateNewResource)EditorGUILayout.ObjectField(Toon.ResourceType, typeof(CreateNewResource), false);
  150. if (Toon.ResourceType)
  151. {
  152. Color ResourceColor = Toon.ResourceType.ResourceBarColor;
  153. EditorGUILayout.ColorField(ResourceColor);
  154. }
  155. EditorGUILayout.EndHorizontal();
  156. #endregion
  157. }
  158. public void AppearanceInfo()
  159. {
  160. CreateNewCharacter Toon = (CreateNewCharacter)target;
  161. #region Appearance
  162. EditorGUILayout.Space();
  163. EditorGUILayout.Space();
  164. EditorGUILayout.HelpBox("Appearance", MessageType.None);
  165. Toon.Icon = (Sprite)EditorGUILayout.ObjectField("Toon GUI Icon", Toon.Icon, typeof(Sprite), false);
  166. Toon.Model = (GameObject)EditorGUILayout.ObjectField("Toon Model/Prefab", Toon.Model, typeof(GameObject), false);
  167. // added these vector3s so we can try to have some control as to where the spell effect originate and terminate
  168. // so we can avoid some weird situations where a charater appears to be shitting out particle effects
  169. // or likewise makign sue that every attack does target the back of their head or ass or some shit
  170. Toon.SpellOrigin = EditorGUILayout.Vector3Field("Attack Origin", Toon.SpellOrigin);
  171. Toon.SpellDestination = EditorGUILayout.Vector3Field("Attack Destination", Toon.SpellDestination);
  172. #endregion
  173. }
  174. public void StatsInfo()
  175. {
  176. // if you need to add another stat, add a new enum to the Attributes.StatName field
  177. // the editor will pouplate the field automatically
  178. CreateNewCharacter Toon = (CreateNewCharacter)target;
  179. #region Stats
  180. EditorGUILayout.Space();
  181. EditorGUILayout.HelpBox("Stats", MessageType.None);
  182. #region get the number of stats currently chilling in Attributes.StatName
  183. int Count = 0;
  184. foreach (Attributes.StatName stat in System.Enum.GetValues(typeof(Attributes.StatName)))
  185. {
  186. Count++;
  187. }
  188. #endregion
  189. #region if that number is different that what is currently in Toon.Stats, whipe Toon.Stats and re-populate
  190. if (Toon.Stats.Count != Count)
  191. {
  192. Toon.Stats.Clear();
  193. foreach (Attributes.StatName stat in System.Enum.GetValues(typeof(Attributes.StatName)))
  194. {
  195. Attributes A = new Attributes();
  196. A.Stat = stat;
  197. A.Value = new Attributes.Values();
  198. Toon.Stats.Add(A);
  199. }
  200. }
  201. #endregion
  202. #region for i loop to draw the StatName and the Values
  203. for (int i = 0; i < Toon.Stats.Count; i++)
  204. {
  205. string stat = Toon.Stats[i].Stat.ToString();
  206. Attributes.Values V = Toon.Stats[i].Value;
  207. EditorGUILayout.HelpBox(stat, MessageType.None);
  208. V.Base = EditorGUILayout.IntField("Base " + stat, V.Base);
  209. V.Max = EditorGUILayout.IntField("Max " + stat, V.Max);
  210. V.Current = EditorGUILayout.IntField("Current " + stat, V.Current);
  211. V.Regen = EditorGUILayout.IntField("Regeneration Rate " + stat, V.Regen);
  212. }
  213. #endregion
  214. #endregion
  215. }
  216. public void RegenInfo()
  217. {
  218. CreateNewCharacter Toon = (CreateNewCharacter)target;
  219. #region Regen - Nothing Here yet
  220. EditorGUILayout.BeginHorizontal();
  221. EditorGUILayout.LabelField("Base Resource Regen Per Tick");
  222. // Toon.Base_Resource_Regen = EditorGUILayout.FloatField(Toon.Base_Resource_Regen, GUILayout.MaxWidth(64));
  223. EditorGUILayout.EndHorizontal();
  224. EditorGUILayout.BeginHorizontal();
  225. EditorGUILayout.LabelField("Base Health Regen Per Tick");
  226. // Toon.Base_Health_Regen = EditorGUILayout.FloatField(Toon.Base_Health_Regen, GUILayout.MaxWidth(64));
  227. EditorGUILayout.EndHorizontal();
  228. EditorGUILayout.Space();
  229. EditorGUILayout.BeginHorizontal();
  230. EditorGUILayout.LabelField("Experience granted upon death");
  231. // Toon.Experience = EditorGUILayout.FloatField(Toon.Experience, GUILayout.MaxWidth(64));
  232. EditorGUILayout.EndHorizontal();
  233. EditorGUILayout.BeginHorizontal();
  234. EditorGUILayout.LabelField("Resources granted upon death");
  235. // Toon.Gold = EditorGUILayout.FloatField(Toon.Gold, GUILayout.MaxWidth(64));
  236. EditorGUILayout.EndHorizontal();
  237. #endregion
  238. }
  239. public void AudioInfo()
  240. {
  241. // if you need to add an additional audio clip- add a new entry to the enum field CreateNewCharacter.CharacterAudio.ClipName
  242. // the editor will pupulate the field automatically
  243. CreateNewCharacter Toon = (CreateNewCharacter)target;
  244. #region Audio
  245. EditorGUILayout.Space();
  246. EditorGUILayout.HelpBox("Sounds", MessageType.None);
  247. #region Count how many ClipNames are currently set in CreateNewCharacter.CharacterAudio
  248. int Count = 0;
  249. foreach (CreateNewCharacter.CharacterAudio.ClipName clip in System.Enum.GetValues(typeof(CreateNewCharacter.CharacterAudio.ClipName)))
  250. {
  251. Count++;
  252. }
  253. #endregion
  254. #region if that number is different than what AudioClips.Count shows, wipe AudioClips.Count and re-populate
  255. if (Toon.AudioClips.Count != Count)
  256. {
  257. Toon.AudioClips.Clear();
  258. foreach (CreateNewCharacter.CharacterAudio.ClipName clip in System.Enum.GetValues(typeof(CreateNewCharacter.CharacterAudio.ClipName)))
  259. {
  260. CreateNewCharacter.CharacterAudio A = new CreateNewCharacter.CharacterAudio();
  261. A.Name = clip;
  262. A.Clip = new AudioClip();
  263. Toon.AudioClips.Add(A);
  264. }
  265. }
  266. #endregion
  267. #region for i loop to draw the inspector shit
  268. for (int i = 0; i < Toon.AudioClips.Count; i++)
  269. {
  270. string Name = Toon.AudioClips[i].Name.ToString();
  271. Toon.AudioClips[i].Clip = (AudioClip)EditorGUILayout.ObjectField(Name, Toon.AudioClips[i].Clip, typeof(AudioClip), true);
  272. }
  273. #endregion
  274. #endregion
  275. }
  276. public void AbilityInfo()
  277. {
  278. CreateNewCharacter Toon = (CreateNewCharacter)target;
  279. #region Abilities
  280. EditorGUILayout.Space();
  281. EditorGUILayout.BeginHorizontal();
  282. EditorGUILayout.HelpBox("Base Moves", MessageType.None);
  283. EditorGUILayout.EndHorizontal();
  284. #region Add an ability to Toon.Skills if there are none there to appease the elder gods
  285. if (Toon.Skills.Count == 0)
  286. {
  287. SpellObject s = new SpellObject();
  288. Toon.Skills.Add(s);
  289. }
  290. #endregion
  291. #region For i loop to draw the inspector shit
  292. for (int i = 0; i < Toon.Skills.Count; i++)
  293. {
  294. Toon.Skills[i] = (SpellObject)EditorGUILayout.ObjectField(Toon.Skills[i], typeof(SpellObject), false);
  295. }
  296. #endregion
  297. #region "Add Spell" Button
  298. if (GUILayout.Button("Add Spell"))
  299. {
  300. SpellObject s = new SpellObject();
  301. Toon.Skills.Add(s);
  302. }
  303. #endregion
  304. #region "Remove Spell" Button
  305. // the length check is there so that you dont subtract 1 from a 0 length list
  306. //and end up with a -1 index and lock up the editor
  307. if (GUILayout.Button("Remove Spell") && Toon.Skills.Count > 1)
  308. {
  309. int index = Toon.Skills.Count - 1;
  310. Toon.Skills.RemoveAt(index);
  311. }
  312. #endregion
  313. #endregion
  314. }
  315. }