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); } //} }
public void SpwanRendomObjects() { randomObject = Random.Range(items.Length, items.Length); for (int i = 0; i < Random.Range(10, RandomSpawnCount); i++) { float randX = Random.Range(-groundSize.transform.localScale.x / 2, groundSize.transform.localScale.x / 2); float randY = groundSize.transform.position.y; float randZ = Random.Range(-groundSize.transform.localScale.z / 2, groundSize.transform.localScale.z / 2); VectorSerialized pos = new VectorSerialized(randX, randY, randZ); Vector3 myPos = new Vector3(pos.x, pos.y, pos.z); int id = Random.Range(0, 3); GameObject objToSpawn = items[id]; GameObject a = Instantiate(objToSpawn, new Vector3(randX, randY, randZ), Quaternion.identity); a.GetComponent <Renderer>().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f); a.name = id.ToString(); listOfGameObj.Add(a); } }