Exemplo n.º 1
0
 void Start()
 {
     //使用全局IoC容器对脚本进行注入
     G_InjectionContainer.Inject(this);
     //给消息容器添加事件订阅
     localsignalContainer.AddListener <SignalA>(OnReceiveSignalA);
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            LocalSignalContainer.AddListener <SignalA>(GetSignalA);
            LocalSignalContainer.AddListener <SignalB>(GetSignalB);
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            LocalSignalContainer.RemoveListener <SignalA>(GetSignalA);
            LocalSignalContainer.RemoveListener <SignalB>(GetSignalB);

            //error
            //LocalSignalContainer.RemoveListener<SignalC>(GetSignalC);
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            LocalSignalContainer.DispatchSignal(new SignalA()
            {
                msg = "A msg broadcast"
            });
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            LocalSignalContainer.DispatchSignal(new SignalB()
            {
                msg = "B msg broadcast"
            });

            //error
            //LocalSignalContainer.DispatchSignal(new SignalC() { msg = "C msg broadcast" });
        }
    }