I have been developing a level editor and I want to add in a feature that detects changes made, so if you try to close out, open a new level, etc, it will prompt you to save any changes. While you may suggest to simply ask you every time you try to close, open a new level, etc, if you want to save, I may need this feature else where in my current project.
So simply put, does anyone know how to detect any and all changes made in a scene, whether that be adding in new gameobjects, changing different options, etc.
this doesnt detect the changes itself, it just turns on the unsaved changes marker. Even when no changes where made
Have a look at the event system:
Add a ‘I have changed’ event handler then fire this event in the Update of each editable object (e.g. detect that the transform.Position has changed since the last Update - this logic could be placed into a common script used by all objects which are movable for instance). This event can be picked up by your editor class to set an ‘I need updating’ flag. This puts the onus of what needs to be changed on each object rather than the editor itself which should only really be concerned with loading/saving the level and other ‘high level things’.
public interface IEditorMessages: IEventSystemHandler
/// Something was moved
In the script attached to the editable object:
ExecuteEvents.Execute<IEditorMessages>(this.gameObject, null, (x1, y1) => x1.ObjectMoved());
The implementation of ObjectMoved in the editor class:
this.changesMade = true;