static void GetReflectionAccessForInspector(OscMonoBase oscBase, UnityAction <OscMessage> method, ref object inspectorMessageEventObject) { if (_inspectorMessageEventInfo == null) { _inspectorMessageEventInfo = typeof(OscMonoBase).GetField("_inspectorMessageEvent", BindingFlags.NonPublic | BindingFlags.Instance); } if (_addListenerInfo == null) { _addListenerInfo = typeof(UnityEventBase).GetMethod("AddListener", BindingFlags.NonPublic | BindingFlags.Instance); } if (_removeListenerInfo == null) { _removeListenerInfo = typeof(UnityEventBase).GetMethod("RemoveListener", BindingFlags.NonPublic | BindingFlags.Instance); } if (inspectorMessageEventObject == null) { inspectorMessageEventObject = _inspectorMessageEventInfo.GetValue(oscBase); } }
public static void RemoveInspectorMessageListener(OscMonoBase oscBase, UnityAction <OscMessage> method, ref object inspectorMessageEventObject) { GetReflectionAccessForInspector(oscBase, method, ref inspectorMessageEventObject); _removeListenerInfo.Invoke(inspectorMessageEventObject, new object[] { method.Target, method.Method }); }