// Use this for initialization void Start() { for (int i = 0; i < InitialNumberOfKomorkas; i++) { var komorka = Instantiate(komorkaPrefab, new Vector3(Random.Range(-15, 15), Random.Range(0, 14), Random.Range(-2, 2)), Quaternion.identity); var map = ShapeGeneration.CreateRandomShape(); komorka.GetComponent <CellGeneratorController>().Init(map, false, true); } }
// Use this for initialization void Start() { var map = ShapeGeneration.CreateRandomShape(); mutableMesh = new MutableMesh(); SquareGrid grid = new SquareGrid( map.width * ShapeAnalizer.scale, map.height * ShapeAnalizer.scale, mutableMesh ); shapeAnalizer = new ShapeAnalizer(map, grid); var meshFilter = gameObject.GetComponent <MeshFilter> (); Vector3[] vertices = mutableMesh.GetVertexes().ToArray(); float tileAmount = 0.5f; float textureWidth = ShapeAnalizer.scale * map.width; float textureHeight = ShapeAnalizer.scale * map.height; Vector2[] uvs = new Vector2[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { float percentX = Mathf.InverseLerp(0, textureWidth, vertices[i].x) * tileAmount; float percentY = Mathf.InverseLerp(0, textureHeight, vertices[i].y) * tileAmount; uvs[i] = new Vector2(percentX, percentY); } var mesh = new Mesh() { vertices = vertices, triangles = mutableMesh.GetTriangles().ToArray(), uv = uvs, uv2 = uvs, }; mesh.RecalculateTangents(); mesh.RecalculateNormals(); mesh.RecalculateBounds(); meshFilter.sharedMesh = mesh; var renderer = gameObject.GetComponent <MeshRenderer> (); renderer.material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f); var pupil = Instantiate(eyePrefab, shapeAnalizer.eye.center, Quaternion.identity, transform); pupil.transform.localScale = new Vector3(2.0f, 2.0f, 0); shapeAnalizer.eye.SetPupil(pupil, 0.12f); shapeAnalizer.eye.MovePupil(Vector3.zero); }
void GenerateKomorkas() { for (int i = 0; i < Space.Width; i++) { for (int j = 0; j < Space.Height; j++) { for (int z = 0; z < Space.Depth; z++) { if (Random.value < 0.05f) { var komorka = Instantiate(komorkaPrefab, pixelToWorldPosition(new Vec3(i, j, z)), Quaternion.identity); var map = ShapeGeneration.CreateRandomShape(); komorka.GetComponent <CellGeneratorController> ().Init(map, false, false); } } } } }