public void Setup(string name, PlanetSquare squareTemplate, int size, float orbitDist, float orbitAlpha, float gravIntensity, float atmDensity, int atmPercentRange, int heightPercentRange) { this.name = name; this.planetName = name; this.maxSubDegree = size; this.squareTemplate = squareTemplate.gameObject; MaterialPosition matPos = this.GetComponent <MaterialPosition> (); matPos.TargetMat = this.squareTemplate.GetComponent <Renderer> ().sharedMaterial; StellarObject sO = this.GetComponent <StellarObject> (); sO.truePos = Quaternion.AngleAxis(orbitAlpha, Vector3.up) * Vector3.forward * (orbitDist); this.gravIntensity = gravIntensity; this.atmDensity = atmDensity; this.atmRangePerCent = atmPercentRange; this.heightRangePerCent = heightPercentRange; }
public void Add(PlanetSquare ps, float priority) { for (int i = 0; i < BufferKVP.Count; i++) { if (BufferKVP [i].Key > priority) { BufferKVP.Insert (i, new KeyValuePair<float, PlanetSquare> (priority, ps)); return; } } BufferKVP.Add (new KeyValuePair<float, PlanetSquare> (priority, ps)); }
public void Add(PlanetSquare ps, float priority) { for (int i = 0; i < BufferKVP.Count; i++) { if (BufferKVP [i].Key > priority) { BufferKVP.Insert(i, new KeyValuePair <float, PlanetSquare> (priority, ps)); return; } } BufferKVP.Add(new KeyValuePair <float, PlanetSquare> (priority, ps)); }
public void Update() { while (BufferKVP.Count > 0) { PlanetSquare ps = BufferKVP [BufferKVP.Count - 1].Value; BufferKVP.RemoveAt(BufferKVP.Count - 1); if (ps != null) { ps.Initialize(); return; } } }
public PlanetSquare AddChildPlanetSquare(int iPos, int jPos, int kPos) { GameObject g = GameObject.Instantiate <GameObject> (this.squareTemplate); g.transform.parent = this.transform; g.transform.localPosition = Vector3.zero; g.transform.localRotation = Quaternion.identity; PlanetSquare ps = g.GetComponent <PlanetSquare> (); ps.subDegree = 0; ps.parent = null; ps.planet = this; ps.iPos = iPos; ps.jPos = jPos; ps.kPos = kPos; ps.name = "Square " + ps.subDegree + "." + ps.iPos + ":" + ps.jPos + ":" + ps.kPos; return(ps); }
public void GenerateRandom() { List <string> randomNames = new List <string> (); randomNames.Add("Alpha"); randomNames.Add("Beta"); randomNames.Add("Gamma"); randomNames.Add("Delta"); randomNames.Add("Epsilon"); randomNames.Add("Zeta"); randomNames.Add("Eta"); randomNames.Add("Theta"); randomNames.Add("Iota"); randomNames.Add("Kappa"); randomNames.Add("Lambda"); randomNames.Add("Mu"); randomNames.Add("Nu"); randomNames.Add("Ksi"); randomNames.Add("Omicron"); randomNames.Add("Pi"); randomNames.Add("Rho"); randomNames.Add("Sigma"); randomNames.Add("Tau"); randomNames.Add("Upsilon"); randomNames.Add("Phi"); randomNames.Add("Khi"); randomNames.Add("Psi"); randomNames.Add("Omega"); this.randomizer = null; this.squarePoll = null; List <PlanetSquare> tmpPoll = new List <PlanetSquare> (this.SquarePoll); for (int i = 1; i <= 10; i++) { if ((this.Randomizer.Rand(i) / 2f + 0.5f) < this.planetRate) { Planet p = GameObject.Instantiate <Planet> (this.PlanetTemplate); int nameIndex = Mathf.FloorToInt(Mathf.Abs(this.Randomizer.Rand(4 * i) * tmpPoll.Count * 42)) % randomNames.Count; string planetName = randomNames [nameIndex]; randomNames.RemoveAt(nameIndex); int size = Mathf.RoundToInt(7.5f + 1.5f * this.Randomizer.Rand(5 * i)); int pollIndex = Mathf.FloorToInt(Mathf.Abs(this.Randomizer.Rand(2 * i) * tmpPoll.Count * 42)) % tmpPoll.Count; PlanetSquare sTemplate = tmpPoll [pollIndex]; tmpPoll.Remove(sTemplate); float orbitAlpha = (this.Randomizer.Rand(3 * i) + 1) * 180f; float orbitDist = i * 50000f; int heightRangePercent = Mathf.RoundToInt(10f + 5f * this.Randomizer.Rand(6 * i)); float atmDensity = 1f + 1f * this.Randomizer.Rand(7 * i); int atmRangePercent = Mathf.RoundToInt(20f + 10f * this.Randomizer.Rand(8 * i)); float gravIntensity = 10f + (size - 6) * 5 + 4f * this.Randomizer.Rand(9 * i); gravIntensity = Mathf.Max(gravIntensity, 1f); p.Setup(planetName, sTemplate, size, orbitDist, orbitAlpha, gravIntensity, atmDensity, atmRangePercent, heightRangePercent); p.Initialize(); } } }
public void Subdivide(bool usePlanetManager, float priority) { if (this.childDepth != 0) { return; } if (this.subDegree == this.planet.maxSubDegree) { return; } this.childDepth = 1; if (this.parent != null) { this.parent.childDepth = 2; } this.children = new PlanetSquare [4]; for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { GameObject g = GameObject.Instantiate <GameObject> (this.planet.squareTemplate); g.transform.parent = this.transform; g.transform.localPosition = Vector3.zero; g.transform.localRotation = Quaternion.identity; g.transform.localScale = Vector3.one; PlanetSquare ps = g.GetComponent <PlanetSquare> (); ps.subDegree = this.subDegree + 1; if ((this.kPos == 0) || (this.kPos == this.indexSize)) { ps.iPos = 2 * this.iPos - a; ps.jPos = 2 * this.jPos - b; ps.kPos = this.kPos; if (ps.kPos != 0) { ps.kPos = Mathf.FloorToInt(Mathf.Pow(2f, ps.subDegree)) + 1; } } else if ((this.jPos == 0) || (this.jPos == this.indexSize)) { ps.iPos = 2 * this.iPos - a; ps.jPos = this.jPos; if (ps.jPos != 0) { ps.jPos = Mathf.FloorToInt(Mathf.Pow(2f, ps.subDegree)) + 1; } ps.kPos = 2 * this.kPos - b; } else if ((this.iPos == 0) || (this.iPos == this.indexSize)) { ps.iPos = this.iPos; if (ps.iPos != 0) { ps.iPos = Mathf.FloorToInt(Mathf.Pow(2f, ps.subDegree)) + 1; } ps.jPos = 2 * this.jPos - b; ps.kPos = 2 * this.kPos - a; } ps.parent = this; ps.planet = this.planet; this.children [b + 2 * a] = ps; ps.name = "Square " + ps.subDegree + "." + ps.iPos + ":" + ps.jPos + ":" + ps.kPos; if (usePlanetManager) { StellarSystem.Manager.Add(ps, priority); } else { ps.Initialize(); } } } }
public void Setup(string name, PlanetSquare squareTemplate, int size, float orbitDist, float orbitAlpha, float gravIntensity, float atmDensity, int atmPercentRange, int heightPercentRange) { this.name = name; this.planetName = name; this.maxSubDegree = size; this.squareTemplate = squareTemplate.gameObject; MaterialPosition matPos = this.GetComponent<MaterialPosition> (); matPos.TargetMat = this.squareTemplate.GetComponent<Renderer> ().sharedMaterial; StellarObject sO = this.GetComponent <StellarObject> (); sO.truePos = Quaternion.AngleAxis (orbitAlpha, Vector3.up) * Vector3.forward * (orbitDist); this.gravIntensity = gravIntensity; this.atmDensity = atmDensity; this.atmRangePerCent = atmPercentRange; this.heightRangePerCent = heightPercentRange; }