Skip to content

Commit

Permalink
Make all magic methods in StateMonoBehaviour overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsarkar committed Oct 13, 2020
1 parent 929dae9 commit 0022e0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Runtime/RenderShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
11 changes: 5 additions & 6 deletions Runtime/StateMonoBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,17 @@ public abstract class ChildView<T> : ChildView<TState, T> {
protected override Dispatcher<TState> 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;
Expand All @@ -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;
Expand Down

0 comments on commit 0022e0d

Please sign in to comment.