Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ゲーム再生終了時にパラメータをリセットする(ゲーム開始時の値に戻す)ScriptableObject
using UnityEngine;
public class ResettableScriptableObject : ScriptableObject
{
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void CallBeforPlayScene()
{
// recently, unity editor will crash
// recommend SaveProject before playing
// UnityEditor.AssetDatabase.SaveAssets ();
}
#endif
protected virtual void OnEnable()
{
#if UNITY_EDITOR
if( UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode == true ){
UnityEditor.EditorApplication.playmodeStateChanged += () => {
if( UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode == false) {
Resources.UnloadAsset(this);
}
};
}
#endif
}
}
[CreateAssetMenu]
public class sample : ResettableScriptableObject
{
[SerializeField] int count;
public void Add()
{
count++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment