using System.Collections; using System.Collections.Generic; using UnityEngine; public class SaveManager : MonoBehaviour { public List objType; public List objInstance; private int allObjectNum; private int currentId; //加载物品使用的变量 private string loadObjName; private int loadObjType; private Vector3 loadObjPos; private Vector3 loadObjAngle; private Vector3 loadObjScale; public void SaveAll() { print("aa"); GameObject[] allObject = GameObject.FindGameObjectsWithTag("canSave"); foreach (GameObject obj in allObject) { objInstance.Add(obj.GetComponent()); allObjectNum++; } SaveSystem.SetInt("AllSaveObjectNum",allObjectNum); foreach (SaveObject sobj in objInstance) { sobj.id = currentId; sobj.SaveObjMassage(); currentId++; } } public void LoadAll() { GameObject[] allObject = GameObject.FindGameObjectsWithTag("canSave"); foreach (GameObject obj in allObject) { Destroy(obj); } int loadObjectNum = SaveSystem.GetInt("AllSaveObjectNum"); for (int id = 0;id < loadObjectNum;id++) { loadObjType = SaveSystem.GetInt("Object" + id + "type"); loadObjName = SaveSystem.GetString("Object" + id + "name"); loadObjPos = SaveSystem.GetVector3("Object" + id + "pos"); loadObjAngle = SaveSystem.GetVector3("Object" + id + "angle"); loadObjScale = SaveSystem.GetVector3("Object" + id + "scale"); GameObject loadObj = Instantiate(objType[loadObjType]); //loadObj.name = loadObjName; loadObj.transform.position = loadObjPos; loadObj.transform.localEulerAngles = loadObjAngle; loadObj.transform.localScale = loadObjScale; print(loadObjType+" "+loadObjName); //GameObject loadObj = Instantiate(); } } }