/// <summary> /// Saves a fleet to disk /// </summary> /// <param name="handler"></param> /// <param name="jsonFile"></param> public static void Save(fleetFileSerializer handler, string jsonFile) { string appDataFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SOV\\"; string s = JsonUtility.ToJson(handler); System.IO.File.WriteAllText(appDataFolder + jsonFile, s); }
public void savefleetform2(List <ShipCon> ships) { string jsonFile = "TestFleet.json"; fleetFileSerializer hnd = new fleetFileSerializer(); hnd.FleetName = "Another Test Fleet"; foreach (ShipCon ship in ships) { string[] shipweapon = new string[5] { null, null, null, null, null }; for (int a = 0; a < 5; a++) { if (ship.Weapons.Count > a) { shipweapon[a] = ship.Weapons[a]; } } Vector3[] shipweaponpos = new Vector3[5] { new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0) }; for (int i = 0; i < 5; i++) { if (ship.Positions.Count > i) { shipweaponpos[i] = ship.Positions[i]; } } Vector3[] shipweaponscale = new Vector3[5] { new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0) }; for (int f = 0; f < 5; f++) { if (ship.Scales.Count > f) { shipweaponscale[f] = ship.Scales[f]; } } hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = ship.ship, Position = ship.loc, Weapon1 = shipweapon[0], Weapon2 = shipweapon[1], Weapon3 = shipweapon[2], Weapon4 = shipweapon[3], Weapon5 = shipweapon[4], WeaponPos1 = shipweaponpos[0], WeaponPos2 = shipweaponpos[1], WeaponPos3 = shipweaponpos[2], WeaponPos4 = shipweaponpos[3], WeaponPos5 = shipweaponpos[4], WeaponScale1 = shipweaponscale[0], WeaponScale2 = shipweaponscale[1], WeaponScale3 = shipweaponscale[2], WeaponScale4 = shipweaponscale[3], WeaponScale5 = shipweaponscale[4] }); } fleetFileSerializer.Save(hnd, jsonFile); }
public void jsonsavedefaultshiplist(string jsonFile) { //// Create a temp file fleetFileSerializer hnd = new fleetFileSerializer(); hnd.FleetName = "Another Test Fleet"; /* * // Add Super Capital (SuperCapitalOffense) * hnd.Ships.Add(new fleetFileSerializer.Ship() { * Type = "SuperCapitalOffense", * Position = new Vector3(0, 0, 0) * }); */ // Add Capital (CapitalDefense) /* * hnd.Ships.Add(new fleetFileSerializer.Ship() { * Type = "CapitalDefense", * Position = new Vector3(0, -1, 0) * }); * * // Add Destroyers (DestroyerOffense, DestroyerSupport) * hnd.Ships.Add(new fleetFileSerializer.Ship() { * Type = "DestroyerOffense", * Position = new Vector3(-1, 0, 0) * }); * hnd.Ships.Add(new fleetFileSerializer.Ship() { * Type = "DestroyerSupport", * Position = new Vector3(1f, 0, 0) * }); */ //pathfinding errors, fix later // Add Cruisers (CruiserDefense, CruiserOffense) hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CruiserDefense", Position = new Vector3(-0.5f, 1, 0) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CruiserOffense", Position = new Vector3(0, 1, 0) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CruiserDefense", Position = new Vector3(0.5f, 1, 0) }); // Add Frigates hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "FrigateOffense", Position = new Vector3(-1, 0, 2.5f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "FrigateOffense", Position = new Vector3(-0.5f, 0, 2.5f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "FrigateOffense", Position = new Vector3(0, 0, 2.5f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "FrigateOffense", Position = new Vector3(0.5f, 0, 2.5f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "FrigateOffense", Position = new Vector3(1, 0, 2.5f) }); // Add Corvettes hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CorvetteOffense", Position = new Vector3(-1, 0, 3) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CorvetteSupport", Position = new Vector3(-0.5f, 0, 3) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CorvetteOffense", Position = new Vector3(0, 0, 3) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CorvetteSupport", Position = new Vector3(0.5f, 0, 3) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "CorvetteOffense", Position = new Vector3(1, 0, 3) }); // Add fighters hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "LightCraftOffense", Position = new Vector3(-1, 0, 3.25f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "LightCraftDefense", Position = new Vector3(-0.5f, 0, 3.25f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "LightCraftSupport", Position = new Vector3(0, 0, 3.25f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "LightCraftTank", Position = new Vector3(0.5f, 0, 3.25f) }); hnd.Ships.Add(new fleetFileSerializer.Ship() { Type = "LightCraftOffense", Position = new Vector3(1, 0, 3.25f) }); fleetFileSerializer.Save(hnd, jsonFile); }
// Spawn objects private void SpawnObjects(bool bot, int a, int spawnfleet) { Debug.Log(a); if ((bot && crosslevelholder.bots == true && crosslevelholder.TestArea == false && crosslevelholder.campaign == false) || (bot == false && alreadyspawned == false)) { if (bot == false) { alreadyspawned = true; } Spawned = true; Debug.Log("Joined room \"" + PhotonNetwork.room.Name + "\""); if (PhotonNetwork.isMasterClient && PhotonNetwork.offlineMode == false) { PhotonNetwork.room.IsOpen = true; } CrossLevelVariableHolder crosslevelvarholder = GameObject.Find("CrossLevelVariables").GetComponent <CrossLevelVariableHolder>(); _gc.convertspawnpoints(crosslevelvarholder.Gamemode); Vector3 spawnLocation = spawnpoint(_gc, a); Quaternion lookDirection = Quaternion.identity; _Ship.eShipColor ShipColor = getspawncolor(a); string jsonFile = "TestFleet.json"; string supercap = "Super-Capital"; savefleetform2(loadshipsform1(spawnfleet)); Vector3 relPos = Vector3.zero - spawnLocation; lookDirection = Quaternion.LookRotation(relPos); fleetFileSerializer handl = fleetFileSerializer.Load(jsonFile); Debug.Log("Loaded \"" + jsonFile + "\" with the fleet named \"" + handl.FleetName + "\""); Debug.Log(handl.Ships.Count); if (bot && crosslevelholder.tutorial == false) { spawnbotcontroller(ShipColor); } float i = 0; foreach (fleetFileSerializer.Ship shp in handl.Ships) { if (shp.Type != "nothing") { Debug.Log(shp.Type); int viewID = PhotonNetwork.AllocateViewID(); int playerID = PhotonNetwork.player.ID; GetModule <MOD_SpawnObject>("Spawn Object").SendSpawnObject(shp.Type, (spawnLocation + new Vector3(0, 0, i)), lookDirection, viewID); if (crosslevelholder.tutorial == false || bot == true) { pv.RPC("fixturrets", PhotonTargets.All, viewID, shp.Weapon1, shp.Weapon2, shp.Weapon3, shp.Weapon4, shp.Weapon5, shp.WeaponPos1, shp.WeaponPos2, shp.WeaponPos3, shp.WeaponPos4, shp.WeaponPos5, shp.WeaponScale1, shp.WeaponScale2, shp.WeaponScale3, shp.WeaponScale4, shp.WeaponScale5, a, bot, (spawnLocation * 1000) + new Vector3(0, 0, i * 1000)); } else { pv.RPC("fixturrets", PhotonTargets.All, viewID, shp.Weapon1, shp.Weapon2, shp.Weapon3, shp.Weapon4, shp.Weapon5, shp.WeaponPos1, shp.WeaponPos2, shp.WeaponPos3, shp.WeaponPos4, shp.WeaponPos5, shp.WeaponScale1, shp.WeaponScale2, shp.WeaponScale3, shp.WeaponScale4, shp.WeaponScale5, a, bot, new Vector3(0, 0, i * 100) + new Vector3(1, 1, 1)); } i++; } } int viewID2 = PhotonNetwork.AllocateViewID(); StartCoroutine("Waitforread"); if (crosslevelholder.Gamemode == CrossLevelVariableHolder.gamemode.CapitalShip) { GetModule <MOD_SpawnObject>("Spawn Object").SendSpawnObject(supercap, ((spawnLocation * 1000) + new Vector3(0, 0, i * 1000)), lookDirection, viewID2); pv.RPC("fixShip", PhotonTargets.All, viewID2, a, (spawnLocation * 1000) + new Vector3(0, 0, i * 1000)); } } if (bot && crosslevelholder.campaign == true) { _Ship.eShipColor ShipColor = getspawncolor(a); Debug.Log(ShipColor); AIController gam = spawnbotcontroller(ShipColor); _gc.convertspawnpoints(CrossLevelVariableHolder.gamemode.TeamDeathMatch); gam.setmission(crosslevelholder.campaignlevel, (spawnpoint(_gc, a)).ToTSVector()); } }