// Update is called once per frame void Update() { int xMove = (int)(player.transform.position.x - startPos.x); int zMove = (int)(player.transform.position.z - startPos.z); if (Mathf.Abs(xMove) >= foamSize || Mathf.Abs(zMove) >= foamSize) { float updateTime = Time.realtimeSinceStartup; int playerX = (int)(Mathf.Floor(player.transform.position.x / foamSize) * foamSize); int playerZ = (int)(Mathf.Floor(player.transform.position.z / foamSize) * foamSize); for (int x = -halfPlanesX; x < halfPlanesX; x++) { for (int z = -halfPlanesZ; z < halfPlanesZ; z++) { Vector3 pos = new Vector3((x * foamSize + playerX), this.gameObject.transform.position.y, (z * foamSize + playerZ)); string planeName = "PLane_" + ((int)(pos.x)).ToString() + "_" + ((int)(pos.z)).ToString(); if (!planes.ContainsKey(planeName)) { GameObject p = (GameObject)Instantiate(foam, pos, Quaternion.identity); p.name = planeName; Foam plane = new Foam(p, updateTime); planes.Add(planeName, plane); } else { (planes[planeName] as Foam).creationTime = updateTime; } } } // Destroy all planes that have outdated timestamps // Put valid planes in a hashtable Hashtable newFoam = new Hashtable(); foreach (Foam pl in planes.Values) { if (pl.creationTime != updateTime) { // Delete plane Destroy(pl.plane); } else { newFoam.Add(pl.plane.name, pl); } } // Copy new hashtable contents to the working hashtable planes = newFoam; startPos = player.transform.position; } }
public string[] GetFoamNames(string term) { List <Foam> foams = Foam.Read(term); string[] foamNames = new string[foams.Count]; for (int i = 0; i < foams.Count; i++) { foamNames[i] = foams[i].FoamName; } return(foamNames); }
public WaterGenerator(byte[] options, bool applyFixes = false) { this.waveshape = (Waveshape)options[0]; this.watercolor = (Watercolor)options[1]; this.reflection = (Reflection)options[2]; this.refraction = (Refraction)options[3]; this.bankalpha = (Bankalpha)options[4]; this.appearance = (Appearance)options[5]; this.global_shape = (Global_Shape)options[6]; this.foam = (Foam)options[7]; this.reach_compatibility = options.Length > 8 ? (Reach_Compatibility)options[8] : Reach_Compatibility.Disabled; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
public WaterGenerator(Waveshape waveshape, Watercolor watercolor, Reflection reflection, Refraction refraction, Bankalpha bankalpha, Appearance appearance, Global_Shape global_shape, Foam foam, Reach_Compatibility reach_compatibility, bool applyFixes = false) { this.waveshape = waveshape; this.watercolor = watercolor; this.reflection = reflection; this.refraction = refraction; this.bankalpha = bankalpha; this.appearance = appearance; this.global_shape = global_shape; this.foam = foam; this.reach_compatibility = reach_compatibility; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
// Start is called before the first frame update private void Start() { //this.gameObject.transform.position = Vector3.zero; startPos = Vector3.zero; // Timestamp each newly created plane or update the timestamp // of a plane that's still in range float updateTime = Time.realtimeSinceStartup; for (int x = -halfPlanesX; x < halfPlanesX; x++) { for (int z = -halfPlanesZ; z < halfPlanesZ; z++) { Vector3 pos = new Vector3((x * foamSize + startPos.x), this.gameObject.transform.position.y, (z * foamSize + startPos.z)); GameObject p = (GameObject)Instantiate(foam, pos, Quaternion.identity); string planeName = "PLane_" + ((int)(pos.x)).ToString() + "_" + ((int)(pos.z)).ToString(); p.name = planeName; Foam plane = new Foam(p, updateTime); planes.Add(planeName, plane); } } }