Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if UNITY_EDITOR
- using UnityEngine;
- using UnityEditor;
- public class EGenericGrid : EditorWindow
- {
- public GameObject obj;
- [MenuItem("tools/editor grid")]
- public static void ShowEditorGridWind()
- {
- EGenericGrid wind = GetWindow<EGenericGrid>();
- wind.titleContent = new GUIContent("Tool for generic game grid");
- wind.maxSize = new Vector2( 350, 250 );
- wind.minSize = wind.maxSize;
- }
- private GUISkin skin;
- private string verLengthSize = "0";
- private string horLengthSize = "0";
- private string status = "waiting for data input";
- private string pathToPrefab = "debug/ed/tile";
- private string warningMsg = "Change const gridLength in GameGrid.cs";
- private void Awake()
- {
- skin = Resources.Load("debug/ed/edSkin") as GUISkin;
- }
- private void OnGUI()
- {
- GUI.skin = skin;
- GUI.Box(new Rect(25, 10, 300, 40), new GUIContent("Enter data for grid"));
- GUI.Label(new Rect(10, 55, 200, 30), "Enter length grid (vertical)");
- GUI.Label(new Rect(10, 90, 200, 30), "Enter length grid (horizontal)");
- verLengthSize = GUI.TextField(new Rect(230, 55, 100, 30), verLengthSize);
- horLengthSize = GUI.TextField(new Rect(230, 90, 100, 30), horLengthSize);
- GUI.Label(new Rect(25, 125, 300, 30), status);
- if (GUI.Button(new Rect(75, 160, 200, 40), new GUIContent("Generic")))
- {
- int x; int y;
- if (!int.TryParse(verLengthSize, out x) || x <= 0)
- {
- status = "correct input vertical length grid";
- return;
- }
- if (!int.TryParse(horLengthSize, out y) || y <= 0)
- {
- status = "correct input horizontal length grid";
- return;
- }
- status = "start generic";
- genericGrid(x, y);
- }
- GUI.Box(new Rect(25, 205, 300, 40), warningMsg, skin.FindStyle("warning"));
- }
- private void genericGrid(int x, int y)
- {
- if (!System.IO.File.Exists(string.Format("Assets/Resources/{0}{1}", pathToPrefab, ".prefab")))
- {
- status = "no find prefab tile";
- return;
- }
- status = "run process generic";
- GameObject parrObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
- parrObj.name = "grid-game";
- Component[] components = parrObj.GetComponents(typeof(Component));
- foreach (Component comp in components)
- {
- if (comp.GetType() == typeof(Transform))
- continue;
- DestroyImmediate(comp);
- }
- GameObject tile = Resources.Load<GameObject>(pathToPrefab);
- float size = tile.transform.localScale.x;
- for (int i = 0; i < x; i++)
- {
- for (int j = 0; j < y; j++)
- {
- Transform tileObj = Instantiate(tile, new Vector3(0, 0, 0), Quaternion.identity).GetComponent<Transform>();
- tileObj.SetParent(parrObj.transform);
- tileObj.position = new Vector3(-0.5f + (j * size), 0.5f, 0.5f - (i * size));
- tileObj.name = string.Format("tile {0} {1}", i, j);
- tileObj.GetComponent<Tile>().setCord(i, j);
- }
- }
- Debug.LogWarning(warningMsg);
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement