private void Update() { int x = Random.Range(0, GalaxyManager.instance.Width - 1); int y = Random.Range(0, GalaxyManager.instance.Height - 1); Vector2 pos = GalaxyManager.instance.SectorToWorldPoint(new Vector2Int(x, y));; pos.x += Random.Range(-50, 50); pos.y += Random.Range(-50, 50); if (Input.GetKeyDown(KeyCode.Q)) { GalaxyManager.SpawnWorldObject(prefab, pos); } if (Input.GetKeyDown(KeyCode.E)) { GalaxyManager.SpawnWorldObject(prefab2, pos); } if (Input.GetKeyDown(KeyCode.S)) { SpaceSerializerDeserializer.MyMonoSerializeToFile(GalaxyManager.instance, "Galaxy.xml"); } if (Input.GetKeyDown(KeyCode.L)) { SpaceSerializerDeserializer.DeserializeGalaxyManager(GalManSource.text); } }
public void Update() { switch (Mode) { case GameMode.SETUP: GameObject chosen = Utils.getRandomEntry <GameObject>(StartingShips); GameObject starter = GalaxyManager.SpawnWorldObject(chosen, Vector3.zero); GalaxyManager.instance.AddObserver(starter); starter.name = "Player"; starter.AddComponent <PlayerController>(); Ship ship = starter.GetComponent <Ship>(); ship.SetFaction(FACTION.PLAYER_FACTION); ship.IsPlayer = true; PlayerData.instance.PlayerShip = ship; PlayerData.instance.AddScrap(StartingScrap); foreach (GameObject mod in StartingModules) { PlayerData.instance.AddModule(mod); } CameraManager.instance.SetToFollow(PlayerData.instance.PlayerShip.gameObject); CameraManager.instance.SetOffset(new Vector3(0, 0, -10)); HudController.instance.Disable(); MenuController.instance.Disable(); ShipEditor.instance.Enable(); // Galaxy Generation Mode = GameMode.NORMAL; break; } HandleMetaInput(); }
public void ShipSelected(GameObject capsuleItem) { Ship s = capsuleItem.GetComponent <Ship> (); if (PlayerData.instance.RemoveScrap(s.ScrapCost)) { ClearAll(); Qvent q = new Qvent(QventType.DESTROYED, typeof(Ship), PlayerData.instance.PlayerShip); foreach (QventHandler handler in PlayerData.instance.PlayerShip.Listeners) { handler.HandleQvent(q); } Vector3 previousPlayerPos = PlayerData.instance.PlayerShip.gameObject.transform.position; PlayerData.instance.AddScrap(s.ScrapCost); GameObject.Destroy(PlayerData.instance.PlayerShip.gameObject); PlayerData.instance.PlayerShip = null; GameObject newShip = GalaxyManager.SpawnWorldObject(s.gameObject, previousPlayerPos); Ship ship = newShip.GetComponent <Ship> (); ship.IsPlayer = true; ship.curhp = ship.maxhp / 5; PlayerData.instance.PlayerShip = ship; newShip.AddComponent <PlayerController> (); CameraManager.instance.SetToFollow(newShip); GalaxyManager.instance.AddObserver(newShip); } }
public GameObject CreateFloatingScrap(int value, Vector2 pos) { GameObject go = GalaxyManager.SpawnWorldObject(FreeFloatingScrap, pos); FloatingScrap fs = go.GetComponent <FloatingScrap> (); fs.ScrapValue = value; return(go); }
public GameObject CreateFloatingSchematic(Module module, Vector2 pos) { GameObject go = GalaxyManager.SpawnWorldObject(FloatingSchematic, pos); FloatingSchematic ffm = go.GetComponent <FloatingSchematic> (); ffm.SetItem(module.BASE_PATH); return(go); }
private void Build() { // done building if (Progress <= 0) { // we are actually building sth if (ChosenToBuild) { // Create the ship GameObject newShip = GalaxyManager.SpawnWorldObject(ChosenToBuild, transform.position); Ship ship = newShip.GetComponent <Ship> (); // Set hp to 1/5 ship.curhp = ship.maxhp / 5; foreach (Port p in ship.ports) { Module m; if ((m = p.GetModule())) { m.curhp = m.maxhp / 5; } } foreach (Port p in ship.mainPorts) { Module m; if ((m = p.GetModule())) { m.curhp = m.maxhp / 5; } } // set faction ship.SetFaction(this.faction); // add to list SpawnedShips.Add(newShip); ChosenToBuild = null; } if (SpawnedShips.Count < MaxSpawned) { ChosenToBuild = Utils.getRandomEntry <GameObject> (ShipsToSpawn); Progress = ChosenToBuild.GetComponent <Ship> ().RepairTime * 3; } } else { Progress -= SpaceGameGlobal.TICK_RATE; } }
public override void Generate(Sector sector) { List <GameObject> ltu; Vector2Int index = sector.index; Vector2Int delta = sector.index - new Vector2Int(GalaxyManager.instance.Width / 2, GalaxyManager.instance.Height / 2); if (delta.magnitude >= 4) { ltu = Level4Objects; } else if (delta.magnitude >= 3) { ltu = Level3Objects; } else if (delta.magnitude >= 2) { ltu = Level2Objects; } else if (delta.magnitude >= 1) { ltu = Level1Objects; } else { ltu = Level0Objects; } int num = Random.Range(1, Range); for (int i = 0; i < num; i++) { Vector2 pos = GalaxyManager.instance.SectorToWorldPoint(index); pos += Random.insideUnitCircle * GalaxyManager.instance.SectorSize / 2; GalaxyManager.SpawnWorldObject(Utils.getRandomEntry <GameObject> (ltu), pos); } }