Class XmlSaveableComponent
All components that you wish to be saved and loaded in some way between runtimes should inherit from XmlSaveableComponent in order to provide functionality for object persistance/reconstruction.
If you want to use the Awake and OnDestroy methods in XmlSaveableComponents, please use the
override keyword and call base.Awake(); and/or base.OnDestroy();.All XmlSaveableComponents have the
[ExecuteInEditMode] attribute; therefore if you encounter unwanted behaviour due to MonoBehaviour methods being called at edit time, consider adding: if (!Application.isPlaying) return;
Namespace: GlitchedPolygons.SavegameFramework.Xml
Assembly: UnityScriptsLibrary.dll
Syntax
public abstract class XmlSaveableComponent : SaveableComponent
Properties
| Improve this Doc View SourceID
The XmlSaveableComponent's ID. This is a unique identifier that should be immutable and persistent.
Declaration
public override int ID { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Overrides
Methods
| Improve this Doc View SourceAfterLoading()
This is called after a successful Load(String).
Child classes should implement this and define what happens after the Load(String) fed the stored data into this class (e.g. if a SaveableComponent's
Transform.position is stored in the savegame, this would be the place to then take that value and load it back into the Transform).
Declaration
public abstract override void AfterLoading()
Overrides
| Improve this Doc View SourceAwake()
Declaration
protected virtual void Awake()
BeforeSaving()
This is called by the SavegameManager implementation before saving this instance's data out to the savegame.
Use this to sync up any data if you need (e.g. loading Unity component data - which is NOT serialized alongside automatically; keep that in mind! - into some field on the savegame like for example a "Vector3 positionCoordinates;" or something like that, yea..)
Declaration
public abstract override void BeforeSaving()
Overrides
| Improve this Doc View SourceGetXml()
Gets the nicely formatted xml System.Xml.Linq.XElement containing all the data that is needed to reconstruct the saveable object through LoadXml(XElement).
Declaration
public abstract XElement GetXml()
Returns
| Type | Description |
|---|---|
| System.Xml.Linq.XElement | The |
LoadXml(XElement)
Loads an System.Xml.Linq.XElement (hopefully the one that was originally produced by the GetXml() method) into the class.
This method should reconstruct the object's state on load, and then return
true if the procedure was successful (false if it failed in some way).
Declaration
public abstract bool LoadXml(XElement xml)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Xml.Linq.XElement | xml | The |
Returns
| Type | Description |
|---|---|
| System.Boolean | Should return |
Remarks
This should NOT be used to make the SaveableComponent use the loaded data in any way: THIS IS JUST FOR LOADING DATA INTO THE CLASS FIELDS! Instead, use the AfterLoading() method for applying the loaded data (e.g. setting Transform positions and rotations and whatnot)!
OnDestroy()
Declaration
protected virtual void OnDestroy()
PrintID()
Declaration
protected void PrintID()