From 0022e0d61d679e22003c3eaef05540441d8bbc6f Mon Sep 17 00:00:00 2001 From: Neil Sarkar Date: Tue, 13 Oct 2020 08:36:29 -0700 Subject: [PATCH] Make all magic methods in StateMonoBehaviour overridable --- Runtime/RenderShortcut.cs | 2 +- Runtime/StateMonoBehaviour.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Runtime/RenderShortcut.cs b/Runtime/RenderShortcut.cs index 456f771..575e073 100644 --- a/Runtime/RenderShortcut.cs +++ b/Runtime/RenderShortcut.cs @@ -11,7 +11,7 @@ public static class RenderShortcut { [Shortcut("VioletRenderShortcut", KeyCode.Semicolon, ShortcutModifiers.Action)] public static void Press() { - Violet.LogVerbose("Rendering from shortcut press"); + Violet.Log("Rendering from shortcut press"); OnPress?.Invoke(); } } diff --git a/Runtime/StateMonoBehaviour.cs b/Runtime/StateMonoBehaviour.cs index f62b538..44ed78d 100644 --- a/Runtime/StateMonoBehaviour.cs +++ b/Runtime/StateMonoBehaviour.cs @@ -45,19 +45,17 @@ public abstract class ChildView : ChildView { protected override Dispatcher Dispatcher => Singleton?.Dispatcher; } - void Awake() { + protected virtual void Awake() { Singleton = this; CopyState(); } #if UNITY_EDITOR - void OnValidate() { + protected virtual void OnValidate() { Render(); } - void Update() { - if (Application.isPlaying) { return; } - + protected virtual void Update() { RenderShortcut.OnPress -= Render; RenderShortcut.OnPress += Render; Singleton = this; @@ -66,10 +64,11 @@ void Update() { protected override void OnDestroy() { base.OnDestroy(); RenderShortcut.OnPress -= Render; + Singleton = null; } [Button("Render (shortcut: cmd+;)"), GUIColor(Violet.r, Violet.g, Violet.b)] - void Render() { + protected void Render() { if (State == null) { Violet.LogWarning($"state is null for {name}"); return;