public void create_obj(EnvAsset asset, Vector3 pos) { EnvObj new_obj = new EnvObj(); new_obj.gobj = GameObject.Instantiate(asset.gobj); float m = Random.Range(0.0f, 1.0f); if (asset == rock && Random.value < .2f) { m = Random.Range(1.5f, 2.0f); } Vector3 scale = (asset.min_scale + ((asset.max_scale - asset.min_scale) * m)) * 2; new_obj.gobj.transform.localScale = scale; pos.y -= 45; new_obj.gobj.transform.position = pos; Vector3 rota = new_obj.gobj.transform.localEulerAngles; rota.y = Random.Range(0, 360); new_obj.gobj.transform.localEulerAngles = rota; spawned_objs.Add(new_obj); }
private void load_asset(ref EnvAsset obj, string name, float spawn_rate, Vector3 min_scale, Vector3 max_scale) { obj = new EnvAsset(); obj.gobj = (GameObject)Resources.Load(name); obj.min_scale = min_scale; obj.max_scale = max_scale; total_spawn_rate += spawn_rate; obj.spawn_rate = total_spawn_rate; assets.Add(obj); }
public void shift_map(float x, float y) { //loop through all vertices in mesh and move by specified x and y //this can be uncommented if need be, but for now moving the map's position works fine vertices = mesh.vertices; for (int i = 0; i < mesh.vertexCount; ++i) { vertices[i].x += x; vertices[i].z += y; } mesh.vertices = vertices; //move map rect x, y by the width/height scale rect.x += rect.width * x; rect.y += rect.height * y; //recalculate mesh bounds with new vertex positions mesh.RecalculateBounds(); offset.x -= (x / mesh.bounds.size.x) * width; offset.z -= (y / mesh.bounds.size.z) * height; foreach (Light light in Light.lights) { light.modified = true; } for (int i = 0; i < Glb.env.spawned_objs.Count; ++i) { Vector3 pos = Glb.env.spawned_objs[i].gobj.transform.position; pos.x -= rect.x; pos.z -= rect.y; if (pos.x < -half_width || pos.x > half_width || pos.z < -half_height || pos.z > half_height) { GameObject.Destroy(Glb.env.spawned_objs[i].gobj); if (Glb.env.spawned_objs[i].light != null) { Glb.env.spawned_objs[i].light.remove(); } Glb.env.spawned_objs.RemoveAt(i); --i; } } Random.seed = (int)((rect.x * 10) + rect.y); int num_env_objs = Random.Range(1, 10); for (int n = 0; n < num_env_objs; ++n) { EnvAsset obj = Glb.env.get_rand_asset(); Vector3 pos = new Vector3((x * half_width) + rect.x + (y * Random.Range(-half_width, half_width)), 0, (y * half_height) + rect.y + (x * Random.Range(-half_height, half_height))); Glb.env.create_obj(obj, pos); } }
public void create_obj(EnvAsset asset, Vector3 pos) { EnvObj new_obj = new EnvObj(); new_obj.gobj = GameObject.Instantiate(asset.gobj); float m = Random.Range(0.0f, 1.0f); if (asset == rock && Random.value < .2f) m = Random.Range(1.5f, 2.0f); Vector3 scale = (asset.min_scale + ((asset.max_scale - asset.min_scale) * m)) * 2; new_obj.gobj.transform.localScale = scale; pos.y -= 45; new_obj.gobj.transform.position = pos; Vector3 rota = new_obj.gobj.transform.localEulerAngles; rota.y = Random.Range(0, 360); new_obj.gobj.transform.localEulerAngles = rota; spawned_objs.Add(new_obj); }