public void LoadAllInfoFromBinary() { string path = Application.dataPath + "/Resources/MyData.txt"; SerializableInfoClass serializableInfoClass = LoadBinaryDataFromDisk <SerializableInfoClass>(path); for (int i = 0; i < serializableInfoClass.myList.Count; i++) { VectorSerialized pos = serializableInfoClass.myList[i].GetMyPos(); VectorSerialized rot = serializableInfoClass.myList[i].GetMyRotation(); VectorSerialized velo = serializableInfoClass.myList[i].getMyVelo(); VectorSerialized angularVelo = serializableInfoClass.myList[i].getMyAngularVelo(); VectorSerialized colour = serializableInfoClass.myList[i].getMyColour(); GameObject newObj = Instantiate(items[serializableInfoClass.myList[i].getObjId()]) as GameObject; Rigidbody rb = newObj.GetComponent <Rigidbody>(); Material mat = newObj.GetComponent <Material>(); /*Color col = new Color(); * col.r = colour.x; * col.g = colour.y; * col.b = colour.z;*/ newObj.transform.position = new Vector3(pos.x, pos.y, pos.z); newObj.transform.eulerAngles = new Vector3(rot.x, rot.x, rot.z); rb.angularVelocity = new Vector3(angularVelo.x, angularVelo.y, angularVelo.z); rb.velocity = new Vector3(velo.x, velo.y, velo.z); // mat.color = col; listOfGameObj.Add(newObj); } }
//public T LoadJsonDataFromDisk<T>(string filePath) //{ // T toRet; // string path = filePath; // if (File.Exists(path)) // { // string jsonString = File.ReadAllText(path); // //FileStream file = File.Open(path, FileMode.Open); // toRet = (T)jsonString; // //file.Close(); // } // else // toRet = default(T); // return toRet; //} public void LoadFromJson() { string jsonString; string path = Application.dataPath + "/Resources/MyJsonData.json"; jsonString = File.ReadAllText(path); SerializableInfoClass serializableInfoClass = (SerializableInfoClass)JsonUtility.FromJson(jsonString, typeof(SerializableInfoClass)); for (int i = 0; i < serializableInfoClass.myList.Count; i++) { VectorSerialized pos = serializableInfoClass.myList[i].GetMyPos(); VectorSerialized rot = serializableInfoClass.myList[i].GetMyRotation(); VectorSerialized velo = serializableInfoClass.myList[i].getMyVelo(); VectorSerialized angularVelo = serializableInfoClass.myList[i].getMyAngularVelo(); VectorSerialized colour = serializableInfoClass.myList[i].getMyColour(); GameObject newObj = Instantiate(items[serializableInfoClass.myList[i].getObjId()]) as GameObject; Rigidbody rb = newObj.GetComponent <Rigidbody>(); Material mat = newObj.GetComponent <MeshRenderer>().material; Color col = new Color(); col.r = colour.x; col.g = colour.y; col.b = colour.z; newObj.transform.position = new Vector3(pos.x, pos.y, pos.z); newObj.transform.eulerAngles = new Vector3(rot.x, rot.x, rot.z); rb.angularVelocity = new Vector3(angularVelo.x, angularVelo.y, angularVelo.z); rb.velocity = new Vector3(velo.x, velo.y, velo.z); mat.color = col; listOfGameObj.Add(newObj); } //} }