public void Kill(Module toKill) { toKill.dead = true; }
protected void AssignPrevious(Module next, Module previous) { next.previous = previous; }
protected void SetPrefabIdentifier(Module module) { module.prefabIdentifier = gameObject.name; }
public override void Bake(ParameterBundle bundle) { if (dead) { return; } Quaternion rotation; if (!bundle.Get("Rotation", out rotation)) { //TODO: used to be Vector3.up. Equivelent? rotation = Quaternion.identity; } Vector3 position = transform.position; Transform parent = null; if (previous != null) { position = previous.transform.position; parent = previous.transform; } Quaternion bakedRot = Quaternion.Euler(UnityEngine.Random.Range(bakedRotationMin.x, bakedRotationMax.x), UnityEngine.Random.Range(bakedRotationMin.y, bakedRotationMax.y), UnityEngine.Random.Range(bakedRotationMin.z, bakedRotationMax.z)); float s = UnityEngine.Random.Range(bakedScaleMin, bakedScaleMax); Vector3 scale = new Vector3(s, s, s); // try get existing instance GameObject prototypeInstance; GameObject instance; if (bakedProtoypes.TryGetValue(prefabIdentifier, out prototypeInstance)) { if (parent == null) { parent = transform; } instance = (GameObject)Instantiate(prototypeInstance, position, bakedRot, parent); instance.transform.localScale = scale; instance.name = "Instance_" + prefabIdentifier; instance.transform.rotation = rotation; instance.SetActive(true); if (bakedScaleOnSpawn) { StartCoroutine(BakedScale(instance)); } } else { //TODO: This could be done off-line. AnyExecute(bundle); //bake transform.position = Vector3.zero; transform.rotation = Quaternion.identity; transform.parent = null; // The current object contains the original mesh data so it needs to become the prototypical instance. we create a copy of it to continue. instance = (GameObject)Instantiate(gameObject, position, rotation, parent); instance.transform.localScale = scale; instance.name = "InitialInstance_" + prefabIdentifier; if (bakedScaleOnSpawn) { StartCoroutine(BakedScale(instance)); } //Kill initial instance module since its already generated. Module initialInstanceModule = instance.GetComponent <Module>(); if (initialInstanceModule != null) { Kill(initialInstanceModule); } gameObject.name = "Prototype_" + prefabIdentifier; Kill(this); //the prototype must not be able to create new instances(they will do the same... etc) gameObject.hideFlags = HideFlags.HideInHierarchy; bakedProtoypes.Add(prefabIdentifier, gameObject); gameObject.SetActive(false); } }