CustomAssets
Askowl Custom Assets
FloatDriver.cs
1 // Copyright 2018 (C) paul@marrington.net http://www.askowl.net/unity-packages
2 
3 using System;
4 using Askowl;
5 using UnityEditor;
6 using UnityEngine;
7 using UnityEngine.Events;
8 
9 namespace CustomAsset.Mutable {
10  /// <a href="http://bit.ly/2QQdUIt"></a> <inheritdoc />
11  public class FloatDriver : ListenerComponent {
12  /// <a href="http://bit.ly/2QQdUIt">Reference to the Asset we are listening to</a>
13  public Float Asset => Listener.AssetToMonitor as Float;
14 
15  [Serializable] private class FloatUnityEvent : UnityEvent<float> { }
16 
17  [SerializeField] private FloatUnityEvent componentValueToSet = default;
18 
19  /// <a href="http://bit.ly/2QQdUIt">On a change the listener needs a copy of the changed data to react to</a>
20  protected override void OnChange(Emitter emitter) => componentValueToSet.Invoke(Asset.Value);
21 
22  #if UNITY_EDITOR
23  [MenuItem("Component/CustomAssets/Float Driver")] private static void AddConnector() =>
24  Selection.activeTransform.gameObject.AddComponent<FloatDriver>();
25  #endif
26  }
27 }
virtual T Value
For safe(ish) access to the contents field
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
Float CustomAsset contains a float value which can be connected directly to OnValueChange callbacks i...
Definition: Mutable/Float.cs:9