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. private var selectedTile : int = 0;
  12. private var selectedTileStrings : String[] = ["1","2","3","4","5","6","7","8","9"];
  13. private var selectedItem : int = 0;
  14. private var selectedItemStrings : String[] = ["1","2","3","4","5","6"];
  15.  
  16.  
  17.  
  18. function OnEnable()
  19. {
  20. grid = target as Grid;
  21. SceneView.onSceneGUIDelegate = GridUpdate;
  22. }
  23.  
  24. function GridUpdate(sceneView : SceneView)
  25. {
  26. var event : Event = Event.current;
  27. var ray : Ray = Camera.current.ScreenPointToRay(Vector3(event.mousePosition.x,-event.mousePosition.y+Camera.current.pixelHeight));
  28. var mousePos : Vector3 = ray.origin;
  29.  
  30. if(threeDOn)
  31. {
  32. threeDOff = false;
  33. grid.color = Color.cyan;
  34. grid.colorD = Color.red;
  35. }
  36. else if(threeDOff)
  37. {
  38. threeDOn = false;
  39. grid.color = Color(0.5,0.5,0.5,0.5);
  40. grid.colorD = Color.clear;
  41. }
  42.  
  43. if (event.isKey && event.character == 'a')
  44. {
  45. switch(selectedTile)
  46. {
  47. case 0 :
  48. object = Settings.setTile1;
  49. case 1 :
  50. object = Settings.setTile2;
  51. }
  52. object = EditorUtility.InstantiatePrefab(object) as GameObject;
  53. 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);
  54. object.transform.position = aligned;
  55. }
  56. else if(event.isKey&&event.character == 'w')
  57. {
  58. switch(selectedItem)
  59. {
  60. case 0 :
  61. object = Settings.setItem1;
  62. case 1 :
  63. object = Settings.setItem2;
  64. }
  65. object = EditorUtility.InstantiatePrefab(object) as GameObject;
  66. var unAligned : Vector3 = Vector3(mousePos.x,mousePos.y,0);
  67. object.transform.position = unAligned;
  68. }
  69. else if(event.isKey && event.character == 'd')
  70. {
  71. for (var object : GameObject in Selection.gameObjects)
  72. {
  73. DestroyImmediate(object);
  74. }
  75. }
  76. }
  77.  
  78. function OnInspectorGUI()
  79. {
  80. GUILayout.BeginHorizontal();
  81. GUILayout.Label("Grid with");
  82. grid.gridWidth = EditorGUILayout.FloatField(grid.gridWidth,GUILayout.Width(50));
  83. GUILayout.EndHorizontal();
  84.  
  85. GUILayout.BeginHorizontal();
  86. GUILayout.Label("Grid height");
  87. grid.gridHeight = EditorGUILayout.FloatField(grid.gridHeight,GUILayout.Width(50));
  88. GUILayout.EndHorizontal();
  89.  
  90. GUILayout.BeginHorizontal();
  91. threeDOn = GUILayout.Button("3D-Mode(on)");
  92. threeDOff = GUILayout.Button("3D-Mode(off)");
  93. GUILayout.EndHorizontal();
  94.  
  95. GUILayout.Space(75);
  96. GUILayout.Label("Tiles");
  97.  
  98. GUILayout.BeginHorizontal();
  99. selectedTile = GUILayout.SelectionGrid(selectedTile,selectedTileStrings,3);
  100. GUILayout.EndHorizontal();
  101.  
  102. GUILayout.Space(25);
  103. GUILayout.Label("Items");
  104.  
  105. GUILayout.BeginHorizontal();
  106. selectedItem = GUILayout.SelectionGrid(selectedItem,selectedItemStrings,3);
  107. GUILayout.EndHorizontal();
  108.  
  109. SceneView.RepaintAll();
  110. }
  111.  
  112. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty