AddListener() public method

Add a non persistent listener to the UnityEvent.

public AddListener ( UnityAction call ) : void
call UnityAction Callback function.
return void
コード例 #1
0
    public static void AddStringEditorListener(this UnityEngine.Events.UnityEvent unityEvent, UnityAction <string> call, string argument)
    {
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
            UnityEditor.Events.UnityEventTools.AddStringPersistentListener(unityEvent, call, argument);
        }
        else
        {
            unityEvent.AddListener(() => call.Invoke(argument));
        }
#else
        unityEvent.AddListener(() => call.Invoke(argument));
#endif
    }
コード例 #2
0
    public static void AddEditorListener(this UnityEngine.Events.UnityEvent unityEvent, UnityAction call)
    {
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
            UnityEditor.Events.UnityEventTools.AddPersistentListener(unityEvent, call);
        }
        else
        {
            unityEvent.AddListener(call);
        }
#else
        unityEvent.AddListener(call);
#endif
    }
コード例 #3
0
    void Awake()
    {
        if (XRSystem.testModeEnabled)
        {
            XRSystem.layoutOverride = xrLayout;

            if (xrLayout == XRLayoutOverride.None)
            {
                return;
            }

            // Built-in font shaders are incompatible with XR, replace them with a ShaderGraph version
            doBeforeTest.AddListener(ReplaceBuiltinFontShaders);
        }

        if (renderPipelineAsset == null)
        {
            Debug.LogWarning("No RenderPipelineAsset has been assigned in the test settings. This may result in a wrong test.");
            return;
        }

        var currentRP = GraphicsSettings.renderPipelineAsset;

        if (currentRP != renderPipelineAsset)
        {
            quitDebug.AppendLine($"{SceneManager.GetActiveScene().name} RP asset change: {((currentRP==null)?"null": currentRP.name)} => {renderPipelineAsset.name}");

            GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
        }
    }
コード例 #4
0
    //Removes all listeners of an event, adds one listener, and then invokes the event depending on parameters
    public static void RemoveAllAndAddListener(UnityEvent e, UnityAction listenerToAdd, bool invoke)
    {
        e.RemoveAllListeners(); //Remove all listeners
        e.AddListener(listenerToAdd); //Add the listen

        if(invoke) //If the event should be invoked
            e.Invoke(); //Invoke all listeners
    }
コード例 #5
0
    private void Start()
    {
        GameObject roadMan = Instantiate(RoadMan, new Vector3(0, 0, 0), Quaternion.identity);

        UnityEvent roadManEvent = new UnityEngine.Events.UnityEvent();

        roadManEvent.AddListener(PlayerFailure);
        roadMan.GetComponent <ControlRoadMan>().GameEndEvent = roadManEvent;
    }
コード例 #6
0
ファイル: EventManager.cs プロジェクト: Mystraht/rush
 public static void StartListening(string eventName, UnityAction listener) {
     UnityEvent thisEvent = null;
     if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) {
         thisEvent.AddListener(listener);
     } else {
         thisEvent = new UnityEvent();
         thisEvent.AddListener(listener);
         instance.eventDictionary.Add(eventName, thisEvent);
     }
 }
コード例 #7
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)));
        }
コード例 #8
0
ファイル: EventBus.cs プロジェクト: vpmedia/template-unity
 // ================================================================================
 // Public Methods
 // ================================================================================
 /// <summary>
 /// Adds a listener to a UnityEvent
 /// </summary>
 /// <param name="eventName">the event to listen for</param>
 /// <param name="listener">the callback to call</param>
 /// <returns></returns>
 public void Add(string eventName, UnityAction listener)
 {
     UnityEvent thisEvent = null;
     if (eventDictionary.TryGetValue (eventName, out thisEvent)) {
         thisEvent.AddListener (listener);
     } else {
         thisEvent = new UnityEvent ();
         thisEvent.AddListener (listener);
         eventDictionary.Add (eventName, thisEvent);
     }
 }
コード例 #9
0
 public static void StartListening(string eventname, UnityAction listener)
 {
     UnityEvent evt = null;
     if (mEMInstance.mEventDictionary.TryGetValue (eventname, out evt)) {
         evt.AddListener (listener);
     } else {
         evt = new UnityEvent();
         evt.AddListener(listener);
         mEMInstance.mEventDictionary.Add(eventname, evt);
     }
 }
