public void Save() { Type[] types = { typeof(ObjectDataList), typeof(ObjectData) }; XmlSerializer xml = new XmlSerializer(typeof(GameData), types); FileStream file; if (File.Exists(Application.persistentDataPath + "/gameData.xml")) { file = File.Open(Application.persistentDataPath + "/gameData.xml", FileMode.Truncate); } else { file = File.Create(Application.persistentDataPath + "/gameData.xml"); } GameData data = new GameData(); data.tutorialComplete = tutorialComplete; if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("SuckerSandbox")) { activeObjects = new ObjectDataList(); GameObject[] objects = GameObject.FindGameObjectsWithTag("created"); foreach (GameObject obj in objects) { if (obj.GetComponent <CreatableObject>().id != null && obj.GetComponent <CreatableObject>().id != "") { ObjectData objectData = new ObjectData(); objectData.id = obj.GetComponent <CreatableObject>().id; objectData.mat = obj.GetComponent <CreatableObject>().matKey; Transform trans = obj.GetComponent <Transform>(); objectData.xPos = trans.position.x; objectData.yPos = trans.position.y; objectData.zPos = trans.position.z; objectData.xRot = trans.rotation.x; objectData.yRot = trans.rotation.y; objectData.zRot = trans.rotation.z; objectData.w = trans.rotation.w; objectData.xScale = trans.localScale.x; objectData.yScale = trans.localScale.y; objectData.zScale = trans.localScale.z; objectData.isFrozen = (float)obj.GetComponent <Rigidbody>().constraints; activeObjects.Add(objectData); } } } data.objectList = activeObjects; xml.Serialize(file, data); file.Close(); }
public virtual int AddToCache(int dataInDocType, object entity, bool isDelete, string[] propertys) { if (_ObjectDataList == null) { _ObjectDataList = new ObjectDataList(); } ObjectDataInfo dataInfo = new ObjectDataInfo(ConvertDataInDocType(dataInDocType), entity); dataInfo.SavePropertys = propertys; //dataInfo.DataState = ObjectDataState.Added; if (isDelete) { dataInfo.DataState = ObjectDataState.Deleted; if (entity.GetType().IsSubclassOf(typeof(MB.Orm.Common.BaseModel))) { (entity as MB.Orm.Common.BaseModel).EntityState = EntityState.Deleted; } } _ObjectDataList.Add(dataInfo); return(1); }