CustomAssets
Askowl Custom Assets
DriverComponent.cs
1 // Copyright 2018 (C) paul@marrington.net http://www.askowl.net/unity-packages
2 
3 using Askowl;
4 using UnityEngine;
5 
6 namespace CustomAsset.Mutable {
7  /// <a href="http://bit.ly/2QNmw2q">Common code for all event listener MonoBehaviours. It registers and deregisters the listener with the channel</a> <inheritdoc />
8  public abstract class DriverComponent<T> : ListenerComponent where T : Base {
9  /// <a href="http://bit.ly/2QNmw2q">Reference to the Asset we are listening to</a>
10  public T Asset => Listener.AssetToMonitor as T;
11  }
12 
13  /// <a href="http://bit.ly/2QNmw2q">Common code for all event listener MonoBehaviours. It registers and deregisters the listener with the channel</a> <inheritdoc cref="MonoBehaviour" />
14  public abstract class ListenerComponent : MonoBehaviour {
15  [SerializeField] private Listener listener = default;
16 
17  /// <a href="http://bit.ly/2QNmw2q">Retrieve a reference to the listener attached to this component</a>
18  public Listener Listener => listener;
19 
20  private void OnEnable() => listener.Register(OnChange);
21 
22  private void OnDisable() => Deregister();
23 
24  /// <a href="http://bit.ly/2QNmw2q">Stop listening to changes in the custom asset</a>
25  public void Deregister() => listener.Deregister();
26 
27  /// <a href="http://bit.ly/2QNmw2q">After we have ensured the change is for the expected member, tell interested parties</a>
28  protected abstract void OnChange(Emitter emitter);
29  }
30 }
WithEmitter AssetToMonitor
Used to classes that have a listener can get back the Custom Asset that triggered it ...
Definition: Listener.cs:25
Common code for all event listener MonoBehaviours. It registers and deregisters the listener with the...
Common code for all event listeners. It registers and deregisters the listener with the channel ...
Definition: Listener.cs:9
Base class for all custom assets - implementing initialisation
Definition: Base.cs:8
void Deregister()
Call to stop receiving change calls
void Register(Emitter.Action actionOnTriggered)
Register an action so that if the custom asset member changes anyone can be told
Definition: Listener.cs:28
Common code for all event listener MonoBehaviours. It registers and deregisters the listener with the...