/// <summary>
        /// Called by Unity.
        /// </summary>
        public void OnValidate()
        {
            // Allow inspector values to be modified at runtime
            recordStepTimer.Interval = (1.0f / recordFPS);

            // Update prefab links
            if (Application.isPlaying == false)
            {
                // Check for valid array
                if (prefabs != null)
                {
                    // Process all prefabs
                    foreach (GameObject go in prefabs)
                    {
                        if (go != null)
                        {
                            // Find the object component
                            ReplayObject obj = go.GetComponent <ReplayObject>();

                            // Make sure the prefab link is updated
                            if (obj != null)
                            {
                                obj.UpdatePrefabLinks();
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        // Methods
        /// <summary>
        /// Called by Unity while in editor mode.
        /// Allows the unique id to be generated when the script is attached to an object.
        /// </summary>
        public virtual void Reset()
        {
            // Generate the unique id if required - This is requried for objects instantiated during replay
            //replayIdentity.Generate();

            // Try to find a parent replay object or create one if required
#if UNITY_EDITOR
            // Check for ignored components
            if (GetType().IsDefined(typeof(ReplayIgnoreAttribute), true) == true)
            {
                return;
            }

            ReplayObject manager = GetManagingObject();

            // Create a manager component
            if (manager == null)
            {
                manager = Undo.AddComponent <ReplayObject>(gameObject);
            }

            // Force rebuild the component list
            if (manager != null)
            {
                manager.RebuildComponentList();
            }
#endif
        }
        /// <summary>
        /// Attempts to register a game object as a prefab so that the replay system is able to spawn or despawn the object as needed.
        /// You only need to do this for objects that are likley to be either instantiated or destroyed during recording.
        /// The replay system will then be able to accuratley restore the scene state during playback.
        /// The specified object must be a prefab otherwise an error will be thrown and the object will not be registered.
        /// Prefab instances are not accepted.
        /// </summary>
        /// <param name="prefab">The prefab object to register with the replay system</param>
        public static void RegisterReplayPrefab(GameObject prefab)
        {
            // Make sure we have a replay manager
            if (prefab == null || Instance == null)
            {
                return;
            }

            // Get the replay prefab component
            ReplayObject component = prefab.GetComponent <ReplayObject>();

            // Check for component
            if (component == null)
            {
                Debug.LogWarning(string.Format("Prefab '{0}' cannot be registered for replay because it does not have a 'ReplayObject' component attached to it", prefab.name));
                return;
            }

            // Check for no prefab
            if (component.IsPrefab == false)
            {
                Debug.LogWarning(string.Format("Object '{0}' cannot be registered as a replay prefab because it is not a prefab object", prefab.name));
                return;
            }

            // Register the prefab
            if (Instance.replayPrefabs.Contains(component) == false)
            {
                Instance.replayPrefabs.Add(component);
            }
        }
Example #4
0
 internal static void CallReplaySpawnedEvents(ReplayObject spawnedObject, Vector3 position, Quaternion rotation)
 {
     // Find all replay behaviours on the target object
     foreach (ReplayBehaviour behaviour in spawnedObject.GetComponentsInChildren <ReplayBehaviour>())
     {
         try
         {
             // Call the spawned method - catch any exceptions so that all behaviours will always receive the event
             behaviour.OnReplaySpawned(position, rotation);
         }
         catch (Exception e)
         {
             // Log the exception to the console
             Debug.LogException(e);
         }
     }
 }
Example #5
0
        private ReplayObject GetManagingObject()
        {
            ReplayObject manager = null;

            Transform current = transform;

            do
            {
                // Check for a replay object to manage this component
                if (current.GetComponent <ReplayObject>() != null)
                {
                    // Get the manager object
                    manager = current.GetComponent <ReplayObject>();
                    break;
                }

                // Look higher in the hierarchy
                current = current.parent;
            }while (current != null);

            // Get the manager
            return(manager);
        }