示例#1
0
    public void Save()
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(Application.persistentDataPath + "/OHObject.dat",
                                         FileMode.OpenOrCreate);

        List <OHObjectData> datas = new List <OHObjectData> ();

        foreach (GameObject ohGameObject in ohObjects)
        {
            OHObjectData data = new OHObjectData();
            data.positionX = ohGameObject.transform.position.x;
            data.positionY = ohGameObject.transform.position.y;
            data.positionZ = ohGameObject.transform.position.z;
            data.size      = ohGameObject.transform.localScale.x;

            OHobject ohObject = (OHobject)ohGameObject.GetComponent(typeof(OHobject));
            data.objectName = ohObject.ItemName;
            datas.Add(data);
        }

        bf.Serialize(file, datas);
        file.Close();

        Debug.Log("Saved " + datas.Count + " dataobjects");
    }
示例#2
0
    public void Save() {
		BinaryFormatter bf = new BinaryFormatter();
		FileStream file = File.Open(Application.persistentDataPath + "/OHObject.dat",
		                            FileMode.OpenOrCreate);

		List<OHObjectData> datas = new List<OHObjectData> ();

		foreach(GameObject ohGameObject in ohObjects){
			OHObjectData data = new OHObjectData();
			data.positionX = ohGameObject.transform.position.x;
			data.positionY = ohGameObject.transform.position.y;
			data.positionZ = ohGameObject.transform.position.z;
			data.size = ohGameObject.transform.localScale.x;

			OHobject ohObject = (OHobject) ohGameObject.GetComponent(typeof(OHobject));
			data.objectName = ohObject.ItemName;
			datas.Add(data);
		}
		
		bf.Serialize(file, datas);
		file.Close();

		Debug.Log("Saved " + datas.Count + " dataobjects");
	}