RemoveListener() public method

Remove a non persistent listener from the UnityEvent.

public RemoveListener ( UnityAction call ) : void
call UnityAction Callback function.
return void
コード例 #1
0
    public static void RemoveEditorListener(this UnityEngine.Events.UnityEvent unityEvent, UnityAction call)
    {
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
            UnityEditor.Events.UnityEventTools.RemovePersistentListener(unityEvent, call);
        }
        else
        {
            unityEvent.RemoveListener(call);
        }
#else
        unityEvent.RemoveListener(call);
#endif
    }
コード例 #2
0
    public static void RemoveStringEditorListener(this UnityEngine.Events.UnityEvent unityEvent, UnityAction <string> call)
    {
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
            UnityEditor.Events.UnityEventTools.RemovePersistentListener(unityEvent, call);
        }
        else
        {
            unityEvent.RemoveListener(() => call.Invoke("")); // TODO: Fix this, this is not correct. This is making a new event/delegate to remove
        }
#else
        unityEvent.RemoveListener(() => call.Invoke(""));
#endif
    }
コード例 #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            myEvent.Invoke();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            // エディタ上でイベントを登録した場合、ここで登録した引数は無視される。
            myIntEvent.Invoke(123);
        }

        // スクリプトだけでイベントを加え、さらに、実行後自らを削除してみる例
        // https://answers.unity.com/questions/1492047/unityactionunityevent-remove-listener-from-within.html
        if (Input.GetKeyDown(KeyCode.T))
        {
            //SetEventFromCode(() => Debug.Log("Invoked Medthod whidh is added from code"));
            UnityAction myAction = null;
            myAction = new UnityAction(() =>
            {
                Debug.Log("Invoked Medthod whidh is added from code");
                myEvent.RemoveListener(myAction);
            });
            SetEventFromCode(myAction);
        }
    }
コード例 #4
0
        public static IObservable <Unit> AsObservable(this UnityEngine.Events.UnityEvent unityEvent)
        {
            var dummy = 0;

            return(Observable.FromEvent <UnityAction>(h =>
            {
                dummy.GetHashCode(); // capture for AOT issue
                return new UnityAction(h);
            }, h => unityEvent.AddListener(h), h => unityEvent.RemoveListener(h)));
        }
コード例 #5
0
ファイル: UnityEventExtensions.cs プロジェクト: ufcpp/UniRx
        public static IObservable <Unit> AsObservable(this UnityEngine.Events.UnityEvent unityEvent)
        {
            var dummy = 0;

            return(Observable.FromEvent <UnityAction, Unit>(h =>
            {
                dummy.GetHashCode(); // capture for AOT issue
                return new UnityAction(() => h(Unit.Default));
            }, h => unityEvent.AddListener(h), h => unityEvent.RemoveListener(h))
#if SystemReactive
                   .Select(_ => Unit.Default)
#endif
                   );
        }
コード例 #6
0
 static int RemoveListener(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.Events.UnityEvent  obj  = (UnityEngine.Events.UnityEvent)ToLua.CheckObject <UnityEngine.Events.UnityEvent>(L, 1);
         UnityEngine.Events.UnityAction arg0 = (UnityEngine.Events.UnityAction)ToLua.CheckDelegate <UnityEngine.Events.UnityAction>(L, 2);
         obj.RemoveListener(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #7
0
 public static int RemoveListener_wrap(long L)
 {
     try
     {
         long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.Events.UnityEvent  obj   = get_obj(nThisPtr);
         UnityAction_delegate           func0 = FCDelegateMng.Instance.GetDelegate <UnityAction_delegate>(L, 0);
         UnityEngine.Events.UnityAction arg0  = null;
         if (func0 != null)
         {
             arg0 = func0.CallFunc;
         }
         // 尽量不要在函数参数中传递委托指针,这个无法自动托管,要尽可能是使用get, set属性方法
         // 如果在参数中传递了委托指针,请在对应的函数中调用FCDelegateMng.Instance.RecordDelegate(delegate_func, func);
         obj.RemoveListener(arg0);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
コード例 #8
0
    static int RemoveListener(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        UnityEngine.Events.UnityEvent  obj  = (UnityEngine.Events.UnityEvent)LuaScriptMgr.GetNetObjectSelf(L, 1, "UnityEngine.Events.UnityEvent");
        UnityEngine.Events.UnityAction arg0 = null;
        LuaTypes funcType2 = LuaDLL.lua_type(L, 2);

        if (funcType2 != LuaTypes.LUA_TFUNCTION)
        {
            arg0 = (UnityEngine.Events.UnityAction)LuaScriptMgr.GetNetObject(L, 2, typeof(UnityEngine.Events.UnityAction));
        }
        else
        {
            LuaFunction func = LuaScriptMgr.GetLuaFunction(L, 2);
            arg0 = () =>
            {
                func.Call();
            };
        }

        obj.RemoveListener(arg0);
        return(0);
    }
コード例 #9
0
 public static IObservable <Unit> AsObservable(this UnityEngine.Events.UnityEvent unityEvent)
 {
     return(Observable.FromEvent <UnityAction>(h => new UnityAction(h), h => unityEvent.AddListener(h), h => unityEvent.RemoveListener(h)));
 }
コード例 #10
0
	protected virtual void RemoveListener(UnityEvent p_event, UnityAction p_action)
	{
		if(p_event != null && p_action != null)
			p_event.RemoveListener(p_action);
	}