Beispiel #1
0
    public override void OnInspectorGUI()
    {
        HexChunkDisplay display = (HexChunkDisplay)target;

        if (DrawDefaultInspector() && display.AutoUpdate)
        {
            display.CreateMap();
        }
        if (GUILayout.Button("Generate"))
        {
            display.CreateMap();
        }
    }
Beispiel #2
0
    private void CreateChunk(int x, int z)
    {
        bool hasNeighborBelow  = (z > 0);
        bool hasNeighborToLeft = (x > 0);

        GameObject[] allChunks = GameObject.FindGameObjectsWithTag("HexChunk");
        numChunks = allChunks.Length;
        //Debug.Log(numChunks + " existing chunks");
        if ((x * zChunks) + z < numChunks) //don't make a chunk if it already exists
        {
            return;
        }
        GameObject newChunkObject = Instantiate(chunk);

        newChunkObject.tag = "HexChunk";
        HexChunkDisplay newDisplay = newChunkObject.GetComponent <HexChunkDisplay>();
        HexChunk        newChunk   = newDisplay.Chunk;

        chunkDisplays.Add(newDisplay);
        chunks.Add(newChunk);
        newDisplay.OffsetX = x;
        newDisplay.OffsetZ = z;
        chunkMap[x, z]     = newChunk;
        Vector3 tVector = new Vector3(x * HexMetrics.chunkWidth, 0f, z * HexMetrics.chunkHeight);

        //Debug.Log("Translation Vector: " + tVector.x + ", " + tVector.y + ", " + tVector.z);
        tVector += newChunkObject.transform.position;
        //newChunk.Translate(tVector);
        //newChunkObject.transform.position = tVector;
        newChunk.CreateGrid(HexMetrics.chunkSize, HexMetrics.chunkSize);
        //newChunk.CompleteGrid();

        newChunk.Translate(tVector);
        if (x > 0)
        {
            newChunk.AddNeighborChunk(false, chunkMap[x - 1, z]);
        }
        if (z > 0)
        {
            newChunk.AddNeighborChunk(true, chunkMap[x, z - 1]);
        }
        //don't do this until after the edges are stitched
        newDisplay.CreateMap();
    }