コード例 #10
0
ファイル: EventManager.cs プロジェクト: Charnock/Space
 // Adds a listener to an event
 // The callback is a void return, zero arguement function
 public static void AddEventListener( string eventName, UnityAction callback )
 {
     UnityEvent thisEvent = null;
     if ( Instance.eventDictionary.TryGetValue ( eventName, out thisEvent ) )
     {
         thisEvent.AddListener ( callback );
     }
     else
     {
         thisEvent = new UnityEvent();
         thisEvent.AddListener( callback );
         ms_instance.eventDictionary.Add( eventName, thisEvent );
     }
 }
コード例 #11
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
                   );
        }
コード例 #12
0
ファイル: EventBus.cs プロジェクト: vpmedia/template-unity
 /// <summary>
 /// Adds a listener to a UnityEvent which is removed as soon as the event is dispatched
 /// </summary>
 /// <param name="eventName">the event to listen for</param>
 /// <param name="listener">the callback to call</param>
 /// <returns></returns>
 public void AddOnce(string eventName, UnityAction listener)
 {
     UnityEvent thisEvent = null;
     UnityAction onceListener = null;
     onceListener = () =>
     {
         thisEvent.RemoveListener (onceListener);
         listener ();
     };
     if (eventDictionary.TryGetValue (eventName, out thisEvent)) {
         thisEvent.AddListener (onceListener);
     } else {
         thisEvent = new UnityEvent ();
         thisEvent.AddListener (onceListener);
         eventDictionary.Add (eventName, thisEvent);
     }
 }
コード例 #13
0
    private void CreateHouse(int Multiplier)
    {
        Vector3    location = new Vector3(Random.Range(Multiplier * 2, Multiplier * 4), Random.Range(Multiplier * 2, Multiplier * 2.5f), -1);
        GameObject house    = Instantiate(HouseSprite, location, Quaternion.identity);

        house.GetComponent <HouseLogic>().HealthyEscapee = HealthySprite;
        house.GetComponent <HouseLogic>().SickEscapee    = SickSprite;

        UnityEvent failureEvent = new UnityEngine.Events.UnityEvent();

        failureEvent.AddListener(PlayerFailure);
        house.GetComponent <HouseLogic>().GameEndEvent = failureEvent;

        UnityEvent successEvent = new UnityEngine.Events.UnityEvent();

        successEvent.AddListener(PlayerSuccess);
        house.GetComponent <HouseLogic>().GameWinEvent = successEvent;
    }
コード例 #14
0
 public static int AddListener_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.AddListener(arg0);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
コード例 #15
0
 public void DoAddEventTrigger(UnityAction CallBack)
 {
     p_listEvent_Main.AddListener(CallBack);
 }
コード例 #16
0
 public void ListenStatChanged(UnityEngine.Events.UnityAction onEvent)
 {
     statChanged.AddListener(onEvent);
 }
コード例 #17
0
	protected virtual void AddListener(UnityEvent p_event, UnityAction p_action)
	{
		if(p_event != null && p_action != null)
		{
			p_event.RemoveListener(p_action);
			p_event.AddListener(p_action);
		}
	}
コード例 #18
0
ファイル: Character.cs プロジェクト: AndrewEmets/FullLife3
 void Start()
 {
     Hunger = 0;
     OnHungerFilled = new UnityEvent();
     OnHungerFilled.AddListener(Die);
 }
