Exemplo n.º 1
0
    public void RegisterObserver(GameEventType eventType, IGameEventObserver observer)
    {
        IGameEventSubject sub = GetGameEvent(eventType);

        if (sub != null)
        {
            sub.RegisterObserver(observer);
            observer.SetSubject(sub);
        }
    }
Exemplo n.º 2
0
    //private void InitGameEvents()
    //{
    //    mGameEvents.Add(GameEventType.EnemyKilled, new EnemyKilledSubject());
    //    mGameEvents.Add(GameEventType.SoldierKilled, new SoldierKilledSubject());
    //    mGameEvents.Add(GameEventType.NewStage, new NewStageSubject());
    //}

    //注册
    public void RegisterObserver(GameEventType gameEventType, IGameEventObserver eventObserver)
    {
        IGameEventSubject sub = GetGameEventSubject(gameEventType);

        if (sub == null)
        {
            return;
        }
        sub.RegisterObserver(eventObserver);
        eventObserver.SetSubject(sub);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 注册
    /// </summary>
    /// <param name="eventType"></param>
    /// <param name="observer"></param>
    public void RegisterObserver(GameEventType eventType, IGameEventObserver observer)
    {
        IGameEventSubject subject = GetGameEventSubject(eventType);

        if (subject == null)
        {
            return;
        }
        subject.RegisterObserver(observer);
        observer.SetSubject(subject);
    }
Exemplo n.º 4
0
    public void RegisterObserver(GameEventType eventType, IGameEventObserver observer)
    {
        //if (mGameEvents.ContainsKey(eventType))
        //{
        //    IGameEventSubject sub= mGameEvents[eventType];
        //    sub.RegisterObserver(observer);  //注册sub事件的观察者
        //    observer.SetSubject(sub); // 设置观察者观察的主题。
        //}
        //else
        //{
        //    Debug.LogError("没有对应被观察事件类型:"+eventType+"的主题类!");

        //}

        IGameEventSubject sub = GetGameEventSub(eventType);

        if (sub == null)
        {
            return;
        }
        sub.RegisterObserver(observer); //注册sub事件的观察者
        observer.SetSubject(sub);       // 设置观察者观察的主题。
    }