// Methods public IEnumerator Start() { // Usually you should register replay prefabs in editor via the global settings but it can also be done via code if required UltimateReplay.Settings.prefabs.RegisterReplayablePrefab(instanitatePrefab); // Start recording - Note that we need to enable 'allowEmptyScene' if there are no replay objects in the scene initially ReplayHandle recordHandle = ReplayManager.BeginRecording(null, null, true, true); // Wait for some time to pass yield return(new WaitForSeconds(1f)); // Spawn a dynamic replay object ReplayObject obj = Instantiate(instanitatePrefab); // Add the object to all recording scenes - This is a required step otherwise the object will not be recorded ReplayManager.AddReplayObjectToRecordScenes(obj); // Wait for some time to pass now that the object has been spawned yield return(new WaitForSeconds(1)); // End recording // The resulting replay will have 1 second of nothing and then the dynamic object will be re-instantiated by the replay system ReplayManager.StopRecording(ref recordHandle); }
// Methods /// <summary> /// Called by Unity. /// </summary> public IEnumerator Start() { //ReplayFileTarget file = ReplayFileTarget.CreateReplayFile("StressTest.replay"); //ReplayHandle handle = ReplayManager.BeginRecording(file, null, true, true); // Start delay yield return(new WaitForSeconds(1)); Transform setParent = parent; if (setParent == null) { // Keep the hierarchy clean with a filter object GameObject root = new GameObject("DemoCubes"); // Store the transform setParent = root.transform; } for (int i = 0; i < spawnAmount; i++) { // Select a random location Vector3 pos = randomPosition(); Quaternion rot = randomRotation(); // Select a random prefab int index = Random.Range(0, spawnCubes.Length); // Spawn a cube GameObject result = Instantiate(spawnCubes[index], pos, rot) as GameObject; // Add as a child object result.transform.SetParent(setParent); spawnedCubes.Add(result); // Add to replay ReplayManager.AddReplayObjectToRecordScenes(result.GetComponent <ReplayObject>()); // Give upwards velocity Rigidbody body = result.GetComponent <Rigidbody>(); if (body != null) { // Find a random direction Vector3 xzForce = new Vector3(Random.Range(-1, 1), 0, Random.Range(-1, 1)); xzForce *= 2; // Upwards force Vector3 upForce = Vector3.up * explosiveForce; // Apply force body.AddForce(xzForce + upForce, ForceMode.Impulse); } // Wait for next frame yield return(null); } float time = Time.time; //while(Time.time < (time + 3600)) //{ // // Wait 6 seconds // yield return new WaitForSeconds(6f); // // Add impulse to all objects // foreach(GameObject go in spawnedCubes) // { // // Give upwards velocity // Rigidbody body = go.GetComponent<Rigidbody>(); // if (body != null) // { // // Find a random direction // Vector3 xzForce = new Vector3(Random.Range(-1, 1), 0, Random.Range(-1, 1)); // xzForce *= 2; // // Upwards force // Vector3 upForce = Vector3.up * explosiveForce; // // Apply force // body.AddForce(xzForce + upForce, ForceMode.Impulse); // } // yield return null; // } //} //ReplayManager.StopRecording(ref handle); //Debug.Log("Replay stress test has finished"); }