예제 #1
0
        private void Set(bool enable)
        {
            if (index < 0)
            {
                return;
            }

            var state = enable ? UnityEventCallState.EditorAndRuntime : UnityEventCallState.Off;

            evt.SetPersistentListenerState(index, state);
        }
예제 #2
0
    private void UpdateResponsesCallState()
    {
        for (int i = 0; i < response.GetPersistentEventCount(); i++)
        {
            response.SetPersistentListenerState(i, enableInEditor ? UnityEventCallState.EditorAndRuntime : UnityEventCallState.RuntimeOnly);
        }

        for (int i = 0; i < responseWithData.GetPersistentEventCount(); i++)
        {
            responseWithData.SetPersistentListenerState(i, enableInEditor ? UnityEventCallState.EditorAndRuntime : UnityEventCallState.RuntimeOnly);
        }
    }
    public void UnityEvent_InvokeCallsListenerOnce()
    {
        var _event = new UnityEvent();

        UnityEventTools.AddPersistentListener(_event, new UnityAction(Counter.Add));
        _event.SetPersistentListenerState(0, UnityEventCallState.EditorAndRuntime);

        _event.Invoke();

        Assert.AreEqual(1, Counter.m_Count);

        for (int i = 1; i < 5; ++i)
        {
            UnityEventTools.AddIntPersistentListener(_event, new UnityAction <int>(Counter.NoOp), i);
            _event.SetPersistentListenerState(i, UnityEventCallState.EditorAndRuntime);
        }

        _event.Invoke();

        Assert.AreEqual(2, Counter.m_Count);
    }
예제 #4
0
        private void Start()
        {
            UnityEvent onClick = GetComponent <Button>().onClick;

            for (int i = 0; i < onClick.GetPersistentEventCount(); i++)
            {
                if (onClick.GetPersistentTarget(i) == this)
                {
                    onClick.SetPersistentListenerState(i, UnityEventCallState.Off);
                }
            }

            onClick.AddListener(GoBack);
        }
    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);
    }