Esempio n. 1
0
        private void OnGUI()
        {
            GUILayout.Label('\n' + "Left mouse button creates tiles snapped to the grid." + '\n' + "Right mouse button deletes tiles in selected parent" + '\n' +
                            "If no parent is given then this tool creates one instead." + '\n' + "WARNING: " + '\n' + "Do not run the game when tool is active! " + '\n' + "It will lose connection to the GridDisplayer" + '\n');

            tileObject   = EditorGUILayout.ObjectField("Prefab Tile", tileObject, typeof(SpriteRenderer), false) as SpriteRenderer;
            tileSprite   = EditorGUILayout.ObjectField("Tile Sprite", tileSprite, typeof(Sprite), false) as Sprite;
            parentObject = EditorGUILayout.ObjectField("Parent for Tile", parentObject, typeof(Transform), true) as Transform;

            if (gridDisplay != null)
            {
                gridDisplay.GridColor  = EditorGUILayout.ColorField("Grid Color", gridDisplay.GridColor);
                gridDisplay.TilePrefab = tileObject;
                gridDisplay.TileArt    = tileSprite;

                if (tileObject != null)
                {
                    gridDisplay.SizeX = tileObject.bounds.size.x;
                    gridDisplay.SizeY = tileObject.bounds.size.y;
                }
                else
                {
                    gridDisplay.SizeX = 1;
                    gridDisplay.SizeY = 1;
                }
            }

            if (GUILayout.Button((gridDisplay == null ? "Activate" : "Deactivate")))
            {
                SceneView.onSceneGUIDelegate -= OnSceneGUI;
                if (gridDisplay != null)
                {
                    DestroyGridDisplay();
                }
                else
                {
                    GameObject g = new GameObject("{GridDisplayer}(Editor Object)");
                    gridDisplay = g.AddComponent <GridDisplay>();
                    SceneView.onSceneGUIDelegate += OnSceneGUI;
                }
            }
        }
Esempio n. 2
0
 private void DestroyGridDisplay()
 {
     SceneView.onSceneGUIDelegate -= OnSceneGUI;
     GameObject.DestroyImmediate(gridDisplay.gameObject);
     gridDisplay = null;
 }