Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 1.13 KB

README.md

File metadata and controls

38 lines (31 loc) · 1.13 KB

UnitySaveSystemSourceGenerator

Source generator using Roslyn used in Unity Save System. It generates code when the 'Save' attribute is present and analyses the code for misuse of this feature.

public partial class Example : MonoBehaviour
{
     [Save]
     public const string EXAMPLE_CONST = "This is a const string";

     [Save]
     public Guid ExampleGuid { get; set; } = Guid.NewGuid();

     [Save]
     private int _exampleValue;

     [Save]
     private void SetExampleValue(int value) => _exampleValue = value;

     private void Awake()
     {
          RegisterSaveObject();
     }
}

// Auto generated code.
public partial class Example
{
     /// ... ///
     protected void RegisterSaveObject()
     {
          global::Celezt.SaveSystem.SaveSystem.GetEntryKey(this)
               .SetSubEntry("example_const", () => EXAMPLE_CONST)
               .SetSubEntry("example_guid", () => ExampleGuid, value => ExampleGuid = (Guid)value)
               .SetSubEntry("example_value", () => _exampleValue, value => SetExampleValue((int)value));
     }
}