Example #1
0
    public static void addListener(object obj, GEventType eventType)
    {
        removeListener(obj, eventType);

        Eventlistener listener = new Eventlistener();

        listener.obj       = obj;
        listener.eventType = eventType;

        MethodInfo method1 = obj.GetType().GetMethod("OnEvent");

        if (method1 != null)
        {
            // TODO: 如果被反射获取的方法签名不匹配, 会报错. 需改进成不报错,但输出log
            listener.funcDelegate = (EventDelegate)Delegate.CreateDelegate(typeof(EventDelegate), obj, method1);
            if (listener.funcDelegate == null)
            {
                return;
            }
        }

        List <Eventlistener> lst = null;

        if (!mListeners.TryGetValue(eventType, out lst))
        {
            lst = new List <Eventlistener>();
            lst.Add(listener);
            mListeners.Add(eventType, lst);
            return;
        }

        lst.Add(listener);
    }
Example #2
0
 public bool OnEvent(GEventType eventType, EventData eventData)
 {
     if (eventType == GEventType.PlayerMove)
     {
         UpdateCamera();
         return(true);
     }
     return(false);
 }
Example #3
0
    /**
     * Function that a handler calls to register itself for events
     */
    public void RegisterMe(GEventType t, EventHandler eh)
    {
        //add the linked list to the key "t" if it doesnt exist yet
        if (!EventHandlers.ContainsKey(t))
        {
            EventHandlers.Add(t, new List <EventHandler> ());
        }

        //add event to the linked list
        EventHandlers [t].Add(eh);
    }
Example #4
0
    public static void sendEvent(GEventType eventType, EventData eventData)
    {
        List <Eventlistener> lst = null;

        if (!mListeners.TryGetValue(eventType, out lst))
        {
            return;
        }

        foreach (Eventlistener listener in lst)
        {
            listener.funcDelegate(eventType, eventData);
        }
    }
    /**
     * Creates and returns an event
     */
    public static GEvent CreateEvent(GEventType eType, object[] eArguments, int ePriority)
    {
        GEvent e = new GEvent();

        e.Arguments = eArguments;

        e.Timestamp = Time.time;

        e.EventType = eType;

        e.Turn = TurnManager.GetCurrentTurn();

        e.Priority = ePriority;

        return(e);
    }
Example #6
0
    public static bool removeListener(object obj, GEventType eventType)
    {
        List <Eventlistener> lst = null;

        if (!mListeners.TryGetValue(eventType, out lst))
        {
            return(false);
        }

        for (int i = 0; i < lst.Count; i++)
        {
            if (obj == lst[i].obj && lst[i].eventType == eventType)
            {
                lst.RemoveAt(i);
                return(true);
            }
        }

        return(false);
    }
 /**
  * Creates an event and throws it to the event manager.
  */
 public static void ThrowEvent(GEventType eType, object[] eArguments)
 {
     EventFactory.ThrowEvent(eType, eArguments, 0);
 }
    /* This is a list of events and their arguments order
     * unless listed otherwise argument 0 is always the originating unit id (ex the moving unit, the firing unit)
     *
     *      AdminSpawnEvent: 1: latitude 2: longitude
     *
     *      AdminStatisticChangeEvent: 1: Controller name as a string 2: Parameter name as a string 3: new value
     *      AttackEvent: 1: target guid 2: weapon 3: damage //note damage of 0 indicates a miss
     *
     *      WeaponTargetEvent: 1: target unit id 2: weapon name 3: amount of shots
     *
     *      MoveEvent: 1: Vector3 of new position
     *
     *      DieEvent: no other arguments
     *
     *      EndOfTurnEvent: 0: the turn number
     *
     *      BackfireEvent: 1: the backfire damage
     *
     *      RemoveTargetEvent: 1: target guid 2: weapon name
     *
     *      UnitEmbarksEvent: 1: the smaller unit guid 2: the super unit guid
     *
     *      UnitUnEmbarksEvent: 1: the smaller unit guid 2: the super unit guid
     *
     *      WeatherChangeEvent: 0: the index of the new weather
     *
     *      ExplosionEvent: 0: The explosion instance
     *
     *      PlanMoveEvent: 0: Unit guid 1: user name 2: unit name 3: vector3 position 4: vector3 destination
     *
     */


    /**
     * Creates and returns an event with default priority of 0
     */
    public static GEvent CreateEvent(GEventType eType, object[] eArguments)
    {
        return(EventFactory.CreateEvent(eType, eArguments, 0));
    }
 /**
  * Creates an event and throws it to the event manager.
  */
 public static void ThrowEvent(GEventType eType, object[] eArguments, int priority)
 {
     EventManager.Instance.AddEvent(CreateEvent(eType, eArguments, priority));
 }