-
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CrestComponent to abstract boilerplate
- Loading branch information
Showing
4 changed files
with
55 additions
and
36 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
crest/Assets/Crest/Crest/Scripts/Helpers/CrestComponent.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Crest Ocean System | ||
|
||
// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE) | ||
|
||
// Base class for MonoBehaviours. | ||
|
||
using UnityEngine; | ||
|
||
namespace Crest | ||
{ | ||
public abstract class CrestComponent : MonoBehaviour | ||
{ | ||
public virtual void OnEnable() | ||
{ | ||
// Delayed initialisation. | ||
if (OceanRenderer.Instance == null) | ||
{ | ||
OceanRenderer.OnOceanRendererEnabled -= OnOceanRendererEnabled; | ||
OceanRenderer.OnOceanRendererEnabled += OnOceanRendererEnabled; | ||
enabled = false; | ||
} | ||
} | ||
|
||
void OnOceanRendererEnabled() => enabled = true; | ||
|
||
void OnDestroy() | ||
{ | ||
// We need this event registered even when this component is disabled. So we unregister only when the | ||
// component is destroyed. | ||
OceanRenderer.OnOceanRendererEnabled -= OnOceanRendererEnabled; | ||
} | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
crest/Assets/Crest/Crest/Scripts/Helpers/CrestComponent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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