Exemple #1
0
        public void Init(MapMesh owner, GameObject root, Vector2Int chunkSize)
        {
            Owner     = owner;
            ChunkSize = chunkSize;

            if (wallDefinition != null)
            {
                Wall = Instantiate(wallDefinition) as MapWallMesh;
                Wall.Init(root, ChunkSize);
            }

            GameObject surfaceRoot = new GameObject(name + " - Surface Mesh");

            surfaceRoot.transform.SetParent(root.transform);

            meshRenderer = surfaceRoot.GetOrAddComponent <MeshRenderer>();
            meshFilter   = surfaceRoot.GetOrAddComponent <MeshFilter>();
            meshCollider = surfaceRoot.GetOrAddComponent <MeshCollider>();

            meshFilter.mesh = mesh = new Mesh();
            mesh.name       = surfaceRoot.name;
            vertices        = new List <Vector3>();
            triangles       = new List <int>();
            normals         = new Vector3[0];
            vertHasWall     = new Dictionary <int, int>();

            rowCacheMax = new int[ChunkSize.x * 2 + 1];
            rowCacheMin = new int[ChunkSize.x * 2 + 1];

            mapBounds = new Bounds();
            mapBounds.SetMinMax(Owner.worldPos, new Vector3(ChunkSize.x, innerHeight + 100f, ChunkSize.y));
        }
Exemple #2
0
        void CreateChunk(Vector2Int chunkIndex)
        {
            MapMesh chunk = Instantiate(chunkDefinition) as MapMesh;

            chunk.name = "Chunk " + chunks.Count + " " + chunkIndex;
            GameObject chunkRoot = new GameObject(chunk.name + " root");

            chunkRoot.transform.SetParent(transform);
            chunk.Init(CreateChunkMap(chunkIndex), chunkRoot, ChunkSize, chunkIndex, mapScale);
            chunks.Add(chunk);
            chunkViews.Add(chunkRoot);


            if (chunkIndex.x > 0)
            {
                this[chunkIndex.x - 1, chunkIndex.y].xNeighbor = chunk;
            }
            if (chunkIndex.y > 0)
            {
                this[chunkIndex.x, chunkIndex.y - 1].yNeighbor = chunk;
                if (chunkIndex.x > 0)
                {
                    this[chunkIndex.x - 1, chunkIndex.y - 1].xyNeighbor = chunk;
                }
            }
        }