public TerrainChunk(Vector2 coord, HightMapSettings hightMapSettings, MeshSettings meshSettings, float size, LODInfo[] lodInfo, int colliderMeshIndex, Transform parent, Material material)
        {
            this.coord             = coord;
            this.hightMapSettings  = hightMapSettings;
            this.meshSettings      = meshSettings;
            this.lodInfo           = lodInfo;
            this.colliderMeshIndex = colliderMeshIndex;



            position = coord * size / meshSettings.uniformScale;
            Vector2 center = coord * size;

            bounds = new Bounds(position, Vector2.one * size);

            Vector3 position3D = new Vector3(position.x, 0, position.y);

            meshObj               = new GameObject("Chunk");
            meshRenderer          = meshObj.AddComponent <MeshRenderer>();
            meshFilter            = meshObj.AddComponent <MeshFilter>();
            meshCollider          = meshObj.AddComponent <MeshCollider>();
            meshRenderer.material = material;

            meshObj.transform.position   = position3D * scale;
            meshObj.transform.parent     = parent;
            meshObj.transform.localScale = Vector3.one * scale;
            SetVisible(false);

            lodMeshes = new LODMesh[lodInfo.Length];
            for (int i = 0; i < lodInfo.Length; i++)
            {
                lodMeshes[i] = new LODMesh(lodInfo[i].lod);
                lodMeshes[i].updateCalback += UpdateChunk;
                if (i == colliderMeshIndex)
                {
                    lodMeshes[i].updateCalback += UpdateColissionMesh;
                }
            }

            TreadedDataRequest.RequestData(() => hightMapGenerator.GenHightMap(meshSettings, hightMapSettings, center), OnMapDataRecive);
        }
Esempio n. 2
0
 private void Awake()
 {
     instance = FindObjectOfType <TreadedDataRequest>() as TreadedDataRequest;
     display  = FindObjectOfType <display>() as display;
 }
        public void RequsetMesh(HightMap map, MeshSettings mSettings)
        {
            hasRequsetMesh = true;

            TreadedDataRequest.RequestData(() => mechDraw.GenerateMech(map.value, mSettings, lod), OnMeshDataRecive);
        }