Last active
June 20, 2017 06:57
-
-
Save tsubaki/6bacf17a930e686722a9cecdc4900344 to your computer and use it in GitHub Desktop.
ゲーム再生終了時にパラメータをリセットする(ゲーム開始時の値に戻す)ScriptableObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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