CustomAssets
Askowl Custom Assets
IntegerDriver.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/2QNmw2q"></a> <inheritdoc />
12  /// <a href="http://bit.ly/2QNmw2q">Reference to the Asset we are listening to</a>
13  public Integer Asset => Listener.AssetToMonitor as Integer;
14 
15  [Serializable] private class IntegerUnityEvent : UnityEvent<int> { }
16 
17  [SerializeField] private IntegerUnityEvent componentValueToSet = default;
18 
19  /// <a href="http://bit.ly/2QNmw2q">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/Integer Driver")] private static void AddConnector() =>
24  Selection.activeTransform.gameObject.AddComponent<IntegerDriver>();
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