Esempio n. 1
0
        /// <summary>
        /// 获得用户组件
        /// </summary>
        /// <typeparam name="T">组件类型</typeparam>
        /// <returns></returns>
        public T GetUserComponent <T>() where T : UserComponent
        {
            var           name          = typeof(T);
            UserComponent userComponent = null;

            userComponentDic.TryGetValue(name, out userComponent);
            return(userComponent as T);
        }
Esempio n. 2
0
        /// <summary>
        /// 移除一个组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void RemoveUserComponent <T>() where T : UserComponent
        {
            var           name          = typeof(T);
            UserComponent userComponent = null;

            userComponentDic.TryGetValue(name, out userComponent);
            if (userComponentDic.Remove(name))
            {
                if (userComponent != null)
                {
                    userComponent.OnRemove();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 添加用户组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T AddUserComponent <T>() where T : UserComponent, new()
        {
            System.Type componentName = typeof(T);
            T           t             = null;

            if (!userComponentDic.ContainsKey(componentName))
            {
                t         = new T();
                t.netUser = this;
                t.OnAdd();
                userComponentDic[componentName] = t;
            }
            else
            {
                UserComponent userComponent = null;
                if (userComponentDic.TryGetValue(componentName, out userComponent))
                {
                    t = userComponent as T;
                }
            }

            return(t);
        }