5.5sec vs 0.1sec
public class StaticCounterExampleFixed : MonoBehaviour {
static int counter = 0;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Init() {
counter = 0;
}
}
var isInFastMode = EditorSettings
.enterPlayModeOptionsEnabled;
if (isInFastMode) {
if (GUILayout.Button(new GUIContent("SPEED"), _ButtonStylesEnabled)) {
EditorSettings.enterPlayModeOptionsEnabled
= false;
EditorSettings.enterPlayModeOptions
= EnterPlayModeOptions.None;
}
}
else {
if (GUILayout.Button(new GUIContent("SPEED"), _ButtonStylesDisabled)) {
EditorSettings.enterPlayModeOptionsEnabled
= true;
EditorSettings.enterPlayModeOptions
= EnterPlayModeOptions.DisableDomainReload;
}
}
... more on that later
Don't leave saving later
public class Foo : MonoBehaviour {
ISomeService _Service;
public void Init(ISomeService service) {
_Service = service;
}
public void DoSomething() {
_Service.PerformTask();
}
}
...
foo.Init(new Service());
public class TestInstaller : MonoInstaller {
public override void InstallBindings() {
Container
.Bind<ISomeService>().FromInstance(new Service());
}
}
public class Foo : MonoBehaviour {
[Inject]
ISomeService _Service;
public void DoSomething() {
_Service.PerformTask();
}
}
public class Context : ScriptableObject {
public ISomeService Service => _Service ??= new Service();
private ISomeService _Service;
}
public class Foo : MonoBehaviour {
[SerializeField]
Context _Context;
public void DoSomething() {
_Context.Service.PerformTask();
}
}
public class Foo : MonoBehaviour {
Context Context =>
_Context ??= Resources.Load<Context>("context");
Context _Context;
public void DoSomething() {
Context.Service.PerformTask();
}
}
[InitializeOnLoadAttribute]
public static class BootLoader {
static BootLoader() {
EditorApplication.playModeStateChanged += (nState) => {
if (nState != PlayModeStateChange.ExitingEditMode)
return;
EditorPrefs.SetString(
KEY_RETURN_TO_SCENE,
EditorSceneManager.GetActiveScene().name);
var bootScene = AssetDatabase
.LoadAssetAtPath<SceneAsset>($"Boot.unity");
EditorSceneManager.playModeStartScene = bootScene;
};
}
}
private void Load() {
var returnScene = EditorPrefs
.GetString(KEY_RETURN_TO_SCENE, null);
EditorPrefs.SetString(KEY_RETURN_TO_SCENE, null);
if (returnScene != null) {
EditorSceneManager.LoadScene(
returnScene,
LoadSceneMode.Additive);
}
}
Every referenced prefab is loaded