コード例 #19
0
    public void Init()
    {
        BT_Root      root = new BT_Root(); behaviourTree = new BehaviourTree(root); BT_Execute firstEx = new BT_Execute();
        BT_Interrupt InterruptTest     = new BT_Interrupt();
        BT_Execute   itrEx             = new BT_Execute();
        BT_Interrupt IfTest            = new BT_Interrupt();
        BT_If        if1               = new BT_If();
        BT_Execute   ifEx1             = new BT_Execute();
        BT_If        if2               = new BT_If();
        BT_Execute   ifEx2             = new BT_Execute();
        BT_If        if3               = new BT_If();
        BT_Execute   ifEx3             = new BT_Execute();
        BT_Interrupt WhileTest         = new BT_Interrupt();
        BT_While     while1            = new BT_While();
        BT_Execute   whileEx1          = new BT_Execute();
        BT_Execute   whileEx2          = new BT_Execute();
        BT_Interrupt SelectorTest      = new BT_Interrupt();
        BT_Selector  selector1         = new BT_Selector();
        BT_Execute   selectorEx2       = new BT_Execute();
        BT_If        selectorIf1       = new BT_If();
        BT_Execute   selectorEx1       = new BT_Execute();
        BT_Execute   selectorEx3       = new BT_Execute();
        BT_Interrupt SequenceTest      = new BT_Interrupt();
        BT_Sequence  sequence1         = new BT_Sequence();
        BT_Execute   sequenceEx1       = new BT_Execute();
        BT_If        sequenceIf1       = new BT_If();
        BT_Execute   sequenceEx2       = new BT_Execute();
        BT_Execute   sequenceEx3       = new BT_Execute();
        BT_Interrupt frameCounterTest  = new BT_Interrupt();
        BT_Execute   frameCounterEx1   = new BT_Execute();
        BT_Timing    frameCounter1     = new BT_Timing(behaviourTree, false, false);
        BT_Interrupt frameCounterTest2 = new BT_Interrupt();
        BT_Execute   frameCounterEx2   = new BT_Execute();
        BT_Interrupt frameCounterTest3 = new BT_Interrupt();
        BT_Execute   frameCounterEx3   = new BT_Execute();
        BT_Timing    frameCounter2     = new BT_Timing(behaviourTree, false, true);
        BT_Interrupt frameCounterTest4 = new BT_Interrupt();
        BT_Execute   frameCounterEx4   = new BT_Execute();
        BT_Timing    frameCounter3     = new BT_Timing(behaviourTree, true, false);
        BT_Interrupt frameCounterTest5 = new BT_Interrupt();
        BT_Execute   frameCounterEx5   = new BT_Execute();
        BT_Interrupt timerTest         = new BT_Interrupt();
        BT_Execute   timerTestEx1      = new BT_Execute();
        BT_Timing    timer1            = new BT_Timing(behaviourTree, false, false);
        BT_Interrupt timerTest2        = new BT_Interrupt();
        BT_Execute   timerTestEx2      = new BT_Execute();
        BT_Interrupt timerTest3        = new BT_Interrupt();
        BT_Execute   timerTestEx3      = new BT_Execute();
        BT_Timing    timer2            = new BT_Timing(behaviourTree, false, true);
        BT_Interrupt timerTest4        = new BT_Interrupt();
        BT_Execute   timerTestEx4      = new BT_Execute();
        BT_Timing    timer3            = new BT_Timing(behaviourTree, true, false);
        BT_Interrupt timerTest5        = new BT_Interrupt();
        BT_Execute   timerTestEx5      = new BT_Execute();
        BT_Success   NextSequence      = new BT_Success();
        BT_Interrupt setParameterTest  = new BT_Interrupt();
        BT_Execute   SetBool1          = new BT_Execute();
        BT_Execute   SetBool2          = new BT_Execute();
        BT_Sequence  sequence          = new BT_Sequence();
        BT_If        setParameterIf1   = new BT_If();
        BT_Execute   setParameterEx1   = new BT_Execute();
        BT_If        setParameterIf2   = new BT_If();
        BT_Execute   setParameterEx2   = new BT_Execute();
        BT_Execute   SetBool3          = new BT_Execute();
        BT_If        setParameterIf3   = new BT_If();
        BT_Execute   setParameterEx3   = new BT_Execute();
        BT_Execute   SetInt1           = new BT_Execute();
        BT_If        setParameterIf4   = new BT_If();
        BT_Execute   setParameterEx4   = new BT_Execute();
        BT_Execute   SetInt2           = new BT_Execute();
        BT_If        setParameterIf5   = new BT_If();
        BT_Execute   setParameterEx5   = new BT_Execute();
        BT_Execute   SetFloat1         = new BT_Execute();
        BT_If        setParameterIf6   = new BT_If();
        BT_Execute   setParameterEx6   = new BT_Execute();
        BT_Execute   SetFloat2         = new BT_Execute();
        BT_If        setParameterIf7   = new BT_If();
        BT_Execute   setParameterEx7   = new BT_Execute();

        firstEx.AddEvent(() => {
            first_ev.Invoke();
        });
        root.AddChild(firstEx);
        InterruptTest.SetCondition(() => {
            return(case2);
        });
        behaviourTree.AddInterrupt(InterruptTest);
        InterruptTest.AddChild(itrEx);
        itrEx.AddEvent(() => {
            itr_ev.Invoke();
        });
        IfTest.SetCondition(() => {
            return(case3);
        });
        behaviourTree.AddInterrupt(IfTest);
        IfTest.AddChild(if1);
        if1.SetCondition(() => {
            return(if_bool1);
        });
        if1.AddChild(ifEx1);
        ifEx1.AddEvent(() => {
            if_ev1.Invoke();
        });
        ifEx1.AddChild(if2);
        if2.SetCondition(() => {
            return(if_int1 > 10);
        });
        if2.AddChild(ifEx2);
        ifEx2.AddEvent(() => {
            if_ev2.Invoke();
        });
        ifEx2.AddChild(if3);
        if3.SetCondition(() => {
            return(if_float1 < 10.0f);
        });
        if3.AddChild(ifEx3);
        ifEx3.AddEvent(() => {
            if_ev3.Invoke();
        });
        while1.SetCondition(() => {
            return(while_bool1);
        });
        while1.AddChild(whileEx2);
        WhileTest.SetCondition(() => {
            return(case4);
        });
        behaviourTree.AddInterrupt(WhileTest);
        WhileTest.AddChild(whileEx1);
        whileEx1.AddEvent(() => {
            while_ev1.Invoke();
        });
        whileEx1.AddChild(while1);
        whileEx2.AddEvent(() => {
            while_ev2.Invoke();
        });
        selectorIf1.SetCondition(() => {
            return(selector_bool1);
        });
        selectorIf1.AddChild(selectorEx1);
        selectorEx1.AddEvent(() => {
            selector_ev1.Invoke();
        });
        SelectorTest.SetCondition(() => {
            return(case5);
        });
        behaviourTree.AddInterrupt(SelectorTest);
        SelectorTest.AddChild(selector1);

        selector1.AddChild(selectorIf1);
        selector1.AddChild(selectorEx2);
        selector1.AddChild(selectorEx3);
        selectorEx2.AddEvent(() => {
            selector_ev2.Invoke();
        });
        selectorEx3.AddEvent(() => {
            selector_ev3.Invoke();
        });
        sequenceEx1.AddEvent(() => {
            sequence_ev1.Invoke();
        });
        sequenceEx1.AddChild(NextSequence);

        SequenceTest.SetCondition(() => {
            return(case6);
        });
        behaviourTree.AddInterrupt(SequenceTest);
        SequenceTest.AddChild(sequence1);

        sequence1.AddChild(sequenceEx1);
        sequence1.AddChild(sequenceIf1);
        sequence1.AddChild(sequenceEx3);
        sequenceIf1.SetCondition(() => {
            return(sequence_bool1
                   );
        });
        sequenceIf1.AddChild(sequenceEx2);
        sequenceEx2.AddEvent(() => {
            sequence_ev2.Invoke();
        });
        sequenceEx3.AddEvent(() => {
            sequence_ev3.Invoke();
        });
        frameCounterEx2.AddEvent(() => {
            frameCounter_ev2.Invoke();
        });
        frameCounterTest.SetCondition(() => {
            return(case7);
        });
        behaviourTree.AddInterrupt(frameCounterTest);
        frameCounterTest.AddChild(frameCounterEx1);
        frameCounter1.SetTimingCreator(() => {
            return(new FrameCounter(frameCounterTest2, 1));
        });
        frameCounterTest2.SetCondition(() => {
            return(false);
        });
        behaviourTree.AddInterrupt(frameCounterTest2);
        frameCounterTest2.AddChild(frameCounterEx2);
        frameCounterEx1.AddEvent(() => {
            frameCounter_ev1.Invoke();
        });
        frameCounterEx1.AddChild(frameCounter1);
        frameCounterTest3.SetCondition(() => {
            return(case8);
        });
        behaviourTree.AddInterrupt(frameCounterTest3);
        frameCounterTest3.AddChild(frameCounterEx3);
        frameCounterEx3.AddEvent(() => {
            frameCounter_ev3.Invoke();
        });
        frameCounterEx3.AddChild(frameCounter2);
        frameCounter2.SetTimingCreator(() => {
            return(new FrameCounter(frameCounterTest4, 1));
        });
        frameCounterTest4.SetCondition(() => {
            return(false);
        });
        behaviourTree.AddInterrupt(frameCounterTest4);
        frameCounterTest4.AddChild(frameCounterEx4);
        frameCounterEx4.AddEvent(() => {
            frameCounter_ev4.Invoke();
        });
        frameCounterEx4.AddChild(frameCounter3);
        frameCounter3.SetTimingCreator(() => {
            return(new FrameCounter(frameCounterTest5, 1));
        });
        frameCounterTest5.SetCondition(() => {
            return(false);
        });
        behaviourTree.AddInterrupt(frameCounterTest5);
        frameCounterTest5.AddChild(frameCounterEx5);
        frameCounterEx5.AddEvent(() => {
            frameCounter_ev5.Invoke();
        });
        timerTest.SetCondition(() => {
            return(case9);
        });
        behaviourTree.AddInterrupt(timerTest);
        timerTest.AddChild(timerTestEx1);
        timerTestEx1.AddEvent(() => {
            timerTest_ev1.Invoke();
        });
        timerTestEx1.AddChild(timer1);
        timer1.SetTimingCreator(() => {
            return(new Timer(timerTest2, 3));
        });
        timerTest2.SetCondition(() => {
            return(false);
        });
        behaviourTree.AddInterrupt(timerTest2);
        timerTest2.AddChild(timerTestEx2);
        timerTestEx2.AddEvent(() => {
            timerTest_ev2.Invoke();
        });
        timerTest3.SetCondition(() => {
            return(case10);
        });
        behaviourTree.AddInterrupt(timerTest3);
        timerTest3.AddChild(timerTestEx3);
        timerTestEx3.AddEvent(() => {
            timerTest_ev3.Invoke();
        });
        timerTestEx3.AddChild(timer2);
        timer2.SetTimingCreator(() => {
            return(new Timer(timerTest4, 1.5));
        });
        timerTest4.SetCondition(() => {
            return(false);
        });
        behaviourTree.AddInterrupt(timerTest4);
        timerTest4.AddChild(timerTestEx4);
        timerTestEx4.AddEvent(() => {
            timerTest_ev4.Invoke();
        });
        timerTestEx4.AddChild(timer3);
        timer3.SetTimingCreator(() => {
            return(new Timer(timerTest5, 3));
        });
        timerTest5.SetCondition(() => {
            return(false);
        });
        behaviourTree.AddInterrupt(timerTest5);
        timerTest5.AddChild(timerTestEx5);
        timerTestEx5.AddEvent(() => {
            timerTest_ev5.Invoke();
        });
        SetBool1.AddEvent(() => {
            setParameterBool1 = true;
        });
        SetBool1.AddChild(setParameterIf1);
        SetBool2.AddEvent(() => {
            setParameterBool2 = false;
        });
        SetBool2.AddChild(setParameterIf2);
        setParameterIf1.SetCondition(() => {
            return(setParameterBool1);
        });
        setParameterIf1.AddChild(setParameterEx1);
        setParameterIf2.SetCondition(() => {
            return(!setParameterBool2);
        });
        setParameterIf2.AddChild(setParameterEx2);
        SetBool3.AddEvent(() => {
            setParameterBool2 = setParameterBool1;
        });
        SetBool3.AddChild(setParameterIf3);
        setParameterIf3.SetCondition(() => {
            return(setParameterBool2);
        });
        setParameterIf3.AddChild(setParameterEx3);
        setParameterEx3.AddEvent(() => {
            setParameterEv3.Invoke();
        });
        setParameterEx1.AddEvent(() => {
            setParameterEv1.Invoke();
        });
        setParameterEx1.AddChild(SetBool2);
        setParameterEx2.AddEvent(() => {
            setParameterEv2.Invoke();
        });
        setParameterEx2.AddChild(SetBool3);
        setParameterTest.SetCondition(() => {
            return(case11);
        });
        behaviourTree.AddInterrupt(setParameterTest);
        setParameterTest.AddChild(sequence);
        setParameterIf4.SetCondition(() => {
            return(setParameterInt1 == 1);
        });
        setParameterIf4.AddChild(setParameterEx4);
        setParameterIf5.SetCondition(() => {
            return(setParameterInt2 == 1);
        });
        setParameterIf5.AddChild(setParameterEx5);

        sequence.AddChild(SetBool1);
        sequence.AddChild(SetInt1);
        sequence.AddChild(SetFloat1);
        SetInt1.AddEvent(() => {
            setParameterInt1 = 1;
        });
        SetInt1.AddChild(setParameterIf4);
        setParameterEx4.AddEvent(() => {
            setParameterEv4.Invoke();
        });
        setParameterEx4.AddChild(SetInt2);
        SetInt2.AddEvent(() => {
            setParameterInt2 = setParameterInt1;
        });
        SetInt2.AddChild(setParameterIf5);
        setParameterEx5.AddEvent(() => {
            setParameterEv5.Invoke();
        });
        setParameterIf6.SetCondition(() => {
            return(setParameterFloat1 > 1.0f);
        });
        setParameterIf6.AddChild(setParameterEx6);
        setParameterEx6.AddEvent(() => {
            setParameterEv6.Invoke();
        });
        setParameterEx6.AddChild(SetFloat2);
        setParameterIf7.SetCondition(() => {
            return(setParameterFloat1 < 1.0f);
        });
        setParameterIf7.AddChild(setParameterEx7);
        SetFloat1.AddEvent(() => {
            setParameterFloat1 = 1.5f;
        });
        SetFloat1.AddChild(setParameterIf6);
        SetFloat2.AddEvent(() => {
            setParameterFloat1 = setParameterFloat2;
        });
        SetFloat2.AddChild(setParameterIf7);
        setParameterEx7.AddEvent(() => {
            setParameterEv7.Invoke();
        });


        calledFlag = new Dictionary <string, bool>();
        calledFlag.Add("firstEx", false);
        first_ev.AddListener(() => {
            calledFlag["firstEx"] = true;
        }); calledFlag.Add("itrEx", false);
        itr_ev.AddListener(() => {
            calledFlag["itrEx"] = true;
        }); calledFlag.Add("ifEx1", false);
        if_ev1.AddListener(() => {
            calledFlag["ifEx1"] = true;
        }); calledFlag.Add("ifEx2", false);
        if_ev2.AddListener(() => {
            calledFlag["ifEx2"] = true;
        }); calledFlag.Add("ifEx3", false);
        if_ev3.AddListener(() => {
            calledFlag["ifEx3"] = true;
        }); calledFlag.Add("whileEx1", false);
        while_ev1.AddListener(() => {
            calledFlag["whileEx1"] = true;
        }); calledFlag.Add("whileEx2", false);
        while_ev2.AddListener(() => {
            calledFlag["whileEx2"] = true;
        }); calledFlag.Add("selectorEx2", false);
        selector_ev2.AddListener(() => {
            calledFlag["selectorEx2"] = true;
        }); calledFlag.Add("selectorEx1", false);
        selector_ev1.AddListener(() => {
            calledFlag["selectorEx1"] = true;
        }); calledFlag.Add("selectorEx3", false);
        selector_ev3.AddListener(() => {
            calledFlag["selectorEx3"] = true;
        }); calledFlag.Add("sequenceEx1", false);
        sequence_ev1.AddListener(() => {
            calledFlag["sequenceEx1"] = true;
        }); calledFlag.Add("sequenceEx2", false);
        sequence_ev2.AddListener(() => {
            calledFlag["sequenceEx2"] = true;
        }); calledFlag.Add("sequenceEx3", false);
        sequence_ev3.AddListener(() => {
            calledFlag["sequenceEx3"] = true;
        }); calledFlag.Add("frameCounterEx1", false);
        frameCounter_ev1.AddListener(() => {
            calledFlag["frameCounterEx1"] = true;
        }); calledFlag.Add("frameCounterEx2", false);
        frameCounter_ev2.AddListener(() => {
            calledFlag["frameCounterEx2"] = true;
        }); calledFlag.Add("frameCounterEx3", false);
        frameCounter_ev3.AddListener(() => {
            calledFlag["frameCounterEx3"] = true;
        }); calledFlag.Add("frameCounterEx4", false);
        frameCounter_ev4.AddListener(() => {
            calledFlag["frameCounterEx4"] = true;
        }); calledFlag.Add("frameCounterEx5", false);
        frameCounter_ev5.AddListener(() => {
            calledFlag["frameCounterEx5"] = true;
        }); calledFlag.Add("timerTestEx1", false);
        timerTest_ev1.AddListener(() => {
            calledFlag["timerTestEx1"] = true;
        }); calledFlag.Add("timerTestEx2", false);
        timerTest_ev2.AddListener(() => {
            calledFlag["timerTestEx2"] = true;
        }); calledFlag.Add("timerTestEx3", false);
        timerTest_ev3.AddListener(() => {
            calledFlag["timerTestEx3"] = true;
        }); calledFlag.Add("timerTestEx4", false);
        timerTest_ev4.AddListener(() => {
            calledFlag["timerTestEx4"] = true;
        }); calledFlag.Add("timerTestEx5", false);
        timerTest_ev5.AddListener(() => {
            calledFlag["timerTestEx5"] = true;
        }); calledFlag.Add("setParameterEx1", false);
        setParameterEv1.AddListener(() => {
            calledFlag["setParameterEx1"] = true;
        }); calledFlag.Add("setParameterEx2", false);
        setParameterEv2.AddListener(() => {
            calledFlag["setParameterEx2"] = true;
        }); calledFlag.Add("setParameterEx3", false);
        setParameterEv3.AddListener(() => {
            calledFlag["setParameterEx3"] = true;
        }); calledFlag.Add("setParameterEx4", false);
        setParameterEv4.AddListener(() => {
            calledFlag["setParameterEx4"] = true;
        }); calledFlag.Add("setParameterEx5", false);
        setParameterEv5.AddListener(() => {
            calledFlag["setParameterEx5"] = true;
        }); calledFlag.Add("setParameterEx6", false);
        setParameterEv6.AddListener(() => {
            calledFlag["setParameterEx6"] = true;
        }); calledFlag.Add("setParameterEx7", false);
        setParameterEv7.AddListener(() => {
            calledFlag["setParameterEx7"] = true;
        });
    }
