CustomAssets
Askowl Custom Assets
StringDriver.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">Drive component string values directly from a custom asset</a> <inheritdoc />
12  /// <a href="http://bit.ly/2QNmw2q">Reference to the Asset we are listening to</a>
13  public string Asset => Listener.AssetToMonitor.ToString();
14 
15  [Serializable] private class StringUnityEvent : UnityEvent<string> { }
16 
17  [SerializeField] private StringUnityEvent 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);
21 
22  #if UNITY_EDITOR
23  [MenuItem("Component/CustomAssets/String Driver")] private static void AddConnector() =>
24  Selection.activeTransform.gameObject.AddComponent<StringDriver>();
25  #endif
26  }
27 }
WithEmitter AssetToMonitor
Used to classes that have a listener can get back the Custom Asset that triggered it ...
Definition: Listener.cs:25
Drive component string values directly from a custom asset
Definition: StringDriver.cs:11
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