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
    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);
    }