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. |
CreateAssetInActiveDirectory(String, Action<TContainer>)
Create a new asset instance saved to disk, in the active directory.
Declaration
public static TContainer CreateAssetInActiveDirectory(string assetName, Action<TContainer> mutator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | assetName | The asset file name with extension. |
| 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 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. |
IsModified()
Determine if there is unsaved modifications.
Declaration
public bool IsModified()
Returns
| Type | Description |
|---|---|
| Boolean | true if there is unsaved modifications, 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()
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. |