Exemplo n.º 1
0
 public static void AddNewReaction(this SignalReceiver receiver, SignalAsset signalAsset)
 {
     if (signalAsset != null && receiver != null)
     {
         Undo.RecordObject(receiver, Styles.UndoAddReaction);
         var newEvent = new UnityEvent();
         newEvent.AddPersistentListener();
         var evtIndex = newEvent.GetPersistentEventCount() - 1;
         newEvent.RegisterVoidPersistentListenerWithoutValidation(evtIndex, receiver.gameObject, string.Empty);
         receiver.AddReaction(signalAsset, newEvent);
         PrefabUtility.RecordPrefabInstancePropertyModifications(receiver);
     }
 }
Exemplo n.º 2
0
        public static void AddNewReaction(this SignalReceiver receiver, SignalAsset signalAsset)
        {
            if (signalAsset != null && receiver != null)
            {
                Undo.RegisterCompleteObjectUndo(receiver, Styles.UndoAddReaction);

                var newEvent = new UnityEvent();
                newEvent.AddPersistentListener();
                var evtIndex = newEvent.GetPersistentEventCount() - 1;
                newEvent.RegisterVoidPersistentListenerWithoutValidation(evtIndex, receiver.gameObject, string.Empty);
                receiver.AddReaction(signalAsset, newEvent);
            }
        }
    public void AddSignalReciever()
    {
        m_signals = Resources.LoadAll(m_signalResourcePath, typeof(SignalAsset));

        SignalReceiver reciever = this.gameObject.AddComponent <SignalReceiver>();

        for (int i = 0; i < m_signals.Length; i++)
        {
            var        ts  = m_signals[i] as SignalAsset;
            UnityEvent evt = new UnityEvent();
            UnityAction <SignalAsset> action = new UnityAction <SignalAsset>(_OnSignal);
            //UnityEditor.Events.UnityEventTools.RemovePersistentListener<SignalAsset>(evt, action);
            UnityEditor.Events.UnityEventTools.AddObjectPersistentListener <SignalAsset>(evt, action, ts);
            evt.SetPersistentListenerState(0, UnityEngine.Events.UnityEventCallState.EditorAndRuntime); // This one needs to add here instead of adding this after the UnityEvent instance.
            reciever.AddReaction(ts, evt);
        }

        BindSignalReciever(reciever);
    }