public void LoadSceneObjects() { //getting resources GameManager.instance.setResources(PlayerPrefs.GetInt("Resource0"), PlayerPrefs.GetInt("Resource1"), PlayerPrefs.GetInt("Resource2")); DeleteAll("StructureTile"); StructureData[] data = SaveSystem.LoadStructures().data; foreach (StructureData structure in data) { //print ("name " + structure.name); Vector2 structurePosition = new Vector2(structure.position[0], structure.position[1]); // GameObject go = GameObject.Find("SceneManager"); ObjectPairList other = this.GetComponent(typeof(ObjectPairList)) as ObjectPairList; string nameToReturn = structure.name; GameObject loadedObject; //Debug.Log (nameToReturn); if (nameToReturn.EndsWith("(Clone)")) { //Debug.Log(nameToReturn.Split('(')[0].Trim()); loadedObject = other.returnGameObject(nameToReturn.Split('(') [0].Trim()); } else { loadedObject = other.returnGameObject(nameToReturn); } //Modified if (structure.duration > 0) { loadedObject = other.returnGameObject("ConstructionSite"); } GameObject instantiatedObject = Instantiate(loadedObject, structurePosition, Quaternion.identity); StructureInfo script = instantiatedObject.GetComponent <StructureInfo> (); script.X = (int)structurePosition.x; script.Y = (int)structurePosition.y; script.Name = structure.name; script.Level = structure.level; script.Duration = structure.duration; } GameManager.instance.Invoke("updateStructureState", 0.1f); //ship part ShipsBuildingData allShips = SaveSystem.LoadShips(); GameManager.instance.setShipsInProgress(allShips.shipsInProgress); GameManager.instance.setFinishedShips(allShips.finishedShips); }
private void spawnObject() { ObjectPairList objPairList = GameObject.Find("SceneManager").GetComponent(typeof(ObjectPairList)) as ObjectPairList; StructureInfo constructionInfo = this.GetComponent <StructureInfo> (); //Debug.Log("script.Name:" + script.Name + ";;" + script.name); GameObject loadedObject = objPairList.returnGameObject(constructionInfo.Name); Vector2 structurePosition = new Vector2(constructionInfo.X, constructionInfo.Y); //Debug.Log("loadedObject:" + loadedObject.name); GameObject instantiatedObject = Instantiate(loadedObject, structurePosition, Quaternion.identity); StructureInfo structureInfo = instantiatedObject.GetComponent <StructureInfo> (); structureInfo.X = (int)structurePosition.x; structureInfo.Y = (int)structurePosition.y; //script.name = structure.name; structureInfo.Level = constructionInfo.Level; Destroy(gameObject); GameManager.instance.Invoke("updateStructureState", 1f); }