fork download
  1. import UnityEditor;
  2. import System.IO;
  3.  
  4. @CustomEditor(Grid)
  5. class TileEditor extends Editor
  6. {
  7. var object : GameObject;
  8. var grid : Grid;
  9. private var threeDOn : boolean = false;
  10. private var threeDOff : boolean = true;
  11.  
  12. function OnEnable()
  13. {
  14. grid = target as Grid;
  15. SceneView.onSceneGUIDelegate = GridUpdate;
  16. }
  17.  
  18. function GridUpdate(sceneView : SceneView)
  19. {
  20. var event : Event = Event.current;
  21. var ray : Ray = Camera.current.ScreenPointToRay(Vector3(event.mousePosition.x,-event.mousePosition.y+Camera.current.pixelHeight));
  22. var mousePos : Vector3 = ray.origin;
  23.  
  24. if(threeDOn)
  25. {
  26. threeDOff = false;
  27. grid.color = Color.cyan;
  28. grid.colorD = Color.red;
  29. }
  30. else if(threeDOff)
  31. {
  32. threeDOn = false;
  33. grid.color = Color(0.5,0.5,0.5,0.5);
  34. grid.colorD = Color.clear;
  35. }
  36.  
  37. if (event.isKey && event.character == 'a')
  38. {
  39. object = Settings.metalTile1;
  40. object = EditorUtility.InstantiatePrefab(object) as GameObject;
  41. var aligned : Vector3 = Vector3((Mathf.Floor(mousePos.x/grid.gridWidth)*grid.gridWidth+grid.gridWidth/2),(Mathf.Floor(mousePos.y/grid.gridHeight)*grid.gridHeight+grid.gridHeight/2),0);
  42. object.transform.position = aligned;
  43. }
  44. else if(event.isKey && event.character == 'd')
  45. {
  46. for (var object : GameObject in Selection.gameObjects)
  47. {
  48. DestroyImmediate(object);
  49. }
  50. }
  51. }
  52.  
  53. function OnInspectorGUI()
  54. {
  55. GUILayout.BeginHorizontal();
  56. GUILayout.Label("Grid with");
  57. grid.gridWidth = EditorGUILayout.FloatField(grid.gridWidth,GUILayout.Width(50));
  58. GUILayout.EndHorizontal();
  59.  
  60. GUILayout.BeginHorizontal();
  61. GUILayout.Label("Grid height");
  62. grid.gridHeight = EditorGUILayout.FloatField(grid.gridHeight,GUILayout.Width(50));
  63. GUILayout.EndHorizontal();
  64.  
  65. GUILayout.BeginHorizontal();
  66. threeDOn = GUILayout.Button("3D-Mode(on)");
  67. threeDOff = GUILayout.Button("3D-Mode(off)");
  68. GUILayout.EndHorizontal();
  69.  
  70. SceneView.RepaintAll();
  71. }
  72.  
  73. }
Runtime error #stdin #stdout 0.27s 213120KB
stdin
Standard input is empty
stdout
Standard output is empty