public static GameObject CreateStar(Vector3 _position, int _seed, StarType _starType) { GameObject starObject = new GameObject("Star"); starObject.transform.position = _position; //planetObject.transform.parent = transform; //newPlanet.AddComponent<Planet> (); int size = Random.Range(20, 30); starObject.transform.localScale = new Vector3(size, size, size); /// planet = newPlanet.GetComponent<Planet> (); int pixWidth = 256; int pixHeight = 256; int scale = 6; float xOrg = 0; float yOrg = 0; //planetMesh = SolarBodyGeneration.GetSphereMesh (); starObject.AddComponent <MeshFilter> ().mesh = SolarBodyGeneration.GetSphereMesh(); MeshRenderer mr = starObject.AddComponent <MeshRenderer> (); //StarType st = (StarType)Random.Range (0, 6); mr.material.mainTexture = Noise.CalculateSeamlessNoise(pixWidth, pixHeight, scale, xOrg, yOrg, _seed, StarColour.GetStarColour(_starType)); mr.material.EnableKeyword("_EMISSION"); mr.material.SetTexture("_EmissionMap", Noise.CalculateSeamlessNoise(pixWidth, pixHeight, scale, xOrg, yOrg, _seed, StarColour.GetStarColour(_starType))); mr.material.SetColor("_EmissionColor", Color.white); return(starObject); }
//public int numberOfSystems; public static GameObject CreateGalaxy(out StarSystem[] starSystem, int numberOfSystems) { GameObject newGalaxy = new GameObject("Galaxy"); starSystem = new StarSystem[numberOfSystems]; for (int i = 0; i < starSystem.Length; i++) { int[] ae = new int[Random.Range(0, 3)]; for (int e = 0; e < ae.Length; e++) { ae [e] = Random.Range(0, 3); } bool me = false; if (i < 10) { me = true; } bool t = false; if (Random.Range(0, 100) < 50) { t = true; } bool ro = false; if (Random.Range(0, 100) < 50) { ro = true; } starSystem [i] = new StarSystem(Random.Range(0, 10000000), ae, me, t, ro); GameObject newSystemPoint = new GameObject("SystemPoint"); newSystemPoint.transform.parent = newGalaxy.transform; newSystemPoint.transform.position = new Vector3((20 * (i)), 0, 0); newSystemPoint.transform.localScale = new Vector3(4, 4, 4); newSystemPoint.AddComponent <MeshFilter> ().mesh = SolarBodyGeneration.GetSphereMesh(); MeshRenderer mr = newSystemPoint.AddComponent <MeshRenderer> (); newSystemPoint.AddComponent <SphereCollider> ().radius = 1; newSystemPoint.AddComponent <SystemPoint> ().SetStarSystem(i); newSystemPoint.tag = "SystemPoint"; int pixWidth = 16; int pixHeight = 16; int scale = 1; float xOrg = 0; float yOrg = 0; StarType st = StarSystemGenerator.GetStarSystemInfo(starSystem[i].seed).starType; mr.material.mainTexture = Noise.CalculateSeamlessNoise(pixWidth, pixHeight, scale, xOrg, yOrg, starSystem[i].seed, StarColour.GetStarColour(st)); mr.material.EnableKeyword("_EMISSION"); mr.material.SetTexture("_EmissionMap", Noise.CalculateSeamlessNoise(pixWidth, pixHeight, scale, xOrg, yOrg, starSystem[i].seed, StarColour.GetStarColour(st))); mr.material.SetColor("_EmissionColor", new Color(0.5f, 0.5f, 0.5f)); } return(newGalaxy); }