导入odin
This commit is contained in:
17
Assets/Obvious/Soap/Core/Runtime/Save/IReset.cs
Normal file
17
Assets/Obvious/Soap/Core/Runtime/Save/IReset.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Obvious.Soap
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for objects that can be reset to their initial value.
|
||||
/// </summary>
|
||||
public interface IReset
|
||||
{
|
||||
void ResetValue();
|
||||
#if UNITY_EDITOR
|
||||
void OnPlayModeStateChanged(PlayModeStateChange playModeStateChange);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/Obvious/Soap/Core/Runtime/Save/IReset.cs.meta
Normal file
11
Assets/Obvious/Soap/Core/Runtime/Save/IReset.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2f1a089b4a201e4fa8fb2d1d643b06b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obvious.Soap
|
||||
{
|
||||
public abstract class ResettableScriptableObject : ScriptableObject
|
||||
{
|
||||
protected string _cachedJson;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
|
||||
}
|
||||
|
||||
protected virtual void OnPlayModeStateChanged(PlayModeStateChange playModeStateChange)
|
||||
{
|
||||
if (playModeStateChange == PlayModeStateChange.ExitingEditMode)
|
||||
{
|
||||
CacheState();
|
||||
}
|
||||
else if (playModeStateChange == PlayModeStateChange.EnteredEditMode)
|
||||
{
|
||||
ResetValue();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CacheState()
|
||||
{
|
||||
_cachedJson = EditorJsonUtility.ToJson(this, prettyPrint: true);
|
||||
}
|
||||
|
||||
[ContextMenu("Reset Value")]
|
||||
public virtual void ResetValue()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_cachedJson))
|
||||
{
|
||||
EditorJsonUtility.FromJsonOverwrite(_cachedJson, this);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc0665cf937e17746aab28f77136a40c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user