Class ScriptableObjectPropertyContainer<TContainer>
Provides the necessary implementation to use properties and serialization with a TContainer
.
Namespace: Unity.Build
Syntax
[Serializable]
public abstract class ScriptableObjectPropertyContainer<TContainer> : ScriptableObject, ISerializationCallbackReceiver where TContainer : ScriptableObjectPropertyContainer<TContainer>
Type Parameters
Name | Description |
---|---|
TContainer | The type of the container. |
Methods
CreateAsset(String, Action<TContainer>)
Create a new asset instance saved to disk.
Declaration
public static TContainer CreateAsset(string assetPath, Action<TContainer> mutator = null)
Parameters
Type | Name | Description |
---|---|---|
String | assetPath | The location where to create the asset. |
Action<TContainer> | mutator | Optional mutator that can be used to modify the asset. |
Returns
Type | Description |
---|---|
TContainer | The new asset instance. |
CreateInstance(Action<TContainer>)
Create a new asset instance.
Declaration
public static TContainer CreateInstance(Action<TContainer> mutator = null)
Parameters
Type | Name | Description |
---|---|---|
Action<TContainer> | mutator | Optional mutator that can be used to modify the asset. |
Returns
Type | Description |
---|---|
TContainer | The new asset instance. |
DeserializeFromJson(TContainer, String)
Deserialize from a JSON String into the container.
Declaration
public static bool DeserializeFromJson(TContainer container, string json)
Parameters
Type | Name | Description |
---|---|---|
TContainer | container | The container to deserialize into. |
String | json | The JSON string to deserialize from. |
Returns
Type | Description |
---|---|
Boolean | true if the operation is successful, false otherwise. |
DeserializeFromPath(TContainer, String)
Deserialize from a file into the container.
Declaration
public static bool DeserializeFromPath(TContainer container, string path)
Parameters
Type | Name | Description |
---|---|---|
TContainer | container | The container to deserialize into. |
String | path | The file path to deserialize from. |
Returns
Type | Description |
---|---|
Boolean | true if the operation is successful, false otherwise. |
DeserializeFromStream(TContainer, Stream)
Deserialize from a stream into the container.
Declaration
public static bool DeserializeFromStream(TContainer container, Stream stream)
Parameters
Type | Name | Description |
---|---|---|
TContainer | container | The container to deserialize into. |
Stream | stream | The stream to deserialize from. |
Returns
Type | Description |
---|---|
Boolean | true if the operation is successful, false otherwise. |
LoadAsset(GUID)
Load an asset from the specified asset
Declaration
public static TContainer LoadAsset(GUID assetGuid)
Parameters
Type | Name | Description |
---|---|---|
GUID | assetGuid | The asset |
Returns
Type | Description |
---|---|
TContainer | The loaded asset if successful, null otherwise. |
LoadAsset(String)
Load an asset from the specified asset path.
Declaration
public static TContainer LoadAsset(string assetPath)
Parameters
Type | Name | Description |
---|---|---|
String | assetPath | The asset path to load from. |
Returns
Type | Description |
---|---|
TContainer | The loaded asset if successful, null otherwise. |
OnAfterDeserialize()
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
Declaration
public void OnBeforeSerialize()
OnEnable()
Declaration
public void OnEnable()
Reset()
Reset this asset in preparation for deserialization.
Declaration
protected virtual void Reset()
RestoreAsset()
Restore this asset from disk.
Declaration
public bool RestoreAsset()
Returns
Type | Description |
---|---|
Boolean | true if the operation is successful, false otherwise. |
Sanitize()
Sanitize this asset after deserialization.
Declaration
protected virtual void Sanitize()
SaveAsset(String)
Save this asset to disk. If no asset path is provided, asset is saved at its original location.
Declaration
public bool SaveAsset(string assetPath = null)
Parameters
Type | Name | Description |
---|---|---|
String | assetPath | Optional file path where to save the asset. |
Returns
Type | Description |
---|---|
Boolean | true if the operation is successful, false otherwise. |
SerializeToJson()
Serialize this container to a JSON String.
Declaration
public string SerializeToJson()
Returns
Type | Description |
---|---|
String | The container as a JSON String if the serialization is successful, null otherwise. |
SerializeToPath(String)
Serialize this container to a file.
Declaration
public void SerializeToPath(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | The file path to write into. |
SerializeToStream(Stream)
Serialize this container to a stream.
Declaration
public void SerializeToStream(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream the serialize into. |
Events
AssetChanged
Event invoked when the asset changed on disk.
Declaration
public static event Action<TContainer> AssetChanged
Event Type
Type | Description |
---|---|
Action<TContainer> |
JsonVisitorRegistration
Event invoked when the container registers
Declaration
public static event Action<JsonVisitor> JsonVisitorRegistration
Event Type
Type | Description |
---|---|
Action<JsonVisitor> |