fork download
  1.  
  2. using UnityEngine;
  3. using UnityEditor;
  4.  
  5.  
  6. [CustomEditor(typeof(MapComponent))]
  7. public class MapComponentEditor : Editor
  8. {
  9. private MapComponent lastSelected;
  10.  
  11. private float cellSize;
  12. private int height;
  13. private int width;
  14. private bool isGenerated;
  15. private bool isPlaced;
  16.  
  17. void OnTriggerDownMove()
  18. {
  19. isPlaced = true;
  20. }
  21.  
  22. /**
  23. * On inspector's GUI update
  24. * @param - <Object> target (inherited) - selected object
  25. * @return - NONE
  26. */
  27. public override void OnInspectorGUI()
  28. {
  29. // Get info about selected object
  30. isGenerated = ((MapComponent)target).isGenerated;
  31. isPlaced = (((MapComponent)target).gameObject.scene.buildIndex != -1);
  32.  
  33. // If new object selected - update displayed parameters
  34. if (lastSelected != (MapComponent)target) {
  35. lastSelected = (MapComponent)target;
  36. cellSize = ((MapComponent)target).cellSize;
  37. height = ((MapComponent)target).height;
  38. width = ((MapComponent)target).width;
  39. }
  40.  
  41. // If object is PREFAB - reset private defaults
  42. if (!isPlaced) {
  43. ((MapComponent)target).isGenerated = false;
  44.  
  45. }
  46.  
  47. // Get user input
  48. // Received = DisplayValue(Name, oldValue)
  49. cellSize = EditorGUILayout.FloatField("Between cells", cellSize);
  50. width = EditorGUILayout.IntField("Width", width);
  51. height = EditorGUILayout.IntField("Height", height);
  52. ((MapComponent)target).tileBasicPrefab = EditorGUILayout.ObjectField("Node Prefab", ((MapComponent)target).tileBasicPrefab, typeof(GameObject), false) as GameObject;
  53. ((MapComponent)target).tileRoadPrefab = EditorGUILayout.ObjectField("Road Prefab", ((MapComponent)target).tileRoadPrefab, typeof(GameObject), false) as GameObject;
  54.  
  55.  
  56. // Call generation onButton press or onSpawning
  57. bool isJustSpawned = (isPlaced && !isGenerated);
  58. if (GUILayout.Button("Generate") || isJustSpawned) {
  59. Undo.IncrementCurrentGroup();
  60. Undo.RegisterFullObjectHierarchyUndo(((MapComponent)target).gameObject, "Map generated");
  61. ((MapComponent)target).Generate(height, width, cellSize);
  62. EditorUtility.SetDirty(((MapComponent)target).gameObject);
  63. }
  64.  
  65. if (GUILayout.Button("Repair") ) {
  66. Undo.IncrementCurrentGroup();
  67. Undo.RegisterFullObjectHierarchyUndo(((MapComponent)target).gameObject, "Map repaired");
  68. ((MapComponent)target).Repair();
  69. EditorUtility.SetDirty(((MapComponent)target).gameObject);
  70.  
  71. }
  72. }
  73. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(2,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing an assembly reference?
prog.cs(3,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?
prog.cs(7,35): error CS0246: The type or namespace name `Editor' could not be found. Are you missing an assembly reference?
prog.cs(9,10): error CS0246: The type or namespace name `MapComponent' could not be found. Are you missing an assembly reference?
prog.cs(27,23): error CS0115: `MapComponentEditor.OnInspectorGUI()' is marked as an override but no suitable method found to override
Compilation failed: 5 error(s), 0 warnings
stdout
Standard output is empty