コード例 #20
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)));
 }
コード例 #21
0
ファイル: WorldRenderer.cs プロジェクト: dav793/2D-RTS
 void startListeningForActiveCellUpdates()
 {
     update_listener = new UnityAction (updateActiveCells);
     update_event = new UnityEvent ();
     update_event.AddListener (update_listener);
 }
コード例 #22
0
 public void SetEventFromCode(UnityAction action)
 {
     myEvent.AddListener(action);
 }
コード例 #23
0
ファイル: UnityEventExt.cs プロジェクト: izackp/Unity-Library
 public static void AddListenerWeak(this UnityEvent obj, Action call)
 {
     obj.AddListener(new WeakAction(call));
 }
コード例 #24
0
ファイル: ScrapDialogueUI.cs プロジェクト: jimistine/Scrapper
 void Start()
 {
     onLineStart.AddListener(DialogueManager.DM.LineStarted);
 }
コード例 #25
0
    public void Init()
    {
        BT_Root      root = new BT_Root(); behaviourTree = new BehaviourTree(root); BT_Selector selector1 = new BT_Selector();
        BT_Execute   attack               = new BT_Execute();
        BT_Execute   chase                = new BT_Execute();
        BT_Execute   patrol               = new BT_Execute();
        BT_Selector  selector2            = new BT_Selector();
        BT_If        if_found             = new BT_If();
        BT_If        If_attack            = new BT_If();
        BT_Execute   attackable_check     = new BT_Execute();
        BT_Execute   moveableCheck        = new BT_Execute();
        BT_If        if_patrol            = new BT_If();
        BT_If        If_chase             = new BT_If();
        BT_If        If_escape            = new BT_If();
        BT_Execute   escape               = new BT_Execute();
        BT_Interrupt DamageInterrupt      = new BT_Interrupt();
        BT_Execute   ResetDamageFlag      = new BT_Execute();
        BT_Execute   ActivateEscape       = new BT_Execute();
        BT_Timing    EscapeTimer          = new BT_Timing(behaviourTree, true, false, "EscapeTimer");
        BT_Interrupt EscapeResetInterrupt = new BT_Interrupt();
        BT_Execute   EscapeResetter       = new BT_Execute();
        BT_Execute   SetFound             = new BT_Execute();

        If_escape.SetCondition(() => {
            return(IsEscape && IsMoveable);
        });
        If_escape.AddChild(escape);
        escape.AddEvent(() => {
            escape_event.Invoke();
        });
        if_found.SetCondition(() => {
            return(IsFound);
        });
        if_found.AddChild(selector2);
        If_attack.SetCondition(() => {
            return(IsAttackable);
        });
        If_attack.AddChild(attack);
        attackable_check.AddEvent(() => {
            attackablecheck_event.Invoke();
        });
        attackable_check.AddChild(If_attack);

        selector2.AddChild(If_escape);
        selector2.AddChild(attackable_check);
        selector2.AddChild(If_chase);
        attack.AddEvent(() => {
            attack_event.Invoke();
        });
        root.AddChild(moveableCheck);

        selector1.AddChild(if_found);
        selector1.AddChild(if_patrol);
        moveableCheck.AddEvent(() => {
            moveablecheck_event.Invoke();
        });
        moveableCheck.AddChild(selector1);
        if_patrol.SetCondition(() => {
            return(IsMoveable);
        });
        if_patrol.AddChild(patrol);
        patrol.AddEvent(() => {
            patrol_event.Invoke();
        });
        EscapeTimer.SetTimingCreator(() => {
            return(new Timer(EscapeResetInterrupt, 3.0));
        });
        EscapeTimer.AddChild(moveableCheck);
        ResetDamageFlag.AddEvent(() => {
            IsGotDamage = false;
        });
        ResetDamageFlag.AddChild(ActivateEscape);
        ActivateEscape.AddEvent(() => {
            IsEscape = true;
        });
        ActivateEscape.AddChild(EscapeTimer);
        SetFound.AddEvent(() => {
            IsFound = true;
        });
        SetFound.AddChild(ResetDamageFlag);
        If_chase.SetCondition(() => {
            return(IsMoveable);
        });
        If_chase.AddChild(chase);
        DamageInterrupt.SetCondition(() => {
            return(IsGotDamage);
        });
        behaviourTree.AddInterrupt(DamageInterrupt);
        DamageInterrupt.AddChild(SetFound);
        chase.AddEvent(() => {
            chase_event.Invoke();
        });
        EscapeResetInterrupt.SetCondition(() => {
            return(false);
        });
        behaviourTree.AddInterrupt(EscapeResetInterrupt);
        EscapeResetInterrupt.AddChild(EscapeResetter);
        EscapeResetter.AddEvent(() => {
            IsEscape = false;
        });
        EscapeResetter.AddChild(moveableCheck);


        calledFlag = new Dictionary <string, bool>();
        calledFlag.Add("attack", false);
        attack_event.AddListener(() => {
            calledFlag["attack"] = true;
        }); calledFlag.Add("chase", false);
        chase_event.AddListener(() => {
            calledFlag["chase"] = true;
        }); calledFlag.Add("patrol", false);
        patrol_event.AddListener(() => {
            calledFlag["patrol"] = true;
        }); calledFlag.Add("attackable_check", false);
        attackablecheck_event.AddListener(() => {
            calledFlag["attackable_check"] = true;
        }); calledFlag.Add("moveableCheck", false);
        moveablecheck_event.AddListener(() => {
            calledFlag["moveableCheck"] = true;
        }); calledFlag.Add("escape", false);
        escape_event.AddListener(() => {
            calledFlag["escape"] = true;
        });
    }