override protected Constellation Construct(ConstellationManifest conMf) { Constellation con; if (constellations.TryGetValue(conMf.position, out con)) { return(con); } con = Instantiate(constellationPrefab) as Constellation; if (con == null) { return(null); } con.Manifest = conMf; con.transform.localPosition = conMf.position; // foreach (var starMf in conMf.stars) { // MapStar starPf = game.GetMapStarPrefab(starMf.color); // MapStar star = Instantiate(starPf) as MapStar; // star.manifest = starMf; // star.constellation = con; // con.stars.Add(star); // } constellations.Add(con.Manifest.position, con); return(con); }
protected override Constellation Construct(ConstellationManifest conMf) { Constellation con; if (constellations.TryGetValue(conMf.position, out con)) { return con; } con = Instantiate(constellationPrefab) as MapConstellation; con.Manifest = conMf; con.transform.localPosition = conMf.position; // stars foreach (var starMf in conMf.stars) { MapStar starPf = game.GetMapStarPrefab(starMf.color); MapStar star = Instantiate(starPf) as MapStar; star.manifest = starMf; star.constellation = con; con.Stars.Add(star); // universeBounds.Encapsulate(con.transform.position + starMf.position); } // Fleet foreach (var shipMf in conMf.fleet) { FleetShip shipPf = game.GetFleetShipPrefab(shipMf); FleetShip ship = Instantiate(shipPf) as FleetShip; ship.transform.parent = con.transform; ship.transform.localPosition = shipMf.position; ship.transform.localScale = new Vector3(3f, 3f, 3f); ship.manifest = shipMf; con.Fleet.Add(ship); } constellations.Add(con.Manifest.position, con); return con; }
private bool StarRequirements(ConstellationManifest constellation, StarManifest star) { foreach (var st in constellation.stars) { float dist = Vector3.Distance(st.position, star.position); if (minStarGap > dist) { return(false); } } return(true); }
public ConstellationManifest GenerateConstellation(Vector3 normalizedPos) { ConstellationManifest constellation = new ConstellationManifest(); // position constellation.position = normalizedPos; constellation.bounds = new Bounds(constellation.position, new Vector3(constellationSize, constellationSize, 1f)); // set seed int origSeed = UnityEngine.Random.seed; UnityEngine.Random.seed = randomSeed + (int)(constellation.position.x / constellationSize) + (int)(constellation.position.y / constellationSize) * 100000; // stars constellation.stars = new List <StarManifest>(); int starCount = UnityEngine.Random.Range(minStars, maxStars); for (int i = 0; i < starCount; i++) { StarManifest star = GenerateStar(); do { star.position = new Vector3( UnityEngine.Random.Range(-constellationSize / 2f + minStarGap, constellationSize / 2f - minStarGap), UnityEngine.Random.Range(-constellationSize / 2f + minStarGap, constellationSize / 2f - minStarGap) ); }while (!StarRequirements(constellation, star)); star.index = i; constellation.stars.Add(star); } // Fleet constellation.fleet = new List <FleetShipManifest>(); int fleetShipCount = UnityEngine.Random.Range(1, 4); for (int i = 0; i < fleetShipCount; i++) { constellation.fleet.Add(GenerateFleetShip()); } // restore previous seed UnityEngine.Random.seed = origSeed; return(constellation); }
public ConstellationManifest GenerateConstellation(Vector3 normalizedPos) { ConstellationManifest constellation = new ConstellationManifest(); // position constellation.position = normalizedPos; constellation.bounds = new Bounds(constellation.position, new Vector3(constellationSize, constellationSize, 1f)); // set seed int origSeed = UnityEngine.Random.seed; UnityEngine.Random.seed = randomSeed + (int)(constellation.position.x / constellationSize) + (int)(constellation.position.y / constellationSize) * 100000; // stars constellation.stars = new List<StarManifest>(); int starCount = UnityEngine.Random.Range(minStars, maxStars); for (int i = 0 ; i < starCount ; i++) { StarManifest star = GenerateStar(); do { star.position = new Vector3( UnityEngine.Random.Range(-constellationSize / 2f + minStarGap, constellationSize / 2f - minStarGap), UnityEngine.Random.Range(-constellationSize / 2f + minStarGap, constellationSize / 2f - minStarGap) ); } while (!StarRequirements(constellation, star)); star.index = i; constellation.stars.Add(star); } // Fleet constellation.fleet = new List<FleetShipManifest>(); int fleetShipCount = UnityEngine.Random.Range(1, 4); for (int i = 0 ; i < fleetShipCount ; i++) { constellation.fleet.Add(GenerateFleetShip()); } // restore previous seed UnityEngine.Random.seed = origSeed; return constellation; }
protected override Constellation Construct(ConstellationManifest conMf) { Constellation con; if (constellations.TryGetValue(conMf.position, out con)) { return con; } con = Instantiate(constellationPrefab) as Constellation; if (con == null) { return null; } con.Manifest = conMf; con.transform.localPosition = conMf.position; // foreach (var starMf in conMf.stars) { // MapStar starPf = game.GetMapStarPrefab(starMf.color); // MapStar star = Instantiate(starPf) as MapStar; // star.manifest = starMf; // star.constellation = con; // con.stars.Add(star); // } constellations.Add(con.Manifest.position, con); return con; }
override protected Constellation Construct(ConstellationManifest conMf) { Constellation con; if (constellations.TryGetValue(conMf.position, out con)) { return(con); } con = Instantiate(constellationPrefab) as MapConstellation; con.Manifest = conMf; con.transform.localPosition = conMf.position; // stars foreach (var starMf in conMf.stars) { MapStar starPf = game.GetMapStarPrefab(starMf.color); MapStar star = Instantiate(starPf) as MapStar; star.manifest = starMf; star.constellation = con; con.Stars.Add(star); // universeBounds.Encapsulate(con.transform.position + starMf.position); } // Fleet foreach (var shipMf in conMf.fleet) { FleetShip shipPf = game.GetFleetShipPrefab(shipMf); FleetShip ship = Instantiate(shipPf) as FleetShip; ship.transform.parent = con.transform; ship.transform.localPosition = shipMf.position; ship.transform.localScale = new Vector3(3f, 3f, 3f); ship.manifest = shipMf; con.Fleet.Add(ship); } constellations.Add(con.Manifest.position, con); return(con); }
void OnDrawGizmos() { if (game == null || game.universeManifest == null) { return; } // camera view bounds Bounds bounds = GetCameraBounds(); Gizmos.color = Color.white; Gizmos.DrawSphere(bounds.center, 1f); // center sphere Gizmos.DrawWireCube(bounds.center, bounds.size); // generation bounds bounds.Expand(3f); Gizmos.color = Color.yellow; Gizmos.DrawSphere(bounds.center, 1f); // center sphere Gizmos.DrawWireCube(bounds.center, bounds.size); // constellations manifest bounds foreach (var pair in game.universeManifest.constellations) { ConstellationManifest con = pair.Value; if (constellations.ContainsKey(con.position)) { Gizmos.color = Color.green; } else { Gizmos.color = Color.gray; } Gizmos.DrawSphere(con.bounds.center, 1f); // center sphere Gizmos.DrawWireCube(con.bounds.center, con.bounds.size); } }
protected override Constellation Construct(ConstellationManifest conMf) { return null; }
private bool StarRequirements(ConstellationManifest constellation, StarManifest star) { foreach (var st in constellation.stars) { float dist = Vector3.Distance(st.position, star.position); if (minStarGap > dist) { return false; } } return true; }
override protected Constellation Construct(ConstellationManifest conMf) { Constellation con; if (constellations.TryGetValue(conMf.position, out con)) { return(con); } con = Instantiate(constellationPrefab) as Constellation; con.Manifest = conMf; con.transform.localPosition = Vector3.zero; // stars foreach (var starMf in conMf.stars) { LocalStar starPf = game.GetLocalStarPrefab(starMf.color); LocalStar star = Instantiate(starPf) as LocalStar; star.manifest = starMf; con.Stars.Add(star); star.constellation = con; if (game.hullManifest.star != starMf.index) { if (star.gameObject.activeSelf) { star.gameObject.SetActive(false); } continue; } if (!star.gameObject.activeSelf) { star.gameObject.SetActive(true); } this.star = star; star.transform.position = Vector3.zero; star.transform.parent = star.constellation.transform; star.transform.localPosition = Vector3.zero; // planets GameObject orbits = new GameObject("Orbits"); orbits.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f); star.planets = new List <Planet>(); foreach (PlanetManifest planetMf in starMf.planets) { GameObject orbit = new GameObject("Orbit " + (planetMf.index + 1)); orbit.transform.parent = orbits.transform; orbit.transform.localScale = new Vector3(1f, 1f, 1f); orbit.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, planetMf.orbitPosition)); BuildCircleMesh line = Instantiate(orbitLinePrefab) as BuildCircleMesh; line.transform.parent = orbit.transform; line.transform.localScale = new Vector3(1f, 1f, 1f); line.transform.localRotation = Quaternion.identity; line.innerRadius = planetMf.orbitDistance - 10; Planet planet = Instantiate(game.GetPlanetPrefab(planetMf.type)) as Planet; star.planets.Add(planet); planet.transform.parent = orbit.transform; planet.transform.localPosition = new Vector3(planetMf.orbitDistance, 0f, 0f); planet.transform.localScale = new Vector3(planetMf.size, planetMf.size, planetMf.size); planet.transform.localRotation = Quaternion.identity; planet.index = planetMf.index; planet.star = star; if (game.hullManifest.planet == planetMf.index) { this.planet = planet; } } Planet lastPlanet = star.planets[star.planets.Count - 1]; // size star.transform.localScale = star.transform.localScale * ((float)starMf.size + 1f); List <ParticleSystem> particleSystems = new List <ParticleSystem>(star.GetComponentsInChildren <ParticleSystem>()); foreach (var ps in particleSystems) { ps.startSize = ps.startSize * ((float)starMf.size + 1f); } // set camera float scaleFactor = lastPlanet.transform.lossyScale.x / lastPlanet.transform.localScale.x; Camera.main.orthographicSize = lastPlanet.transform.localPosition.x * scaleFactor * Camera.main.aspect; // Camera.main.transform.position = new Vector3( // Camera.main.transform.position.x, // -(Camera.main.orthographicSize + 45f) * 0.484f, // Camera.main.transform.position.z // ); // ship position if (playerShip.transform.position == Vector3.zero) { playerShip.transform.position = new Vector3( 0f, -lastPlanet.transform.localPosition.x * scaleFactor - 6f, 0f ); } else if (playerShip.manifest.planet != null) { playerShip.transform.position = star.planets[(int)playerShip.manifest.planet].transform.position; } } constellations.Add(con.Manifest.position, con); return(con); }
protected abstract Constellation Construct(ConstellationManifest conMf);
abstract protected Constellation Construct(ConstellationManifest conMf);
protected override Constellation Construct(ConstellationManifest conMf) { Constellation con; if (constellations.TryGetValue(conMf.position, out con)) { return con; } con = Instantiate(constellationPrefab) as Constellation; con.Manifest = conMf; con.transform.localPosition = Vector3.zero; // stars foreach (var starMf in conMf.stars) { LocalStar starPf = game.GetLocalStarPrefab(starMf.color); LocalStar star = Instantiate(starPf) as LocalStar; star.manifest = starMf; con.Stars.Add(star); star.constellation = con; if (game.hullManifest.star != starMf.index) { if (star.gameObject.activeSelf) { star.gameObject.SetActive(false); } continue; } if (!star.gameObject.activeSelf) { star.gameObject.SetActive(true); } this.star = star; star.transform.position = Vector3.zero; star.transform.parent = star.constellation.transform; star.transform.localPosition = Vector3.zero; // planets GameObject orbits = new GameObject("Orbits"); orbits.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f); star.planets = new List<Planet>(); foreach (PlanetManifest planetMf in starMf.planets) { GameObject orbit = new GameObject("Orbit " + (planetMf.index + 1)); orbit.transform.parent = orbits.transform; orbit.transform.localScale = new Vector3(1f, 1f, 1f); orbit.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, planetMf.orbitPosition)); BuildCircleMesh line = Instantiate(orbitLinePrefab) as BuildCircleMesh; line.transform.parent = orbit.transform; line.transform.localScale = new Vector3(1f, 1f, 1f); line.transform.localRotation = Quaternion.identity; line.innerRadius = planetMf.orbitDistance - 10; Planet planet = Instantiate(game.GetPlanetPrefab(planetMf.type)) as Planet; star.planets.Add(planet); planet.transform.parent = orbit.transform; planet.transform.localPosition = new Vector3(planetMf.orbitDistance, 0f, 0f); planet.transform.localScale = new Vector3(planetMf.size, planetMf.size, planetMf.size); planet.transform.localRotation = Quaternion.identity; planet.index = planetMf.index; planet.star = star; if (game.hullManifest.planet == planetMf.index) { this.planet = planet; } } Planet lastPlanet = star.planets[star.planets.Count - 1]; // size star.transform.localScale = star.transform.localScale * ((float)starMf.size + 1f); List<ParticleSystem> particleSystems = new List<ParticleSystem>(star.GetComponentsInChildren<ParticleSystem>()); foreach (var ps in particleSystems) { ps.startSize = ps.startSize * ((float)starMf.size + 1f); } // set camera float scaleFactor = lastPlanet.transform.lossyScale.x / lastPlanet.transform.localScale.x; Camera.main.orthographicSize = lastPlanet.transform.localPosition.x * scaleFactor * Camera.main.aspect; // Camera.main.transform.position = new Vector3( // Camera.main.transform.position.x, // -(Camera.main.orthographicSize + 45f) * 0.484f, // Camera.main.transform.position.z // ); // ship position if (playerShip.transform.position == Vector3.zero) { playerShip.transform.position = new Vector3( 0f, -lastPlanet.transform.localPosition.x * scaleFactor - 6f, 0f ); } else if (playerShip.manifest.planet != null) { playerShip.transform.position = star.planets[(int)playerShip.manifest.planet].transform.position; } } constellations.Add(con.Manifest.position, con); return con; }
override protected Constellation Construct(ConstellationManifest conMf) { return(null); }