CustomAssets
Askowl Custom Assets
TriggerDriver.cs
1 // Copyright 2018 (C) paul@marrington.net http://www.askowl.net/unity-packages
2 
3 using Askowl;
4 using UnityEditor;
5 using UnityEngine;
6 using UnityEngine.Events;
7 
8 namespace CustomAsset.Mutable {
9  /// <a href="http://bit.ly/2QNmw2q">Trigger a component function directly from a custom asset</a> <inheritdoc />
11  [SerializeField] private UnityEvent componentValueToSet = default;
12 
13  /// <a href="http://bit.ly/2QNmw2q">On a change the listener needs a copy of the changed data to react to</a>
14  protected override void OnChange(Emitter emitter) => componentValueToSet.Invoke();
15 
16  #if UNITY_EDITOR
17  [MenuItem("Component/CustomAssets/Trigger Driver")] private static void AddConnector() =>
18  Selection.activeTransform.gameObject.AddComponent<TriggerDriver>();
19  #endif
20  }
21 }
Common code for all event listener MonoBehaviours. It registers and deregisters the listener with the...
Trigger a component function directly from a custom asset