flowchart TB
A["GameFrameworkEntry.GetModule"] --> B["自动创建模块"]
B --> C["按优先级排序"]
C --> D["统一Update循环"]
D --> E["逆序Shutdown"]
F["高优先级模块"] --> G["先执行Update"]
F --> H["后执行Shutdown"]
///<summary> /// 获取游戏框架模块。 ///</summary> ///<typeparam name="T">要获取的游戏框架模块类型。</typeparam> ///<returns>要获取的游戏框架模块。</returns> ///<remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks> publicstatic T GetModule<T>() where T : class { Type interfaceType = typeof(T); // 1. 必须是接口类型 if (!interfaceType.IsInterface) { thrownew GameFrameworkException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName)); } // 2. 必须是游戏框架模块, 必须是 GameFramework 命名空间下的类型 if (!interfaceType.FullName.StartsWith("GameFramework.", StringComparison.Ordinal)) { thrownew GameFrameworkException(Utility.Text.Format("You must get a Game Framework module, but '{0}' is not.", interfaceType.FullName)); } // 3. 命名约定:IXxxManager -> XxxManager string moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1)); // 去掉前缀 I Type moduleType = Type.GetType(moduleName); if (moduleType == null) { thrownew GameFrameworkException(Utility.Text.Format("Can not find Game Framework module type '{0}'.", moduleName)); }
///<summary> /// 关闭并清理所有游戏框架模块。 ///</summary> publicstaticvoidShutdown() { for (LinkedListNode<GameFrameworkModule> current = s_GameFrameworkModules.Last; current != null; current = current.Previous) { current.Value.Shutdown(); }
// 工厂方法 publicstatic T GetModule<T>() where T : class { // 1. 检查是否已存在 GameFrameworkModule existingModule = GetModule(moduleType); if (existingModule != null) return existingModule as T;
// 2. 不存在则创建新实例 return CreateModule(moduleType) as T; } }
工厂模式:
flowchart TB
A["Client 客户端"] --> B["Factory 工厂类"]
B --> C{产品类型判断}
C -->|TypeA| D["ProductA 产品 A"]
C -->|TypeB| E["ProductB 产品 B"]
C -->|TypeC| F["ProductC 产品 C"]
D --> G["IProduct产品接口"]
E --> G
F --> G
G --> H["返回给客户端"]
单例模式:
flowchart TB
A["Client 客户端"] --> B["Singleton 单例类"]
B --> C{判断是否已存在}
C -->|已存在| D["返回实例"]
C -->|不存在| E["创建新实例"]
E --> F["返回实例"]