【Unity】简单的事件分发系统

 /// 
    /// 事件触发机制(CMD  RPC)
    /// 

    Dictionary dic = new Dictionary();

    public void AddToDictionary(string key, Delegate d)
    {
        if (!dic.ContainsKey(key))
        {
            dic.Add(key, d);
        }
    }
    /// 
    /// 事件的注册
    /// 
    /// 
    /// 
    /// 
    public void ResistEvent(string key, Action arg)
    {
        AddToDictionary(key, arg);
    }
    public void ResistEvent(string key, Action arg)
    {
        AddToDictionary(key, arg);
    }
    public void Notify(string key, params object[] args)
    {
        dic[key].DynamicInvoke(args);
    }

你可能感兴趣的:(Unity3D,Unity,开发)