Beispiel #1
0
    private static void _fire(HandleTable handles,
                              LinkedList <EventObj> firedEvents,
                              string eventname,
                              object[] args)
    {
        handles.Lock();
        List <Pair> lst;

        if (!handles.TryGetValue(eventname, out lst))
        {
            handles.UnLock();
            return;
        }

        Debug.Log("fire 1:" + eventname);

        for (int i = 0; i < lst.Count; i++)
        {
            var eobj = new EventObj();
            eobj._info = lst[i];
            eobj._args = args;
            firedEvents.AddLast(eobj);
        }

        handles.UnLock();
    }
Beispiel #2
0
    private static bool _unregister(HandleTable handles,
                                    string eventname,
                                    object obj,
                                    string funcname)
    {
        handles.Lock();
        List <Pair> lst;

        if (!handles.TryGetValue(eventname, out lst))
        {
            handles.UnLock();
            return(false);
        }

        for (int i = 0; i < lst.Count; i++)
        {
            if (obj == lst[i]._obj && lst[i]._funcname == funcname)
            {
                lst.RemoveAt(i);
                handles.UnLock();
                return(true);
            }
        }

        handles.UnLock();
        return(false);
    }
Beispiel #3
0
    public static void _process(HandleTable handles)
    {
        handles.Lock();
        if (handles._fired.Count > 0)
        {
            foreach (EventObj evt in handles._fired)
            {
                handles._doing.AddLast(evt);
            }
            handles._fired.Clear();
        }
        handles.UnLock();

        while (handles._doing.Count > 0)
        {
            EventObj eobj = handles._doing.First.Value;
            Debug.Log("process msg : " + eobj._info._funcname);
            try {
                eobj._info._method.Invoke(eobj._info._obj, eobj._args);
            }
            catch (Exception e) {
                Debug.Log("Event::processOutEvents: event=" +
                          eobj._info._funcname + "\n" + e);
            }
            handles._doing.RemoveFirst();
        }
    }
Beispiel #4
0
    private static bool _hasRegister(HandleTable handles,
                                     string eventname)
    {
        bool has;

        handles.Lock();
        has = handles.ContainsKey(eventname);
        handles.UnLock();

        return(has);
    }
Beispiel #5
0
    private static bool _register(HandleTable handles,
                                  string eventname,
                                  object obj,
                                  string funcname)
    {
        _unregister(handles, eventname, obj, funcname);
        List <Pair> lst;

        var pair = new Pair();

        pair._obj      = obj;
        pair._funcname = funcname;
        pair._method   = obj.GetType().GetMethod(funcname);

        if (pair._method == null)
        {
            Debug.Log("funcname not exist: " + eventname + " " + funcname);
            return(false);
        }

        handles.Lock();

        if (!handles.TryGetValue(eventname, out lst))
        {
            lst = new List <Pair>();
            lst.Add(pair);
            handles.Add(eventname, lst);
            handles.UnLock();
            return(true);
        }

        lst.Add(pair);
        handles.UnLock();

        return(true);
    }