Advertisement
Camocc_Studios

SM

Aug 18th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 20.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5.  
  6. public class StructureManager : MonoBehaviour
  7. {
  8.     public GameObject WorldHolder;
  9.     public PlayerScript PS;
  10.     public CityManager CityMan;
  11.     public Devmode Dev;
  12.     public UIManager UMan;
  13.     public IslandGenerator IG;
  14.  
  15.     public Animator NoteAnim; //notification bar
  16.     public TextMeshProUGUI NoteText;
  17.  
  18.     [HideInInspector]
  19.     public List<List<GameObject>> Templates = new List<List<GameObject>>();
  20.  
  21.  
  22.     [Header("Defense")]
  23.     public List<GameObject> Defense = new List<GameObject>();
  24.     public List<GameObject> TemplateDefense = new List<GameObject>();
  25.     [Header("Weapons")]
  26.     public List<GameObject> Weapons = new List<GameObject>();
  27.     public List<GameObject> TemplateWeapons = new List<GameObject>();
  28.     [Header("Factories")]
  29.     public List<GameObject> Factories = new List<GameObject>();
  30.     public List<GameObject> TemplateFactories = new List<GameObject>();
  31.     [Header("Houses")]
  32.     public List<GameObject> Houses = new List<GameObject>();
  33.     public List<GameObject> TemplateHouses = new List<GameObject>();
  34.     [Header("Decoration")]
  35.     public List<GameObject> Decoration = new List<GameObject>();
  36.     public List<GameObject> TemplateDecoration = new List<GameObject>();
  37.     [Header("Transport")]
  38.     public List<GameObject> Transport = new List<GameObject>();
  39.     public List<GameObject> TemplateTransport = new List<GameObject>();
  40.     [Space(10)]
  41.  
  42.  
  43.     [HideInInspector]
  44.     public List<List<GameObject>> Builds = new List<List<GameObject>>();
  45.  
  46.     [Header("InScene")]
  47.     public List<GameObject> _Defense = new List<GameObject>();
  48.     public List<GameObject> _Weapons = new List<GameObject>();
  49.     public List<GameObject> _Factories = new List<GameObject>();
  50.     public List<GameObject> _Houses = new List<GameObject>();
  51.     public List<GameObject> _Decoration = new List<GameObject>();
  52.     public List<GameObject> _Transport = new List<GameObject>();
  53.     [Space(10)]
  54.  
  55.     [Header("Floors")]
  56.     public GameObject EmptyFoor;
  57.     public List<GameObject> Floors = new List<GameObject>();
  58.     public List<GameObject> _Floors = new List<GameObject>();
  59.     public List<GameObject> FloorsTemplates = new List<GameObject>();
  60.     [Space(10)]
  61.  
  62.     [Header("Island Stuff")]
  63.     public GameObject myTotem;
  64.     public List<GameObject> Totems = new List<GameObject>();
  65.     public List<GameObject> Islands = new List<GameObject>();
  66.     public List<GameObject> genIslands = new List<GameObject>();
  67.  
  68.     [Space(10)]
  69.  
  70.     [Header("Other Stuff")]
  71.     public List<GameObject> Mines = new List<GameObject>();
  72.  
  73.  
  74.  
  75.     private void Start()
  76.     {
  77.         Builds.Add(_Defense);
  78.         Builds.Add(_Weapons);
  79.         Builds.Add(_Factories);
  80.         Builds.Add(_Houses);
  81.         Builds.Add(_Decoration);
  82.         Builds.Add(_Transport);
  83.         Builds.Add(_Floors);
  84.         Dev.Log("Custom Obj Array set");
  85.  
  86.         Templates.Add(Defense);
  87.         Templates.Add(Weapons);
  88.         Templates.Add(Factories);
  89.         Templates.Add(Houses);
  90.         Templates.Add(Decoration);
  91.         Templates.Add(Transport);
  92.         Templates.Add(Floors);
  93.         Dev.Log("Template Array Set");
  94.  
  95.         for (int i = 0; i < 12; i++)
  96.         {
  97.             string SaveName = PlayerPrefs.GetString(i + ":" + "SaveName");
  98.  
  99.             if (SaveName != "")
  100.             {
  101.                 UMan.SaveSlots[i].transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = SaveName;
  102.                 UMan.SaveSlots[i].transform.GetChild(1).GetComponent<TextMeshProUGUI>().text = PlayerPrefs.GetString(SaveName + ":" + "DateTime");
  103.                 UMan.SaveSlots[i].transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = (PlayerPrefs.GetInt(SaveName + ":" + "UniqueID")+PlayerPrefs.GetInt(SaveName + ":" + "IleTotal")).ToString();
  104.             }
  105.         }
  106.  
  107.     }
  108.  
  109.     public void ReciveObj(GameObject obj)
  110.     {
  111.         string Class = obj.GetComponent<SDH>().Class;
  112.         if(Class == "Defense")
  113.         {
  114.             _Defense.Add(obj);
  115.         }
  116.         if (Class == "Weapons")
  117.         {
  118.             _Weapons.Add(obj);
  119.         }
  120.         if (Class == "Factories")
  121.         {
  122.             _Factories.Add(obj);
  123.         }
  124.         if (Class == "Houses")
  125.         {
  126.             _Houses.Add(obj);
  127.         }
  128.         if (Class == "Decoration")
  129.         {
  130.             _Decoration.Add(obj);
  131.         }
  132.         if (Class == "Transport")
  133.         {
  134.             _Transport.Add(obj);
  135.         }
  136.         Dev.Log("Structure Manager recived " + obj.name + " from class " + Class);
  137.     }
  138.  
  139.     public void ClearSave(string SaveName, int menuIndex)
  140.     {
  141.         StartCoroutine(DataCorDelete(SaveName, menuIndex));
  142.     }
  143.  
  144.     public void SaveData(string SaveName, int MenuIndex)
  145.     {
  146.         StartCoroutine(DataCorSave(SaveName, MenuIndex));
  147.     }
  148.     public void ClearCurrentPlate()
  149.     {
  150.         Dev.Log("Clearing plate");
  151.         foreach (List<GameObject> array in Builds)
  152.         {
  153.             foreach (GameObject obj in array)
  154.             {
  155.                 SDH data = obj.GetComponent<SDH>();
  156.                 data.isDestroyed = 1;
  157.                 Destroy(obj);
  158.             }
  159.  
  160.         }
  161.         foreach (List<GameObject> array in Builds)
  162.         {
  163.             array.Clear();
  164.             Dev.Log("Objs Cleared");
  165.         }
  166.  
  167.         CityMan.Population = 0;
  168.         CityMan.Money = 0;
  169.  
  170.         for (int i = 0; i < CityMan.Resource.Count; i++)
  171.         {
  172.             CityMan.Resource[i] = 0;
  173.            
  174.         }
  175.         Dev.Log("Clearing Resources");
  176.  
  177.         foreach(GameObject ile in genIslands)
  178.         {
  179.             Destroy(ile);
  180.         }
  181.         Destroy(myTotem);
  182.         genIslands.Clear();
  183.         Dev.Log("Islands Cleared");
  184.         Dev.Log("Totem Reset");
  185.         Dev.Log("Plate Cleared");
  186.     }
  187.  
  188.     public void LoadData(string SaveName)
  189.     {
  190.         StartCoroutine(DataCorLoad(SaveName));
  191.     }
  192.  
  193.     private void Update()
  194.     {
  195.         if (PlayerPrefs.GetInt("UniqueID") > PlayerPrefs.GetInt("MostObjs"))
  196.         {
  197.             PlayerPrefs.SetInt("MostObjs", PlayerPrefs.GetInt("UniqueID"));
  198.         }
  199.  
  200.  
  201.  
  202.     }
  203.  
  204.     IEnumerator DataCorSave(string SaveName, int MenuIndex)
  205.     {
  206.         yield return null;
  207.         Dev.Log("Saving Data of " + SaveName);
  208.         NoteText.text = "Saving";
  209.         NoteAnim.SetTrigger("Note");
  210.  
  211.         string Time = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
  212.  
  213.         PlayerPrefs.SetInt(SaveName + ":" + "Population", CityMan.Population);
  214.         PlayerPrefs.SetInt(SaveName + ":" + "Money", CityMan.Money);
  215.         PlayerPrefs.SetInt(SaveName + ":" + "UniqueID", PS.nextUniqueID);
  216.         PlayerPrefs.SetInt(SaveName + ":" + "SaveSlot", MenuIndex);
  217.         PlayerPrefs.SetString(SaveName + ":" + "DateTime", Time);
  218.         PlayerPrefs.SetString(MenuIndex + ":" + "SaveName", SaveName);
  219.  
  220.         PlayerPrefs.SetFloat(SaveName + ":" + "PlayerxPos", PS.PlayerModel.transform.position.x);
  221.         PlayerPrefs.SetFloat(SaveName + ":" + "PlayeryPos", PS.PlayerModel.transform.position.y);
  222.         PlayerPrefs.SetFloat(SaveName + ":" + "PlayerzPos", PS.PlayerModel.transform.position.z);
  223.         Dev.Log("Player Data saved");
  224.  
  225.  
  226.         Dev.Log("UI Prefs saved");
  227.  
  228.         foreach (string res in CityMan.Names)
  229.         {
  230.             PlayerPrefs.SetInt(SaveName + ":" + res, CityMan.Resource[CityMan.Names.IndexOf(res)]);
  231.             Dev.Log("Saving " + CityMan.Resource[CityMan.Names.IndexOf(res)] + " " + SaveName + ":" + res);
  232.             yield return null;
  233.         }
  234.  
  235.         foreach (List<GameObject> array in Builds)
  236.         {
  237.             yield return null;
  238.             foreach (GameObject obj in array)
  239.             {
  240.                 SDH _sdh = obj.GetComponent<SDH>();
  241.  
  242.  
  243.                 int ID = _sdh.uniqueID;
  244.                 Debug.Log(ID);
  245.                 PlayerPrefs.SetInt(SaveName + ":" + ID.ToString() + "ID", ID);
  246.                 PlayerPrefs.SetString(SaveName + ":" + ID.ToString() + "Type", _sdh.type);
  247.                 PlayerPrefs.SetString(SaveName + ":" + ID.ToString() + "Class", _sdh.Class);
  248.                 PlayerPrefs.SetFloat(SaveName + ":" + ID.ToString() + "xPos", _sdh.xPos);
  249.                 PlayerPrefs.SetFloat(SaveName + ":" + ID.ToString() + "yPos", _sdh.yPos);
  250.                 PlayerPrefs.SetFloat(SaveName + ":" + ID.ToString() + "zPos", _sdh.zPos);
  251.                 PlayerPrefs.SetFloat(SaveName + ":" + ID.ToString() + "Rot", _sdh.Rot);
  252.                 PlayerPrefs.SetInt(SaveName + ":" + ID.ToString() + "isDestroyed", _sdh.isDestroyed);
  253.                 PlayerPrefs.SetFloat(SaveName + ":" + ID.ToString() + "Durab", _sdh.durability);
  254.                 PlayerPrefs.SetFloat(SaveName + ":" + ID.ToString() + "Health", _sdh.health);
  255.                 Dev.Log("Saving " + SaveName + ":" + ID + " : " + _sdh.type + " : " + " : " + _sdh.Class);
  256.                 //Debug.Log(PS.nextUniqueID);
  257.                 //Debug.Log("ID = " + ID + " Type = " + _sdh.type + " Class = " + _sdh.Class + " Pos = " + new Vector3(_sdh.xPos,_sdh.yPos,_sdh.zPos) + " Rot = " + _sdh.Rot + " IsD = " + _sdh.isDestroyed);
  258.  
  259.             }
  260.         }
  261.  
  262.         foreach (GameObject ile in genIslands)
  263.         {
  264.             yield return null;
  265.             IslandData IleData = ile.GetComponent<IslandData>();
  266.             PlayerPrefs.SetInt(SaveName + ":" + IleData.islandID.ToString() + "IleID", IleData.islandID);
  267.             PlayerPrefs.SetInt(SaveName + ":" + IleData.islandID.ToString() + "IleType", IleData.ileType);
  268.             PlayerPrefs.SetFloat(SaveName + ":" + IleData.islandID.ToString() + "IleRot", IleData.Rot);
  269.             PlayerPrefs.SetFloat(SaveName + ":" + IleData.islandID.ToString() + "IlexPos", IleData.xPos);
  270.             PlayerPrefs.SetFloat(SaveName + ":" + IleData.islandID.ToString() + "IleyPos", IleData.yPos);
  271.             PlayerPrefs.SetFloat(SaveName + ":" + IleData.islandID.ToString() + "IlezPos", IleData.zPos);
  272.             Dev.Log("Saving Island " + SaveName + ":" + IleData.islandID + " : " + IleData.ileType);
  273.  
  274.             PlayerPrefs.SetInt(SaveName + ":" + "IleTotal", IG.islandID);
  275.             PlayerPrefs.SetFloat(SaveName + ":" + "TimeElapsed", IG.elapsetTimeInGame);
  276.             PlayerPrefs.SetFloat(SaveName + ":" + "TimeOfDay", IG.todayTime);
  277.  
  278.            
  279.         }
  280.  
  281.         PlayerPrefs.SetInt(SaveName + ":" + "TotemID", myTotem.GetComponent<TotemData>().totemID);
  282.         PlayerPrefs.SetInt(SaveName + ":" + "TotemBuffScale", myTotem.GetComponent<TotemData>().buffScale);
  283.  
  284.         UMan.SaveSlots[MenuIndex].transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = SaveName;
  285.         UMan.SaveSlots[MenuIndex].transform.GetChild(1).GetComponent<TextMeshProUGUI>().text = PlayerPrefs.GetString(SaveName + ":" + "DateTime");
  286.         UMan.SaveSlots[MenuIndex].transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = (PlayerPrefs.GetInt(SaveName + ":" + "UniqueID") + PlayerPrefs.GetInt(SaveName + ":" + "IleTotal")).ToString();
  287.  
  288.  
  289.         NoteText.text = "Saved";
  290.         NoteAnim.SetTrigger("Note");
  291.         Dev.Log("Saved");
  292.         UMan.SaveEditUI.SetActive(false);
  293.  
  294.     }
  295.     IEnumerator DataCorLoad(string SaveName)
  296.     {
  297.         yield return null;
  298.         Dev.Log("Loading Data of " + SaveName);
  299.  
  300.         NoteText.text = "Loading Save";
  301.         NoteAnim.SetTrigger("Note");
  302.  
  303.         ClearCurrentPlate();
  304.  
  305.         PS.nextUniqueID = PlayerPrefs.GetInt(SaveName + ":" + "UniqueID");
  306.         CityMan.Money = PlayerPrefs.GetInt(SaveName + ":" + "Money");
  307.         CityMan.Population = PlayerPrefs.GetInt(SaveName + ":" + "Population");
  308.         int Menuindex = PlayerPrefs.GetInt(SaveName + ":" + "SaveSlot");
  309.  
  310.         float plrXPos = PlayerPrefs.GetFloat(SaveName + ":" + "PlayerxPos");
  311.         float plrYPos = PlayerPrefs.GetFloat(SaveName + ":" + "PlayeryPos");
  312.         float plrZPos = PlayerPrefs.GetFloat(SaveName + ":" + "PlayerzPos");
  313.  
  314.  
  315.         Dev.Log("Loading Player Data");
  316.  
  317.         foreach (string res in CityMan.Names)
  318.         {
  319.             CityMan.Resource[CityMan.Names.IndexOf(res)] = PlayerPrefs.GetInt(SaveName + ":" + res);
  320.             Dev.Log("Loading Resource " + CityMan.Resource[CityMan.Names.IndexOf(res)] + " " + res);
  321.             yield return null;
  322.         }
  323.  
  324.         PS.FilledFloors.Clear(); //ref to down below
  325.  
  326.         for (int i = 0; i < PS.nextUniqueID; i++)
  327.         {
  328.             yield return null;
  329.             //Debug.Log("Loop " +i+"/"+PS.nextUniqueID);
  330.             if (PlayerPrefs.GetInt(SaveName + ":" + i.ToString() + "isDestroyed") == 0)
  331.             {
  332.  
  333.                 int ID = i;
  334.                 string Type = PlayerPrefs.GetString(SaveName + ":" + ID.ToString() + "Type");
  335.                 string Class = PlayerPrefs.GetString(SaveName + ":" + ID.ToString() + "Class");
  336.                 float xPos = PlayerPrefs.GetFloat(SaveName + ":" + ID.ToString() + "xPos");
  337.                 float yPos = PlayerPrefs.GetFloat(SaveName + ":" + ID.ToString() + "yPos");
  338.                 float zPos = PlayerPrefs.GetFloat(SaveName + ":" + ID.ToString() + "zPos");
  339.                 float Rot = PlayerPrefs.GetFloat(SaveName + ":" + ID.ToString() + "Rot");
  340.                 int isDestroyed = PlayerPrefs.GetInt(SaveName + ":" + ID.ToString() + "isDestroyed");
  341.                 float Durab = PlayerPrefs.GetFloat(SaveName + ":" + ID.ToString() + "Durab");
  342.                 float Health = PlayerPrefs.GetFloat(SaveName + ":" + ID.ToString() + "Health");
  343.  
  344.                 Vector3 Position = new Vector3(xPos, yPos, zPos);
  345.  
  346.                 Dev.Log("Data of object " + ID + " accessed, class = " + Class + ", type = " + Type);
  347.  
  348.                 //Debug.Log("ID = " +ID+" Type = " + Type+" Class = "+Class+" Pos = "+Position+ " Rot = "+Rot+" IsD = " +isDestroyed);
  349.  
  350.                 GameObject inst = null;
  351.  
  352.                 if (Class == "Defense")
  353.                 {
  354.                     for (int R = 0; R < Defense.Count; R++)
  355.                     {
  356.                         if (Defense[R].name + "(Clone)" == Type)
  357.                         {
  358.                             inst = Instantiate(Defense[R], Position, new Quaternion(0, 0, 0, 0), WorldHolder.transform);
  359.                             _Defense.Add(inst);
  360.  
  361.                         }
  362.                     }
  363.                 }
  364.                 else if (Class == "Weapons")
  365.                 {
  366.                     for (int R = 0; R < Weapons.Count; R++)
  367.                     {
  368.                         if (Weapons[R].name + "(Clone)" == Type)
  369.                         {
  370.                             inst = Instantiate(Weapons[R], Position, new Quaternion(0, 0, 0, 0), WorldHolder.transform);
  371.                             _Weapons.Add(inst);
  372.  
  373.                         }
  374.                     }
  375.                 }
  376.                 else if (Class == "Factories")
  377.                 {
  378.                     for (int R = 0; R < Factories.Count; R++)
  379.                     {
  380.                         if (Factories[R].name + "(Clone)" == Type)
  381.                         {
  382.                             inst = Instantiate(Factories[R], Position, new Quaternion(0, 0, 0, 0), WorldHolder.transform);
  383.                             _Factories.Add(inst);
  384.  
  385.                         }
  386.                     }
  387.                 }
  388.                 else if (Class == "Houses")
  389.                 {
  390.                     for (int R = 0; R < Houses.Count; R++)
  391.                     {
  392.                         if (Houses[R].name + "(Clone)" == Type)
  393.                         {
  394.                             inst = Instantiate(Houses[R], Position, new Quaternion(0, 0, 0, 0), WorldHolder.transform);
  395.                             _Houses.Add(inst);
  396.  
  397.                         }
  398.                     }
  399.                 }
  400.                 else if (Class == "Decoration")
  401.                 {
  402.                     for (int R = 0; R < Decoration.Count; R++)
  403.                     {
  404.                         if (Decoration[R].name + "(Clone)" == Type)
  405.                         {
  406.                             inst = Instantiate(Decoration[R], Position, new Quaternion(0, 0, 0, 0), WorldHolder.transform);
  407.                             _Decoration.Add(inst);
  408.  
  409.                         }
  410.                     }
  411.                 }
  412.                 else if (Class == "Transport")
  413.                 {
  414.                     for (int R = 0; R < Transport.Count; R++)
  415.                     {
  416.                         if (Transport[R].name + "(Clone)" == Type)
  417.                         {
  418.                             inst = Instantiate(Transport[R], Position, new Quaternion(0, 0, 0, 0), WorldHolder.transform);
  419.                             _Transport.Add(inst);
  420.  
  421.                         }
  422.                     }
  423.                 }
  424.                 else if (Class == "Floor")
  425.                 {
  426.                     for (int R = 0; R < Floors.Count; R++)
  427.                     {
  428.                         if (Floors[R].name + "(Clone)" == Type)
  429.                         {
  430.                             inst = Instantiate(Floors[R], Position, new Quaternion(0, 0, 0, 0), WorldHolder.transform);
  431.                             _Floors.Add(inst);
  432.  
  433.                             PS.FilledFloors.Add(Position);
  434.  
  435.                             if (!PS.FilledFloors.Contains(new Vector3(Position.x + 5, 0, Position.z)))
  436.                             {
  437.                                 Instantiate(EmptyFoor, new Vector3(Position.x + 5, 0, Position.z), Quaternion.identity, inst.transform);
  438.                             }
  439.                             if (!PS.FilledFloors.Contains(new Vector3(Position.x - 5, 0, Position.z)))
  440.                             {
  441.                                 Instantiate(EmptyFoor, new Vector3(Position.x - 5, 0, Position.z), Quaternion.identity, inst.transform);
  442.                             }
  443.                             if (!PS.FilledFloors.Contains(new Vector3(Position.x, 0, Position.z + 5)))
  444.                             {
  445.                                 Instantiate(EmptyFoor, new Vector3(Position.x, 0, Position.z + 5), Quaternion.identity, inst.transform);
  446.                             }
  447.                             if (!PS.FilledFloors.Contains(new Vector3(Position.x, 0, Position.z - 5)))
  448.                             {
  449.                                 Instantiate(EmptyFoor, new Vector3(Position.x, 0, Position.z - 5), Quaternion.identity, inst.transform);
  450.                             }
  451.                         }
  452.                     }
  453.                 }
  454.                 else
  455.                 {
  456.                     inst = null;
  457.                     Dev.Log("Item not found");
  458.                 }
  459.                 if (inst != null)
  460.                 {
  461.                     inst.transform.localEulerAngles = new Vector3(0, Rot, 0);
  462.  
  463.                     SDH sdh = inst.GetComponent<SDH>();
  464.                     sdh.uniqueID = ID;
  465.                     sdh.type = Type;
  466.                     sdh.Class = Class;
  467.                     sdh.xPos = xPos;
  468.                     sdh.yPos = yPos;
  469.                     sdh.zPos = zPos;
  470.                     sdh.Rot = Rot;
  471.                     sdh.isDestroyed = isDestroyed;
  472.                     sdh.durability = Durab;
  473.                     sdh.health = Health;
  474.  
  475.                     Dev.Log("Loaded " + Type + " at " + xPos + "," + yPos + "," + zPos + " with health " + Durab + "/" + Health);
  476.                 }
  477.                 UMan.SaveEditUI.SetActive(false);
  478.  
  479.  
  480.             }
  481.         }
  482.  
  483.         for (int i = 0; i < PlayerPrefs.GetInt(SaveName + ":" + "IleTotal"); i++)
  484.         {
  485.             yield return null;
  486.             int IleID = PlayerPrefs.GetInt(SaveName + ":" + i.ToString() + "IleID");
  487.             int IleType = PlayerPrefs.GetInt(SaveName + ":" + i.ToString() + "IleType");
  488.             float IleRot = PlayerPrefs.GetFloat(SaveName + ":" + i.ToString() + "IleRot");
  489.             float IlexPos = PlayerPrefs.GetFloat(SaveName + ":" + i.ToString() + "IlexPos");
  490.             float IleyPos = PlayerPrefs.GetFloat(SaveName + ":" + i.ToString() + "IleyPos");
  491.             float IlezPos = PlayerPrefs.GetFloat(SaveName + ":" + i.ToString() + "IlezPos");
  492.             Dev.Log("Loading Island " + SaveName + ":" + i.ToString() + " : " + IleType);
  493.  
  494.             GameObject newIle = Instantiate(Islands[IleType], new Vector3(IlexPos, IleyPos, IlezPos), Quaternion.identity, WorldHolder.transform);
  495.             newIle.transform.localEulerAngles = new Vector3(0, IleRot, 0);
  496.             IslandData IleData = newIle.GetComponent<IslandData>();
  497.  
  498.             IleData.islandID = IleID;
  499.             IleData.ileType = IleType;
  500.             IleData.Rot = IleRot;
  501.             IleData.xPos = IlexPos;
  502.             IleData.yPos = IleyPos;
  503.             IleData.zPos = IlezPos;
  504.             genIslands.Add(newIle);
  505.         }
  506.         IG.todayTime = PlayerPrefs.GetFloat(SaveName + ":" + "TimeOfDay");
  507.         IG.elapsetTimeInGame = PlayerPrefs.GetFloat(SaveName + ":" + "TimeElapsed");
  508.         GameObject first = genIslands[0];
  509.         genIslands.Remove(first);
  510.         Debug.Log(first.transform.position);
  511.         Destroy(first);
  512.  
  513.         myTotem = Instantiate(Totems[PlayerPrefs.GetInt(SaveName + ":" + "TotemID")],IG.TotemSpawn,Quaternion.identity,WorldHolder.transform);
  514.         myTotem.GetComponent<TotemData>().buffScale = PlayerPrefs.GetInt(SaveName + ":" + "TotemBuffScale");
  515.  
  516.         PS.PlayerModel.transform.position = new Vector3(plrXPos, plrYPos, plrZPos);
  517.  
  518.         CityMan.UpdateResDisp();
  519.         NoteText.text = "Loaded";
  520.         NoteAnim.SetTrigger("Note");
  521.  
  522.         Dev.Log("Loaded");
  523.     }
  524.     IEnumerator DataCorDelete(string SaveName, int menuIndex)
  525.     {
  526.         yield return null;
  527.         NoteText.text = "Clearing Save";
  528.         NoteAnim.SetTrigger("Note");
  529.         Dev.Log("clearing Save of  " + SaveName);
  530.  
  531.         ClearCurrentPlate();
  532.         int HS = PlayerPrefs.GetInt("MostObjs");
  533.         for (int i = 0; i < HS; i++)
  534.         {
  535.             yield return null;
  536.             if (PlayerPrefs.HasKey(SaveName + ":" + i.ToString() + "ID"))
  537.             {
  538.                 Dev.Log("Deleting item " + SaveName + ":" + i);
  539.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "ID");
  540.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "Type");
  541.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "Class");
  542.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "xPos");
  543.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "yPos");
  544.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "zPos");
  545.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "Rot");
  546.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "isDestroyed");
  547.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "Duraby");
  548.                 PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "Health");
  549.  
  550.             }
  551.         }
  552.         PlayerPrefs.DeleteKey(SaveName + ":" + "UniqueID");
  553.         PlayerPrefs.DeleteKey(SaveName + ":" + "Money");
  554.         PlayerPrefs.DeleteKey(SaveName + ":" + "Population");
  555.         PlayerPrefs.DeleteKey(menuIndex + ":" + "SaveName");
  556.         PlayerPrefs.DeleteKey(SaveName + ":" + "SaveSlot");
  557.         PlayerPrefs.DeleteKey(SaveName + ":" + "DateTime");
  558.  
  559.         for (int i = 0; i < PlayerPrefs.GetInt(SaveName + ":" + "IleTotal"); i++)
  560.         {
  561.             yield return null;
  562.  
  563.             PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "IleID");
  564.             PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "IleType");
  565.             PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "IleRot");
  566.             PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "IlexPos");
  567.             PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "IleyPos");
  568.             PlayerPrefs.DeleteKey(SaveName + ":" + i.ToString() + "IlezPos");
  569.         }
  570.         PlayerPrefs.DeleteKey(SaveName + ":" + "IleTotal");
  571.         PlayerPrefs.DeleteKey(SaveName + ":" + "TimeElapsed");
  572.         PlayerPrefs.DeleteKey(SaveName + ":" + "TimeOfDay");
  573.  
  574.         Dev.Log("Player Data Deleted");
  575.  
  576.         foreach (string res in CityMan.Names)
  577.         {
  578.             yield return null;
  579.  
  580.             PlayerPrefs.DeleteKey(SaveName + ":" + res);
  581.             Dev.Log("Deleting resource " + (SaveName + ":" + res));
  582.         }
  583.  
  584.         UMan.SaveSlots[menuIndex].transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "New Save";
  585.         UMan.SaveSlots[menuIndex].transform.GetChild(1).GetComponent<TextMeshProUGUI>().text = "MM/DD/YYYY";
  586.         UMan.SaveSlots[menuIndex].transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = "00.0Mb";
  587.  
  588.  
  589.         NoteText.text = "Save Cleared";
  590.         NoteAnim.SetTrigger("Note");
  591.         Dev.Log("All Data from " + SaveName + " Deleted");
  592.         UMan.SaveEditUI.SetActive(false);
  593.  
  594.     }
  595.  
  596.  
  597.  
  598. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement