예제 #1
0
    /// <summary>
    /// Attach each mesh of the chunk to a GameObject
    /// </summary>
    /// <param name="chunk">the chunk</param>
    public void RenderChunk(WorldChunk chunk)
    {
        if (chunk.GameObjects != null && chunk.GameObjects.Length != 0)
        {
            for (int i = 0; i < chunk.GameObjects.Length; i++)
            {
                chunk.GameObjects[i].SetActive(false);
            }
        }


        List <GameObject> GOs = new List <GameObject>();

        Vector3 goPosition = chunk.GetGlobalPosition();

        for (int i = 0; i < chunk.MeshData.Length; i++)
        {
            GameObject go = _Pool.NextObject();

            if (go == null)
            {
                Debug.LogError("Pool has no GameObject available");
                break;
            }
            AttachMesh(go, chunk, chunk.MeshData[i]);

            go.transform.position = goPosition;
            GOs.Add(go);
        }

        chunk.GameObjects = GOs.ToArray();
    }