private void OnDeleteSaveGame()
 {
     //Reset data
     m_WidthInputField.text          = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_WIDTH, 5).ToString();
     m_HeightInputField.text         = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_HEIGHT, 5).ToString();
     m_TextCharactersInputField.text = SaveGameManager.GetString(SaveGameManager.SAVE_LEVEL_TEXTCHARACTERS, "sdfghjkl");
     m_SeedInputField.text           = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_SEED, -1).ToString();
 }
    public void Show()
    {
        if (m_CanvasGroup != null)
        {
            m_CanvasGroup.Show();
        }

        if (LevelDirector.Instance != null)
        {
            LevelDirector.Instance.AddInputBlocker();
        }

        if (m_GenerateButton != null)
        {
            StartCoroutine(SelectButtonRoutine());
        }

        //Load all the save game data
        m_WidthInputField.text          = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_WIDTH, 5).ToString();
        m_HeightInputField.text         = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_HEIGHT, 5).ToString();
        m_TextCharactersInputField.text = SaveGameManager.GetString(SaveGameManager.SAVE_LEVEL_TEXTCHARACTERS, "sdfghjkl");
        m_SeedInputField.text           = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_SEED, -1).ToString();
    }
    private IEnumerator GenerateLevelFromGridRoutine()
    {
        //Temp, wait one frame so everyone has the time to do subscribe etc before a level actually get's generated
        yield return(new WaitForEndOfFrame());

        //Get data
        int width  = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_WIDTH, 5);
        int height = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_HEIGHT, 5);
        int seed   = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_SEED, -1);

        if (seed == -1)
        {
            UnityEngine.Random.InitState(System.Environment.TickCount); //Random enough?
        }
        else
        {
            UnityEngine.Random.InitState(seed);
        }

        //Clear Level if needed
        if (m_Nodes == null)
        {
            m_Nodes = new List <Node>();
        }
        else
        {
            ClearLevel();
        }

        //Create all the nodes
        for (int i = 0; i < width * height; ++i)
        {
            int x = (i % width);
            int y = (i / width);

            Node newNode = GameObject.Instantiate <Node>(m_NodePrefab);

            newNode.name                    = "Node (" + x + ", " + y + ")";
            newNode.transform.parent        = transform;
            newNode.transform.localPosition = new Vector3(x * m_TileSize, -y * m_TileSize, 0.0f); //0, 0 in the top left

            m_Nodes.Add(newNode);
        }

        //Link all the nodes
        for (int i = 0; i < m_Nodes.Count; ++i)
        {
            Node currentNode = m_Nodes[i];

            int x = (i % width);
            int y = (i / width);

            //Assign right neighbour (and assign their left to us)
            if (x >= 0 && x < width - 1)
            {
                Node rightNeighbour = m_Nodes[i + 1];
                currentNode.SetNeighbour(Direction.East, rightNeighbour);
                rightNeighbour.SetNeighbour(Direction.West, currentNode);
            }

            //Assign bottom neighbour (and assign their top to us)
            if (y >= 0 && y < height - 1)
            {
                Node bottomNeighbour = m_Nodes[i + width];
                currentNode.SetNeighbour(Direction.South, bottomNeighbour);
                bottomNeighbour.SetNeighbour(Direction.North, currentNode);
            }
        }

        //Assign node characters
        AssignNodeTextCharacters(seed);

        //Assign start node
        List <int> quadrants = new List <int> {
            0, 1, 2, 3
        };

        int randStartQuadrant = UnityEngine.Random.Range(0, quadrants.Count);

        m_StartNode = GetRandomNodeInQuadrant(width, height, quadrants[randStartQuadrant]);

        //Assign end node
        quadrants.Remove(randStartQuadrant); //Make sure the end quadrant is not the same as the start one

        int randEndQuadrant = UnityEngine.Random.Range(0, quadrants.Count);

        m_EndNode = GetRandomNodeInQuadrant(width, height, quadrants[randEndQuadrant]);
        m_EndNode.SetExit(true); //Visualize

        //Calculcate the collider bounds (so the camera doesn't go out of bounds)
        if (m_CameraCollider != null)
        {
            Vector3 topLeft     = m_Nodes[0].transform.localPosition;
            Vector3 topRight    = m_Nodes[width - 1].transform.localPosition;
            Vector3 bottomLeft  = m_Nodes[(height * width) - width].transform.localPosition;
            Vector3 bottomRight = m_Nodes[(height * width) - 1].transform.localPosition;

            Vector2[] colliderPath = new Vector2[4];
            colliderPath[0] = new Vector2(topLeft.x - (m_TileSize * 0.5f), topLeft.y + (m_TileSize * 0.5f));
            colliderPath[1] = new Vector2(topRight.x + (m_TileSize * 0.5f), topRight.y + (m_TileSize * 0.5f));
            colliderPath[2] = new Vector2(bottomRight.x + (m_TileSize * 0.5f), bottomRight.y - (m_TileSize * 0.5f));
            colliderPath[3] = new Vector2(bottomLeft.x - (m_TileSize * 0.5f), bottomLeft.y - (m_TileSize * 0.5f));

            m_CameraCollider.SetPath(0, colliderPath);

            //Set ourselves to the center
            Vector3 total = topLeft + topRight + bottomLeft + bottomRight;
            transform.position = new Vector3(-total.x / 4.0f, -total.y / 4.0f, 0.0f);
        }

        //Let the world know!
        if (LevelGeneratedEvent != null)
        {
            LevelGeneratedEvent();
        }

        m_CurrentRoutine = null;

        yield return(null);
    }