public void LoadIt() { if (System.IO.File.Exists(Application.dataPath + "SaveMesh.dat")) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.FileStream fs = new System.IO.FileStream(Application.dataPath + "SaveMesh.dat", System.IO.FileMode.Open); Serialize_Mesh Ser_Mesh = (Serialize_Mesh)bf.Deserialize(fs); myMesh = Ser_Mesh.Construct(); fs.Close(); filter.mesh = myMesh; filter.gameObject.GetComponent <Renderer> ().material = mat; filter.mesh.RecalculateNormals(); filter.mesh.RecalculateBounds(); filter.gameObject.GetComponent <MeshCollider> ().sharedMesh = filter.mesh; string path = Application.dataPath + "file.txt"; string tmp = System.IO.File.ReadAllText(path); string[] arr = tmp.Split(char.Parse(" ")); float r = float.Parse(arr[0]); float g = float.Parse(arr[1]); float b = float.Parse(arr[2]); float a = float.Parse(arr[3]); this.GetComponent <Renderer>().material.color = new Color(r, g, b, a); } else { Debug.Log("No file"); } }
public void SaveIt() { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.FileStream fs = new System.IO.FileStream(Application.dataPath + "SaveMesh.dat", System.IO.FileMode.Create); Serialize_Mesh Ser_Mesh = new Serialize_Mesh(filter.mesh); bf.Serialize(fs, Ser_Mesh); fs.Close(); float red = this.GetComponent <Renderer>().material.color.r; float green = this.GetComponent <Renderer>().material.color.g; float blue = this.GetComponent <Renderer>().material.color.b; float alpha = this.GetComponent <Renderer>().material.color.a; string mycolor = red + " " + green + " " + blue + " " + alpha; Debug.Log(mycolor + "......................................"); string path = Application.dataPath + "file.txt"; System.IO.File.WriteAllText(path, mycolor); }