Browse Source

Revert "更新代码调用"

This reverts commit bc5024c3570ca32213eb4ecb19f39e0f7f283829.
蓝色星空 1 year ago
parent
commit
1d372cd463
100 changed files with 2449 additions and 34 deletions
  1. BIN
      Assets/Plugins/Blue/Blue.dll
  2. 0 33
      Assets/Plugins/Blue/Blue.dll.meta
  3. 1 1
      Assets/Scripts/Blue/0.FrameworkDesign.meta
  4. 8 0
      Assets/Scripts/Blue/0.FrameworkDesign/Command.meta
  5. 18 0
      Assets/Scripts/Blue/0.FrameworkDesign/Command/DefaultCommandHandler.cs
  6. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Command/DefaultCommandHandler.cs.meta
  7. 7 0
      Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommand.cs
  8. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommand.cs.meta
  9. 8 0
      Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommandHandler.cs
  10. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommandHandler.cs.meta
  11. 8 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core.meta
  12. 202 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/AbstractArchitecture.cs
  13. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/AbstractArchitecture.cs.meta
  14. 130 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/ArchitectureInitiator.cs
  15. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/ArchitectureInitiator.cs.meta
  16. 29 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitecture.cs
  17. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitecture.cs.meta
  18. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModule.cs
  19. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModule.cs.meta
  20. 36 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModuleExtension.cs
  21. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModuleExtension.cs.meta
  22. 6 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/ICanInject.cs
  23. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/ICanInject.cs.meta
  24. 9 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IController.cs
  25. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IController.cs.meta
  26. 10 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IModel.cs
  27. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IModel.cs.meta
  28. 10 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IService.cs
  29. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IService.cs.meta
  30. 9 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IUtility.cs
  31. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/IUtility.cs.meta
  32. 54 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/ModuleInitiator.cs
  33. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Core/ModuleInitiator.cs.meta
  34. BIN
      Assets/Scripts/Blue/0.FrameworkDesign/Design.eddx
  35. 7 0
      Assets/Scripts/Blue/0.FrameworkDesign/Design.eddx.meta
  36. 8 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event.meta
  37. 22 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/BindablePropertyUnSubscribe.cs
  38. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/BindablePropertyUnSubscribe.cs.meta
  39. 41 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/ChainEventSubscription.cs
  40. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/ChainEventSubscription.cs.meta
  41. 27 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultChainEventUnSubcribe.cs
  42. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultChainEventUnSubcribe.cs.meta
  43. 160 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultTypeEventSystem.cs
  44. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultTypeEventSystem.cs.meta
  45. 49 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/EventToActionAdapter.cs
  46. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/EventToActionAdapter.cs.meta
  47. 8 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEvent.cs
  48. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEvent.cs.meta
  49. 18 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventSubscription.cs
  50. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventSubscription.cs.meta
  51. 31 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubcribeExtension.cs
  52. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubcribeExtension.cs.meta
  53. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubscribe.cs
  54. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubscribe.cs.meta
  55. 6 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IEvent.cs
  56. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IEvent.cs.meta
  57. 13 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/ISubscription.cs
  58. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/ISubscription.cs.meta
  59. 28 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/ITypeEventSystem.cs
  60. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/ITypeEventSystem.cs.meta
  61. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribe.cs
  62. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribe.cs.meta
  63. 26 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribeExtension.cs
  64. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribeExtension.cs.meta
  65. 49 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSubscription.cs
  66. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSubscription.cs.meta
  67. 19 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSystemUnSubscribe.cs
  68. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSystemUnSubscribe.cs.meta
  69. 22 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeChainEventOnDestroyTrigger.cs
  70. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeChainEventOnDestroyTrigger.cs.meta
  71. 22 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDestroyTrigger.cs
  72. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDestroyTrigger.cs.meta
  73. 22 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDisableTrigger.cs
  74. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDisableTrigger.cs.meta
  75. 8 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC.meta
  76. 236 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/AbstractArchitectureComponentInjector.cs
  77. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/AbstractArchitectureComponentInjector.cs.meta
  78. 132 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ArchitectureInjecter.cs
  79. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ArchitectureInjecter.cs.meta
  80. 36 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/AutoInjectAttribute.cs
  81. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/AutoInjectAttribute.cs.meta
  82. 54 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ControllerInjector.cs
  83. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ControllerInjector.cs.meta
  84. 19 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/IArchitectureComponentInjector.cs
  85. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/IArchitectureComponentInjector.cs.meta
  86. 19 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/IInjector.cs
  87. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/IInjector.cs.meta
  88. 65 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/IOCContainer.cs
  89. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/IOCContainer.cs.meta
  90. 13 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectInfo.cs
  91. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectInfo.cs.meta
  92. 40 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectRuleAttribute.cs
  93. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectRuleAttribute.cs.meta
  94. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectScope.cs
  95. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectScope.cs.meta
  96. 43 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ModelInjector.cs
  97. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ModelInjector.cs.meta
  98. 43 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ServiceInjector.cs
  99. 11 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/ServiceInjector.cs.meta
  100. 79 0
      Assets/Scripts/Blue/0.FrameworkDesign/IOC/TypeChecker.cs

BIN
Assets/Plugins/Blue/Blue.dll


+ 0 - 33
Assets/Plugins/Blue/Blue.dll.meta

@@ -1,33 +0,0 @@
-fileFormatVersion: 2
-guid: ce12ede5325fa0549b9337f00ba2771c
-PluginImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  iconMap: {}
-  executionOrder: {}
-  defineConstraints: []
-  isPreloaded: 0
-  isOverridable: 0
-  isExplicitlyReferenced: 0
-  validateReferences: 1
-  platformData:
-  - first:
-      Any: 
-    second:
-      enabled: 1
-      settings: {}
-  - first:
-      Editor: Editor
-    second:
-      enabled: 0
-      settings:
-        DefaultValueInitialized: true
-  - first:
-      Windows Store Apps: WindowsStoreApps
-    second:
-      enabled: 0
-      settings:
-        CPU: AnyCPU
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 1 - 1
Assets/Plugins/Blue.meta → Assets/Scripts/Blue/0.FrameworkDesign.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 06f4576903578454a8f4f497b8fda9d5
+guid: 77ed7435e9ea8ee4baa3ed85f70d94a0
 folderAsset: yes
 DefaultImporter:
   externalObjects: {}

+ 8 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Command.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: ddfab4732bc4200488644a06987a4e3d
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 18 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Command/DefaultCommandHandler.cs

@@ -0,0 +1,18 @@
+namespace Blue
+{
+    /// <summary>
+    /// 默认Command 处理类
+    /// </summary>
+    public class DefaultCommandHandler : ICommandHandler
+    {
+        public void ExcuteCommand(ICommand command)
+        {
+            command.OnExcute();
+        }
+
+        public void ExcuteCommand<T>() where T : ICommand, new()
+        {
+            ExcuteCommand(new T());
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Command/DefaultCommandHandler.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b3d22e8c7927ea94ea756fbaf507eab4
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 7 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommand.cs

@@ -0,0 +1,7 @@
+namespace Blue
+{
+    public interface ICommand:ICanGetService,ICanGetModel,ICanGetUtility,ICanTriggerEvent,ICanSendCommand
+    {
+        void OnExcute();
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommand.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: de3ff73d66e6dc44d85d583a30ca4137
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommandHandler.cs

@@ -0,0 +1,8 @@
+namespace Blue
+{
+    public interface ICommandHandler
+    {
+        void ExcuteCommand(ICommand command);
+        void ExcuteCommand<T>() where T:ICommand,new();
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Command/ICommandHandler.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 0589e9d01727a9242ac4bb6701ade270
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: c1e93bff4fd1fe346906a5880e4bdf96
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 202 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/AbstractArchitecture.cs

@@ -0,0 +1,202 @@
+using System;
+using System.Collections.Generic;
+
+namespace Blue
+{
+    /// <summary>
+    /// Architecture抽象类,继承自IArchitecture
+    /// </summary>
+    public abstract class AbstractArchitecture<T>:IArchitecture where T:AbstractArchitecture<T>,new()
+    {
+        private static IArchitecture architectureInstance;
+        private List<IModel> modelList;
+        private List<IService> serviceList;
+        private IOCContainer modelContainer = new IOCContainer();
+        private IOCContainer serviceContainer=new IOCContainer();
+        private IOCContainer utilityContainer = new IOCContainer();
+        private ITypeEventSystem eventSystem=new DefaultTypeEventSystem();
+        private ICommandHandler commandHandle=new DefaultCommandHandler();
+        private IQueryHandler queryHandler = new DefaultQueryHandler();
+
+        /// <summary>
+        /// 设置Architecture_Instance
+        /// </summary>
+        void IArchitecture.SetArchitectureInstance(IArchitecture instance)
+        {
+            architectureInstance = instance;
+            ICanGetModelExtension.SetArchitecture(architectureInstance);
+            ICanGetServiceExtension.SetArchitecture(architectureInstance);
+            ICanGetUtilityExtension.SetArchitecture(architectureInstance);
+            IArchitectureModuleExtension.SetArchitecture(architectureInstance);
+            ICanSendCommandExtension.SetCommandHandler(commandHandle);
+            ICanTriggerEventExtension.SetEventSystem(eventSystem);
+            ICanSubscribeEventExtension.SetEventSystem(eventSystem);
+            IChainEventUnSubcribeExtension.SetEventSystem(eventSystem);
+            ICanSendQueryExtension.SetQueryHandler(queryHandler);
+        }
+
+        /// <summary>
+        /// 注册
+        /// </summary>
+        void IArchitecture.Register()
+        {
+            modelList = new List<IModel>();
+            serviceList = new List<IService>();
+            OnInit();
+        }
+
+        /// <summary>
+        /// 初始化Architecture
+        /// </summary>
+        void IArchitecture.InitArchitecture()
+        {
+            InitModels();
+            InitServices();
+        }
+
+        /// <summary>
+        /// 完成初始化Architecture
+        /// </summary>
+        void IArchitecture.FinishInit()
+        {
+            modelList.Clear();
+            serviceList.Clear();
+            modelList = null;
+            serviceList = null;
+        }
+
+        /// <summary>
+        /// 初始化 Model 层
+        /// </summary>
+        private void InitModels()
+        {
+            foreach (var model in modelList)
+            {
+                model.OnInit();
+            }
+            /*modelList.Clear();
+            modelList = null;*/
+        }
+
+        /// <summary>
+        /// 初始化 Services 层
+        /// </summary>
+        private void InitServices()
+        {
+            foreach (var service in serviceList)
+            {
+                service.OnInit();
+            }
+            /*serviceList.Clear();
+            serviceList = null;*/
+        }
+
+        protected abstract void OnInit();
+
+        /// <summary>
+        /// 设置事件系统
+        /// </summary>
+        protected virtual void SetTypeEventSystem(ITypeEventSystem typeEventSystem)
+        {
+            eventSystem = typeEventSystem;
+        }
+
+        /// <summary>
+        /// 获取 Model
+        /// </summary>
+        public K GetModel<K>() where K:IModel
+        {
+            return modelContainer.Get<K>();
+        }
+
+        /// <summary>
+        /// 获取 Service
+        /// </summary>
+        public K GetService<K>() where K : IService
+        {
+            return serviceContainer.Get<K>();
+        }
+
+        /// <summary>
+        /// 获取 Utility
+        /// </summary>
+        public K GetUtility<K>() where K : IUtility
+        {
+            return utilityContainer.Get<K>();
+        }
+
+        /// <summary>
+        /// 获取 Model
+        /// </summary>
+        public object GetModel(Type type)
+        {
+            return modelContainer.Get(type);
+        }
+
+        /// <summary>
+        /// 获取 Service
+        /// </summary>
+        public object GetService(Type type)
+        {
+            return serviceContainer.Get(type);
+        }
+
+        /// <summary>
+        /// 获取 Utility
+        /// </summary>
+        public object GetUtility(Type type)
+        {
+            return utilityContainer.Get(type);
+        }
+
+        /// <summary>
+        /// 注册 Model
+        /// </summary>
+        public void RegisterModel<K>() where K :  IModel, new()
+        {
+            RegisterModel(new K());
+        }
+
+        /// <summary>
+        /// 注册 Service
+        /// </summary>
+        public void RegisterService<K>() where K : IService, new()
+        {
+            RegisterService(new K());
+        }
+
+        /// <summary>
+        /// 注册 Utility
+        /// </summary>
+        public void RegisterUtility<K>() where K : IUtility, new()
+        {
+            RegisterUtility(new K());
+        }
+
+        /// <summary>
+        /// 注册 Model
+        /// </summary>
+        public void RegisterModel<K>(K modelInstance) where K : IModel
+        {
+            modelContainer.Register(modelInstance);
+            modelList.Add(modelInstance);
+        }
+
+        /// <summary>
+        /// 注册 Service
+        /// </summary>
+        public void RegisterService<K>(K serviceInstance) where K : IService
+        {
+            serviceContainer.Register(serviceInstance);
+            serviceList.Add(serviceInstance);
+        }
+
+        /// <summary>
+        /// 注册 Utility
+        /// </summary>
+        public void RegisterUtility<K>(K utilityInstance) where K : IUtility
+        {
+            utilityContainer.Register(utilityInstance);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/AbstractArchitecture.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 32afae3298447024aa4cfeb2e4c7f555
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 130 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/ArchitectureInitiator.cs

@@ -0,0 +1,130 @@
+using System;
+using System.Reflection;
+using UnityEngine;
+using UnityEngine.Scripting;
+
+namespace Blue
+{
+    [Preserve]
+    internal sealed class ArchitectureInitiator
+    {
+        private ArchitectureInitiator() { }
+
+        private Type architectureType = typeof(IArchitecture);
+        private IArchitecture architectureInstance = null;
+        private IInjector mInjector;
+        private bool architectureInited = false;
+        //private bool
+        private static ArchitectureInitiator mInstance;
+        private ModuleInitiator moduleInitiator;
+
+        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
+        private static void Initiate()
+        {
+            mInstance = new ArchitectureInitiator();
+            mInstance.CreateInjector();
+            mInstance.CreateModuleInitiator();
+            Type[] typeArr = Assembly.GetExecutingAssembly().GetTypes();
+            int typeLength = typeArr.Length;
+            for (int i = 0; i < typeLength; i++)
+            {
+                Type tmpType = typeArr[i];
+                if (!tmpType.IsInterface) 
+                {
+                    if (mInstance.IsArchitecture(tmpType))
+                    {
+                        mInstance.CreateArchitectureInstance(tmpType);
+                    }
+                    mInstance.PrepairModuleData(tmpType);
+                    mInstance.PrepairInjectionData(tmpType);
+                }
+            }
+            mInstance.RegisterArchitecture();
+            StartInject();
+            mInstance.InitArchitecture();
+            mInstance.FinishInit();
+        }
+        //[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
+        private static void StartInject() 
+        {
+            Debug.Log("StartInject");
+            mInstance.Inject();
+            //mInstance.Clear();
+        }
+        private void Clear() 
+        {
+            mInjector.Dispose();
+            moduleInitiator.Dispose();
+            mInjector = null;
+            moduleInitiator = null;
+            mInstance = null;
+        }
+        private void Inject() 
+        {
+            mInjector.Inject(architectureInstance);
+        }
+        private void FinishInit()
+        {
+            architectureInstance.FinishInit();
+            mInstance.Clear();
+        }
+        private void RegisterArchitecture()
+        {
+            if (architectureInstance != null)
+            {
+                architectureInstance.SetArchitectureInstance(architectureInstance);
+                architectureInstance.Register();
+                InitModule();
+            }
+        }
+        private void InitArchitecture()
+        {
+            architectureInstance.InitArchitecture();
+        }
+        private void InitModule() 
+        {
+            moduleInitiator.InitModule();
+        }
+        private bool IsArchitecture(Type tmpType)
+        {
+            if (architectureInited) 
+            {
+                return false;
+            }
+            if (tmpType.IsAbstract)
+            {
+                return false;
+            }
+            return architectureType.IsAssignableFrom(tmpType);
+        }
+        private void PrepairModuleData(Type type) 
+        {
+            moduleInitiator.PrepairModuleData(type);
+        }
+
+        private void CreateArchitectureInstance(Type archiType)
+        {
+            if (architectureInstance == null)
+            {
+                architectureInstance = (IArchitecture)Activator.CreateInstance(archiType);
+                architectureInited = true;
+            }
+            else
+            {
+                throw new Exception("More than one Architecture sub-class in the application,it should be only one!");
+            }
+        }
+        private void PrepairInjectionData(Type type) 
+        {
+            mInjector.PrepairInjectionData(type);
+        }
+        private void CreateModuleInitiator() 
+        {
+            moduleInitiator=new ModuleInitiator();
+        }
+        private void CreateInjector() 
+        {
+            mInjector = new ArchitectureInjecter();
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/ArchitectureInitiator.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1ab12634675f7e9449ae7461b5e0b8f6
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 29 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitecture.cs

@@ -0,0 +1,29 @@
+using System;
+using UnityEngine.Scripting;
+namespace Blue
+{
+    /// <summary>
+    /// Architecture 接口
+    /// </summary>
+    [RequireImplementors]
+    public interface IArchitecture
+    {
+        void SetArchitectureInstance(IArchitecture instance);
+        void Register();
+        void InitArchitecture();
+        void FinishInit();
+        T GetService<T>() where T : IService;
+        T GetModel<T>() where T : IModel;
+        T GetUtility<T>() where T : IUtility;
+        object GetService(Type type);
+        object GetModel(Type type);
+        object GetUtility(Type type);
+        void RegisterService<T>() where T : IService,new();
+        void RegisterModel<T>() where T : IModel,new();
+        void RegisterUtility<T>() where T : IUtility,new();
+
+        void RegisterModel<T>(T modelInstance) where T : IModel;
+        void RegisterService<T>(T serviceInstance) where T : IService;
+        void RegisterUtility<T>(T utilityInstance) where T : IUtility;
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitecture.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b31c733c3aa4cdd4b960743d9d431154
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModule.cs

@@ -0,0 +1,11 @@
+namespace Blue
+{
+    /// <summary>
+    /// 模块的基本接口
+    /// 所有模块都需要继承此接口并实现
+    /// </summary>
+    public interface IArchitectureModule
+    {
+        void OnInit();
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModule.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 2a74765de6b66d74dbf16b836db70b1a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 36 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModuleExtension.cs

@@ -0,0 +1,36 @@
+namespace Blue
+{
+    public static class IArchitectureModuleExtension
+    {
+        private static IArchitecture _architecture;
+        public static void SetArchitecture(IArchitecture architecture)
+        {
+            _architecture = architecture;
+        }
+        public static void RegisterModel<T>(this IArchitectureModule self) where T : IModel, new()
+        {
+            _architecture.RegisterModel<T>();
+        }
+        public static void RegisterModel<T>(this IArchitectureModule self,T modelInstance) where T : IModel
+        {
+            _architecture.RegisterModel<T>(modelInstance);
+        }
+
+        public static void RegisterService<T>(this IArchitectureModule self) where T:IService,new()
+        {
+            _architecture.RegisterService<T>();
+        }
+        public static void RegisterService<T>(this IArchitectureModule self,T serviceInstance) where T : IService
+        {
+            _architecture.RegisterService<T>(serviceInstance);
+        }
+        public static void RegisterUtility<T>(this IArchitectureModule self) where T : IUtility, new()
+        {
+            _architecture.RegisterUtility<T>();
+        }
+        public static void RegisterUtility<T>(this IArchitectureModule self, T utilityInstance) where T : IUtility
+        {
+            _architecture.RegisterUtility<T>(utilityInstance);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IArchitectureModuleExtension.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8a2172eafe60365449adcc0a04674f79
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 6 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/ICanInject.cs

@@ -0,0 +1,6 @@
+namespace Blue
+{
+    public interface ICanInject
+    {
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/ICanInject.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 52f5dfcb6f5a29a4b9f316ab29445925
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IController.cs

@@ -0,0 +1,9 @@
+namespace Blue
+{
+    /// <summary>
+    /// Controller 层接口
+    /// </summary>
+    public interface IController :ICanInject,ICanGetService,ICanGetModel,ICanGetUtility,ICanSendCommand,ICanSubscribeEvent,ICanSendQuery
+    {
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IController.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 66a47c3ec2764924ea72fb85f095fdc0
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IModel.cs

@@ -0,0 +1,10 @@
+namespace Blue
+{
+    /// <summary>
+    /// Model 层接口
+    /// </summary>
+    public interface IModel:ICanInject,ICanGetUtility,ICanTriggerEvent
+    {
+        void OnInit();
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IModel.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 503ddaef7fb374740b196c39b34d8ff4
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IService.cs

@@ -0,0 +1,10 @@
+namespace Blue
+{
+    /// <summary>
+    /// Service 层接口
+    /// </summary>
+    public interface IService : ICanInject,ICanGetService, ICanSendCommand,ICanGetModel, ICanGetUtility,ICanSubscribeEvent,ICanTriggerEvent,ICanSendQuery
+    {
+        void OnInit();
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IService.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e47cad12f256280419369689b8f3a46a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IUtility.cs

@@ -0,0 +1,9 @@
+namespace Blue
+{
+    /// <summary>
+    /// Utility 层接口
+    /// </summary>
+    public interface IUtility:ICanInject,ICanGetUtility
+    {
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/IUtility.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7969df155656a76438f58da4b53183d6
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 54 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/ModuleInitiator.cs

@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+
+namespace Blue
+{
+    public class ModuleInitiator:IDisposable
+    {
+        private Type moduleInterfaceType;
+        private List<Type> moduleList;
+        public ModuleInitiator() 
+        {
+            moduleInterfaceType = typeof(IArchitectureModule);
+            moduleList = new List<Type>();
+        }
+        public void PrepairModuleData(Type type) 
+        {
+            if (IsModule(type)) 
+            {
+                moduleList.Add(type);
+            }
+        }
+        public void InitModule() 
+        {
+            int moduleCount = moduleList.Count;
+            if (moduleCount == 0) 
+            {
+                return;
+            }
+            for (int i = 0; i < moduleCount; i++)
+            {
+                IArchitectureModule module =(IArchitectureModule)Activator.CreateInstance(moduleList[i]);
+                module.OnInit();
+            }
+        }
+
+        public void Dispose() 
+        {
+            moduleInterfaceType = null;
+            moduleList = null;
+        }
+        private bool IsModule(Type type)
+        {
+            if (type.IsInterface)
+            {
+                return false;
+            }
+            if (type.IsAbstract)
+            {
+                return false;
+            }
+            return moduleInterfaceType.IsAssignableFrom(type);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Core/ModuleInitiator.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5188fd3725c63fd4d9e31632b19b0172
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Scripts/Blue/0.FrameworkDesign/Design.eddx


+ 7 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Design.eddx.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 2b7919ae31a57be4fbcef440aece1f8b
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 182ecb4e6148c144eb1311060ec35775
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 22 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/BindablePropertyUnSubscribe.cs

@@ -0,0 +1,22 @@
+using System;
+namespace Blue
+{
+    public struct BindablePropertyUnSubscribe<T> : IUnSubscribe
+    {
+        private Action<T> _onPropertyChanged;
+        private BindableProperty<T> _property;
+
+        public BindablePropertyUnSubscribe(BindableProperty<T> property,Action<T> onPropertyChanged) 
+        {
+            _property = property;
+            _onPropertyChanged = onPropertyChanged;
+        }
+
+        public void UnSubscribe()
+        {
+            _property.UnSubscribe(_onPropertyChanged);
+            _property = null;
+            _onPropertyChanged = null;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/BindablePropertyUnSubscribe.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d06c79933b7d1364a82598aeb1b21625
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 41 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/ChainEventSubscription.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+
+
+namespace Blue {
+    public class ChainEventSubscription : IChainEventSubscription
+    {
+        private Dictionary<Type, int> actionHashPool;
+        private Type mChainEventType;
+        public ChainEventSubscription(Type chainEventType)
+        {
+            mChainEventType = chainEventType;
+        }
+        public int SubscribeCount => actionHashPool.Count;
+
+        public IChainEventUnSubscribe Subscribe(Type eventType,int actionHashCode,Action onOnSubscribe)
+        {
+            actionHashPool.TryAdd(eventType, actionHashCode);
+            return new DefaultChainEventUnSubcribe(mChainEventType, () => { onOnSubscribe?.Invoke(); UnSubscribe(eventType); });
+        }
+        public bool IsSubscribed(Type eventType)
+        {
+            return actionHashPool.ContainsKey(eventType);
+        }
+        public int GetActionHashCode(Type eventType)
+        {
+            return actionHashPool[eventType];
+        }
+        public List<Type> GetEventTypeList()
+        {
+            List<Type> valueList = new List<Type>(actionHashPool.Count);
+            valueList.AddRange(actionHashPool.Keys);
+            return valueList;
+        }
+
+        public bool UnSubscribe(Type eventType)
+        {
+            return actionHashPool.Remove(eventType);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/ChainEventSubscription.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f66d043e4732e3c4ea955f6d1eb44fbe
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 27 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultChainEventUnSubcribe.cs

@@ -0,0 +1,27 @@
+using System;
+namespace Blue
+{
+
+    public class DefaultChainEventUnSubcribe : IChainEventUnSubscribe
+    {
+        private Action mOnUnSub;
+        private Type mChainEventType;
+        public DefaultChainEventUnSubcribe(Type chainEventType,Action onUnSub)
+        {
+            mChainEventType = chainEventType;
+            mOnUnSub = onUnSub;
+        }
+
+        public Type GetChainEventType()
+        {
+            return mChainEventType;
+        }
+
+        public void UnSubscribe()
+        {
+            mOnUnSub?.Invoke();
+            mOnUnSub = null;
+            mChainEventType = null;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultChainEventUnSubcribe.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6a5468baf24a91541953bb08963c7d19
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 160 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultTypeEventSystem.cs

@@ -0,0 +1,160 @@
+using System;
+using System.Collections.Generic;
+
+namespace Blue
+{
+    /// <summary>
+    /// 默认事件系统类,实现ITypeEventSystem
+    /// </summary>
+    public class DefaultTypeEventSystem : ITypeEventSystem
+    {
+        private Dictionary<Type, ISubscription> eventSubscriptionPool = new Dictionary<Type, ISubscription>(128);
+        private Dictionary<Type, IChainEventSubscription> chainEventPool = new Dictionary<Type, IChainEventSubscription>(8);
+        public IUnSubscribe SubscribeEvent<T>(Action<T> onEvent) where T : IEvent
+        {
+            Type t = typeof(T);
+            ISubscription subscription;
+            var adapter = new EventToActionAdapter(onEvent.GetHashCode(),(ievent) => { onEvent?.Invoke((T)ievent); });
+            if (!eventSubscriptionPool.TryGetValue(t, out subscription))
+            {
+                subscription = new TypeEventSubscription(t);
+                eventSubscriptionPool.Add(t, subscription);
+            }
+            return subscription.Subscribe(adapter);
+        }
+
+        public IChainEventUnSubscribe SubscribeChainEvent<T,K>(Action<K> onEvent) where T : IChainEvent where K:IEvent
+        {
+            Type chainEventType = typeof(T);
+            return SubscribeChainEvent(chainEventType,onEvent);
+        }
+        public IChainEventUnSubscribe SubscribeChainEvent<K>(Type chainEventType, Action<K> onEvent) where K : IEvent 
+        {
+            Type eventType = typeof(K);
+            IChainEventSubscription chainSubscription;
+            if (!chainEventPool.TryGetValue(chainEventType, out chainSubscription))
+            {
+                chainSubscription = new ChainEventSubscription(chainEventType);
+                chainEventPool.Add(chainEventType, chainSubscription);
+            }
+            if (chainSubscription.IsSubscribed(eventType))
+            {
+                UnSubscribeEvent(eventType, chainSubscription.GetActionHashCode(eventType));
+                chainSubscription.UnSubscribe(eventType);
+            }
+            ISubscription eventSubscription;
+            var adapter = new EventToActionAdapter(onEvent.GetHashCode(), (ievent) => { onEvent?.Invoke((K)ievent); });
+            if (!eventSubscriptionPool.TryGetValue(eventType, out eventSubscription))
+            {
+                eventSubscription = new TypeEventSubscription(eventType);
+                eventSubscriptionPool.Add(eventType, eventSubscription);
+            }
+            eventSubscription.Subscribe(adapter);
+            return chainSubscription.Subscribe(eventType, onEvent.GetHashCode(),()=> { eventSubscription.UnSubscribe(onEvent.GetHashCode()); });
+        }
+        public void TriggerEvent<T>() where T : IEvent, new()
+        {
+            TriggerEvent(new T());
+        }
+
+        public void TriggerEvent<T>(T e) where T : IEvent
+        {
+            if (eventSubscriptionPool.TryGetValue(e.GetType(), out ISubscription subscription))
+            {
+                subscription.TriggerEvent(e);
+            }
+        }
+
+        public void TriggerChainEvent<T>(params IEvent[] events) where T:IChainEvent
+        {
+            IChainEventSubscription chainSubscription;
+            Type chainEventType = typeof(T);
+            if (chainEventPool.TryGetValue(chainEventType, out chainSubscription))
+            {
+                Dictionary<Type, IEvent> eventInstanceMap = new Dictionary<Type, IEvent>(events.Length);
+                foreach (var mEvent in events)
+                {
+                    eventInstanceMap.TryAdd(mEvent.GetType(),mEvent);
+                }
+                List<Type> chainEventTypeList=chainSubscription.GetEventTypeList();
+                foreach (var eventType in chainEventTypeList)
+                {
+                    IEvent eventInstance;
+                    if (!eventInstanceMap.TryGetValue(eventType, out eventInstance))
+                    {
+                        eventInstance = (IEvent)Activator.CreateInstance(eventType);
+                    }
+                    TriggerEvent(eventInstance);
+                }
+            }
+        }
+        public void TriggerChainEvent<T>() where T : IChainEvent
+        {
+            IChainEventSubscription chainSubscription;
+            Type chainEventType = typeof(T);
+            if (chainEventPool.TryGetValue(chainEventType, out chainSubscription))
+            {
+                List<Type> chainEventTypeList = chainSubscription.GetEventTypeList();
+                foreach (var eventType in chainEventTypeList)
+                {
+                    TriggerEvent((IEvent)Activator.CreateInstance(eventType));
+                }
+            }
+        }
+
+        public void UnSubscribeEvent<T>(Action<T> onEvent) where T : IEvent
+        {
+            Type t = typeof(T);
+            UnSubscribeEvent(t, onEvent.GetHashCode());
+        }
+        public void UnSubscribeChainEvent<T>() where T:IChainEvent
+        {
+            Type chainEventType = typeof(T);
+            UnSubscribeChainEvent(chainEventType);
+        }
+        public void UnSubscribeChainEvent(Type chainEventType)
+        {
+            IChainEventSubscription chainSubscription;
+            if (chainEventPool.TryGetValue(chainEventType, out chainSubscription))
+            {
+                List<Type> chainEventTypeList= chainSubscription.GetEventTypeList();
+                foreach (var eventType in chainEventTypeList)
+                {
+                    UnSubscribeEvent(eventType,chainSubscription.GetActionHashCode(eventType));
+                    chainSubscription.UnSubscribe(eventType);
+                }
+                chainEventPool.Remove(chainEventType);
+            }
+        }
+        public void UnSubscribeEventFromChainEvent<T, K>() where T : IChainEvent where K : IEvent
+        {
+            IChainEventSubscription chainSubscription;
+            Type chainEventType = typeof(T);
+            if (chainEventPool.TryGetValue(chainEventType, out chainSubscription))
+            {
+                Type eventType = typeof(K);
+                if (chainSubscription.UnSubscribe(eventType))
+                {
+                    UnSubscribeEvent(eventType,chainSubscription.GetActionHashCode(eventType));
+                }
+                if (chainSubscription.SubscribeCount == 0)
+                {
+                    chainEventPool.Remove(chainEventType);
+                }
+            }
+        }
+        private bool UnSubscribeEvent(Type eventType, int hash)
+        {
+            bool result = false;
+            if (eventSubscriptionPool.TryGetValue(eventType, out ISubscription subscription))
+            {
+                result=subscription.UnSubscribe(hash);
+                if (subscription.SubscribeCount <= 0)
+                {
+                    eventSubscriptionPool.Remove(eventType);
+                }
+            }
+            return result;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/DefaultTypeEventSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b1c6bf9c7ceccdc48be0e5670f6cbbbf
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 49 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/EventToActionAdapter.cs

@@ -0,0 +1,49 @@
+using System;
+namespace Blue
+{
+    /// <summary>
+    /// Event Action 适配
+    /// </summary>
+    public struct EventToActionAdapter
+    {
+        private Action<IEvent> mAdapterAction;
+        private int mHashCode;
+
+        /// <summary>
+        /// 初始化 hashCode ,Action
+        /// </summary>
+        /// <param name="hashCode"></param>
+        /// <param name="adapterAction"></param>
+        public EventToActionAdapter(int hashCode,Action<IEvent> adapterAction)
+        {
+            mHashCode = hashCode;
+            mAdapterAction = adapterAction;
+        }
+
+        /// <summary>
+        /// 获取适配的 Action
+        /// </summary>
+        /// <returns></returns>
+        public Action<IEvent> GetAdapterAction()
+        {
+            return mAdapterAction;
+        }
+
+        /// <summary>
+        /// 获取 Action 的 HashCode
+        /// </summary>
+        /// <returns></returns>
+        public int GetActionHashCode()
+        {
+            return mHashCode;
+        }
+
+        /// <summary>
+        /// 清除 Action
+        /// </summary>
+        public void Clear()
+        {
+            mAdapterAction = null;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/EventToActionAdapter.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 508bb6b400b007049905805f0b89a427
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEvent.cs

@@ -0,0 +1,8 @@
+using System;
+namespace Blue
+{
+    public interface IChainEvent : IEvent
+    {
+        //IChainEvent NextEvent<T>(Action<T> onEvent) where T : IEvent;
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEvent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9f4f56a81d70e9749a9dce79de2bdb63
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 18 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventSubscription.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+
+namespace Blue
+{
+	/// <summary>
+	/// 订阅链事件的接口
+	/// </summary>
+	public interface IChainEventSubscription
+	{
+		int SubscribeCount { get; }
+		IChainEventUnSubscribe Subscribe(Type eventType, int actionHashCode, Action onOnSubscribe);
+		List<Type> GetEventTypeList();
+		bool IsSubscribed(Type eventType);
+		int GetActionHashCode(Type eventType);
+		bool UnSubscribe(Type eventType);
+	}
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventSubscription.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ced60633d27b154448f77c490aafd9b3
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 31 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubcribeExtension.cs

@@ -0,0 +1,31 @@
+using System;
+using UnityEngine;
+namespace Blue
+{
+    public static class IChainEventUnSubcribeExtension
+    {
+        private static ITypeEventSystem _typeEventSystem;
+        public static void SetEventSystem(ITypeEventSystem typeEventSystem) 
+        {
+            _typeEventSystem = typeEventSystem;
+        }
+        public static void UnSubscribeAllEventOnGameobjectDestroyed(this IChainEventUnSubscribe unSubscribe, GameObject gameObject)
+        {
+            var trigger = gameObject.GetComponent<UnSubscribeChainEventOnDestroyTrigger>();
+            if (!trigger)
+            {
+                trigger = gameObject.AddComponent<UnSubscribeChainEventOnDestroyTrigger>();
+            }
+            trigger.AddUnSubscribe(unSubscribe);
+        }
+        public static IChainEventUnSubscribe NextEvent<T>(this IChainEventUnSubscribe self,Action<T> onEvent) where T:IEvent
+        {
+            return _typeEventSystem.SubscribeChainEvent(self.GetChainEventType(),onEvent);
+        }
+
+        public static void UnSubscribeAllEventsOnChain(this IChainEventUnSubscribe self) 
+        {
+            _typeEventSystem.UnSubscribeChainEvent(self.GetChainEventType());
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubcribeExtension.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9b6a4df5b9e8d2d46beeec36947e9988
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubscribe.cs

@@ -0,0 +1,11 @@
+using System;
+namespace Blue
+{
+    /// <summary>
+    /// 链事件取消订阅事件的接口
+    /// </summary>
+    public interface IChainEventUnSubscribe:IUnSubscribe
+    {
+        Type GetChainEventType();
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IChainEventUnSubscribe.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1d1c4a86f4744964488f49a0f96be4a9
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 6 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IEvent.cs

@@ -0,0 +1,6 @@
+namespace Blue
+{
+    public interface IEvent
+    {
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IEvent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: fc15043a7bae13545a4917169a4dafbb
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 13 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/ISubscription.cs

@@ -0,0 +1,13 @@
+namespace Blue
+{
+    /// <summary>
+    /// 订阅事件的接口
+    /// </summary>
+    public interface ISubscription
+    {
+        int SubscribeCount { get; }
+        IUnSubscribe Subscribe(EventToActionAdapter adapter);
+        bool UnSubscribe(int hashCode);
+        void TriggerEvent(IEvent e);
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/ISubscription.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 84b9daa0c1696a24aa1da163cfef3d92
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 28 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/ITypeEventSystem.cs

@@ -0,0 +1,28 @@
+using System;
+namespace Blue
+{
+    /// <summary>
+    /// 事件系统接口
+    /// ① 注册事件、注册链事件
+    /// ② 订阅事件、订阅链事件
+    /// ③ 取消订阅事件、取消订阅链事件
+    /// ④ 取消订阅链事件中的事件
+    /// </summary>
+    public interface ITypeEventSystem
+    {
+        void TriggerEvent<T>() where T : IEvent, new();
+        void TriggerEvent<T>(T e) where T : IEvent;
+        void TriggerChainEvent<T>(params IEvent[] events) where T : IChainEvent;
+        void TriggerChainEvent<T>() where T : IChainEvent;
+
+        IUnSubscribe SubscribeEvent<T>(Action<T> onEvent) where T : IEvent;
+        IChainEventUnSubscribe SubscribeChainEvent<T, K>(Action<K> onEvent) where T : IChainEvent where K : IEvent;
+        IChainEventUnSubscribe SubscribeChainEvent<K>(Type chainEventType,Action<K> onEvent) where K : IEvent;
+
+        void UnSubscribeEvent<T>(Action<T> onEvent) where T : IEvent;
+        void UnSubscribeChainEvent<T>() where T : IChainEvent;
+        void UnSubscribeChainEvent(Type chainEventType);
+
+        void UnSubscribeEventFromChainEvent<T, K>() where T : IChainEvent where K : IEvent;
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/ITypeEventSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d82e9e7dfba9ff94fb9aecdfd3d6b496
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribe.cs

@@ -0,0 +1,11 @@
+using System;
+namespace Blue
+{
+    /// <summary>
+    /// 取消订阅事件的接口
+    /// </summary>
+    public interface IUnSubscribe
+    {
+        void UnSubscribe();
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribe.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5688daa9d0182bb41b587264043cb717
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 26 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribeExtension.cs

@@ -0,0 +1,26 @@
+using UnityEngine;
+namespace Blue
+{
+    public static class IUnSubscribeExtension
+    {
+        public static void UnSubScribeWhenGameObjectDestroyed(this  IUnSubscribe unSubscribe,GameObject gameObject) 
+        {
+            var trigger= gameObject.GetComponent<UnSubscribeOnDestroyTrigger>();
+            if (!trigger) 
+            {
+                trigger = gameObject.AddComponent<UnSubscribeOnDestroyTrigger>();
+            }
+            trigger.AddUnSubscribe(unSubscribe);
+        }
+        public static void UnSubScribeWhenGameObjectDisabled(this IUnSubscribe unSubscribe, GameObject gameObject)
+        {
+            var trigger = gameObject.GetComponent<UnSubscribeOnDisableTrigger>();
+            if (!trigger)
+            {
+                trigger = gameObject.AddComponent<UnSubscribeOnDisableTrigger>();
+            }
+            trigger.AddUnSubscribe(unSubscribe);
+        }
+
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/IUnSubscribeExtension.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 303c2a2d213a0334190a068194e50398
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 49 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSubscription.cs

@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+namespace Blue
+{
+    public class TypeEventSubscription : ISubscription
+    {
+        private Action<IEvent> mOnEvent;
+        private int subscribeCount;
+        private Type mEventType;
+        private Dictionary<int, EventToActionAdapter> adapterPool = new Dictionary<int, EventToActionAdapter>();
+        public TypeEventSubscription(Type eventType) 
+        {
+            mEventType = eventType;
+        }
+        public int SubscribeCount { get => subscribeCount;}
+        public IUnSubscribe Subscribe(EventToActionAdapter adapter)
+        {
+            try
+            {
+                adapterPool.Add(adapter.GetActionHashCode(), adapter);
+                mOnEvent += adapter.GetAdapterAction();
+                subscribeCount++;
+                return new TypeEventSystemUnSubscribe(() => { UnSubscribe(adapter.GetActionHashCode()); });
+            }
+            catch (ArgumentException)
+            {
+                //LogUtil.LogError("Event subscription duplicated on "+mEventType+",please make sure you have unsubscribe it before re-subscribe!");
+                throw;
+            }
+        }
+        public void TriggerEvent(IEvent e)
+        {
+            mOnEvent?.Invoke(e);
+        }
+
+        public bool UnSubscribe(int hashCode)
+        {
+            if (adapterPool.TryGetValue(hashCode, out var adapter)) 
+            {
+                mOnEvent -= adapter.GetAdapterAction();
+                subscribeCount--;
+                adapter.Clear();
+                adapterPool.Remove(hashCode);
+                return true;
+            }
+            return false;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSubscription.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a3815b906ccbdc8468f82c22c1822841
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 19 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSystemUnSubscribe.cs

@@ -0,0 +1,19 @@
+using System;
+
+namespace Blue
+{
+
+    public struct TypeEventSystemUnSubscribe : IUnSubscribe
+    {
+        private Action mOnUnSubscribe;
+        public TypeEventSystemUnSubscribe(Action onUnSubscribe) 
+        {
+            mOnUnSubscribe = onUnSubscribe;
+        }
+        public void UnSubscribe() 
+        {
+            mOnUnSubscribe?.Invoke();
+            mOnUnSubscribe = null;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/TypeEventSystemUnSubscribe.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 44ae6ff8f6dfeb844bac5d1b65b54d80
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 22 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeChainEventOnDestroyTrigger.cs

@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using UnityEngine;
+namespace Blue
+{
+    public class UnSubscribeChainEventOnDestroyTrigger : MonoBehaviour
+    {
+        private HashSet<IChainEventUnSubscribe> unSubscribes = new HashSet<IChainEventUnSubscribe>();
+
+        public void AddUnSubscribe(IChainEventUnSubscribe unSubscribe)
+        {
+            unSubscribes.Add(unSubscribe);
+        }
+        private void OnDestroy()
+        {
+            foreach (var item in unSubscribes)
+            {
+                item.UnSubscribeAllEventsOnChain();
+            }
+            unSubscribes.Clear();
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeChainEventOnDestroyTrigger.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e2ea2cf248d81c942b3e2f71515b8a5a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 22 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDestroyTrigger.cs

@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using UnityEngine;
+namespace Blue
+{
+    public class UnSubscribeOnDestroyTrigger : MonoBehaviour
+    {
+        private HashSet<IUnSubscribe> unSubscribes = new HashSet<IUnSubscribe>();
+
+        public void AddUnSubscribe(IUnSubscribe unSubscribe) 
+        {
+            unSubscribes.Add(unSubscribe);
+        }
+        private void OnDestroy()
+        {
+            foreach (var item in unSubscribes)
+            {
+                item.UnSubscribe();
+            }
+            unSubscribes.Clear();
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDestroyTrigger.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 2410ca90123a40f40b013a57fed4236d
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 22 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDisableTrigger.cs

@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using UnityEngine;
+namespace Blue
+{
+    public class UnSubscribeOnDisableTrigger : MonoBehaviour
+    {
+        private HashSet<IUnSubscribe> unSubscribes = new HashSet<IUnSubscribe>();
+
+        public void AddUnSubscribe(IUnSubscribe unSubscribe) 
+        {
+            unSubscribes.Add(unSubscribe);
+        }
+        private void OnDisable()
+        {
+            foreach (var item in unSubscribes)
+            {
+                item.UnSubscribe();
+            }
+            unSubscribes.Clear();
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/Event/UnSubscribeOnDisableTrigger.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 67d3e185b45a31b46ae1d9b41aaefd8d
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: f127b83d66b479f4289ea12e6c748925
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 236 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/AbstractArchitectureComponentInjector.cs

@@ -0,0 +1,236 @@
+using System;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Blue
+{
+    public abstract class AbstractArchitectureComponentInjector : IArchitectureComponentInjector
+    {
+        private Type mComponentType;
+        private bool canInjectTypeListNotInitiated=true;
+        private List<Type> canInjectTypeList;
+        private Dictionary<Type, List<InjectInfo>> injectionMap;
+        protected IArchitecture architectureInstance;
+
+        public AbstractArchitectureComponentInjector(Type componentType)
+        {
+            SetComponentType(componentType);
+        }
+        public void SetArchitecture(IArchitecture architecture)
+        {
+            if (architectureInstance == null)
+            {
+                architectureInstance = architecture;
+            }
+        }
+        private void SetComponentType(Type componentType)
+        {
+            mComponentType = componentType;
+        }
+
+        public virtual void PrepairInjectionData(Type baseType)
+        {
+            if (canInjectTypeListNotInitiated)
+            {
+                canInjectTypeListNotInitiated = false;
+                injectionMap = new Dictionary<Type, List<InjectInfo>>();
+                canInjectTypeList = GetCanInjectTypeList(mComponentType);
+            }
+            FilterInjectInfoList(GetInjectInfo(baseType), mComponentType);
+        }
+        public virtual void Inject(IArchitecture architecture)
+        {
+            if (injectionMap == null)
+            {
+                return;
+            }
+            SetArchitecture(architecture);
+            int injectionCount = injectionMap.Count;
+            List<Type> types = new List<Type>(injectionCount);
+            types.AddRange(injectionMap.Keys);
+            if (injectionCount > 0)
+            {
+                for (int i = 0; i < injectionCount; i++)
+                {
+                    Type baseType = types[i];
+                    object injectObject = GetInjectObject(baseType);
+                    if (injectObject == null)
+                    {
+                        continue;
+                        //throw new Exception("Can not find instance of "+baseType.FullName+" ,please make sure you have registed it.");
+                    }
+                    if (!injectObject.GetType().Equals(baseType))
+                    {
+                        continue;//Not the registed Type
+                    }
+                    List<InjectInfo> typeInjectInfoList = injectionMap[baseType];
+                    foreach (InjectInfo injectInfo in typeInjectInfoList)
+                    {
+                        if (injectInfo.InjectScope == InjectScope.Prototype)
+                        {
+                            InjectPrototype(injectObject, injectInfo.InjectField, injectInfo.InjectType);
+                        }
+                        else
+                        {
+                            object injectInstance = GetInjectInstance(injectInfo.InjectType);
+                            InjectSingleton(injectObject, injectInfo.InjectField, injectInstance);
+                        }
+                    }
+                }
+            }
+        }
+        public void Dispose()
+        {
+            if (canInjectTypeList != null)
+            {
+                canInjectTypeList.Clear();
+                canInjectTypeList = null;
+            }
+            if (injectionMap != null)
+            {
+                injectionMap.Clear();
+                injectionMap = null;
+            }
+            mComponentType = null;
+            architectureInstance = null;
+        }
+        protected virtual object GetInjectObject(Type baseType)
+        {
+            return null;
+        }
+        protected virtual object GetInjectInstance(Type injectType)
+        {
+            if (TypeChecker.Instance.IsService(injectType))
+            {
+                return architectureInstance.GetService(injectType);
+            }
+            if (TypeChecker.Instance.IsModel(injectType))
+            {
+                return architectureInstance.GetModel(injectType);
+            }
+            if (TypeChecker.Instance.IsUtility(injectType))
+            {
+                return architectureInstance.GetUtility(injectType);
+            }
+            throw new Exception(injectType.FullName+" is not a can inject type!");
+        }
+        protected Dictionary<Type, List<InjectInfo>> GetInjectionMap()
+        {
+            return injectionMap;
+        }
+        protected void InjectSingleton(object injectObject, FieldInfo fieldInfo, object injectInstance)
+        {
+            fieldInfo.SetValue(injectObject, injectInstance);
+        }
+        protected void InjectPrototype(object injectObject, FieldInfo fieldInfo, Type injectType)
+        {
+            fieldInfo.SetValue(injectObject, Activator.CreateInstance(injectType));
+        }
+
+        private List<Type> GetCanInjectTypeList(Type baseType)
+        {
+            List<Type> canInjectTypeList = new List<Type>();
+            Type[] interfaceArr = baseType.GetInterfaces();
+            for (int i = 0; i < interfaceArr.Length; i++)
+            {
+                Type interfaceType = interfaceArr[i];
+                InjectRuleAttribute attribute = null;
+                if ((attribute = interfaceType.GetCustomAttribute<InjectRuleAttribute>()) != null)
+                {
+                    canInjectTypeList.AddRange(attribute.GetCanInjectList());
+                }
+            }
+            return canInjectTypeList;
+        }
+        private List<InjectInfo> GetInjectInfo(Type tmpType)
+        {
+            List<InjectInfo> injectInfoList = new List<InjectInfo>();
+            FieldInfo[] tmpFieldArr = tmpType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
+            int length = 0;
+            if (tmpFieldArr != null)
+            {
+                length = tmpFieldArr.Length;
+            }
+            for (int i = 0; i < length; i++)
+            {
+                FieldInfo tmpField = tmpFieldArr[i];
+                AutoInjectAttribute autoInjectAttribute = tmpField.GetCustomAttribute<AutoInjectAttribute>();
+                if (autoInjectAttribute != null)
+                {
+                    InjectInfo injectInfo = new InjectInfo()
+                    {
+                        BaseType = tmpType,
+                        InjectField = tmpField,
+                        InjectScope = autoInjectAttribute.GetInjectScope()
+                    };
+                    if (autoInjectAttribute.GetInjectType() != null)
+                    {
+                        if (CheckType(tmpField.FieldType, autoInjectAttribute.GetInjectType()))
+                        {
+                            injectInfo.InjectType = autoInjectAttribute.GetInjectType();
+                        }
+                        else
+                        {
+                            throw new Exception("Can not finish the injection of:" + tmpType.FullName + ": property: " + tmpField.Name + ", please check the injectType!");
+                        }
+                    }
+                    else
+                    {
+                        injectInfo.InjectType = tmpField.FieldType;
+                    }
+                    injectInfoList.Add(injectInfo);
+                }
+            }
+            return injectInfoList;
+        }
+        //if the injectinfo not match the inject rule,than remove it from the injectInfoList
+        //for example,you can not  inject a IService instance in a IMolde implementation class 
+        private void FilterInjectInfoList(List<InjectInfo> injectInfoList, Type type)
+        {
+            int count = injectInfoList.Count;
+            for (int i = 0; i < count; i++)
+            {
+                InjectInfo injectInfo = injectInfoList[i];
+                if (CheckIfCanInject(canInjectTypeList, injectInfo.InjectType))
+                {
+                    if (injectionMap.ContainsKey(injectInfo.BaseType))
+                    {
+                        injectionMap[injectInfo.BaseType].Add(injectInfo);
+                    }
+                    else
+                    {
+                        List<InjectInfo> typeInjectInfoList = new List<InjectInfo>();
+                        typeInjectInfoList.Add(injectInfo);
+                        injectionMap.Add(injectInfo.BaseType, typeInjectInfoList);
+                    }
+                }
+            }
+        }
+        //check if the fieldType and injectType is mismatch;
+        private bool CheckType(Type fieldType, Type injectType)
+        {
+            if (injectType.Equals(fieldType))
+            {
+                return true;
+            }
+            if (fieldType.IsInterface)
+            {
+                return fieldType.IsAssignableFrom(injectType);
+            }
+            return injectType.IsSubclassOf(fieldType);
+        }
+        private bool CheckIfCanInject(List<Type> canInjectTypeList, Type injectType)
+        {
+            bool result = false;
+            foreach (var canInjectType in canInjectTypeList)
+            {
+                if (canInjectType.IsAssignableFrom(injectType))
+                {
+                    result = true;
+                    break;
+                }
+            }
+            return result;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/AbstractArchitectureComponentInjector.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8214e77b5dfd03f4caf9b282e105b66c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 132 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ArchitectureInjecter.cs

@@ -0,0 +1,132 @@
+using System.Diagnostics;
+using System.Linq.Expressions;
+using System;
+
+namespace Blue
+{
+    /// <summary>
+    /// Architecture注入类
+    /// 主要负责四层 Controller、Model、Service、Utility的分别注入
+    /// </summary>
+    public class ArchitectureInjecter:IInjector
+    {
+        private IArchitectureComponentInjector controllerInjector;
+        private IArchitectureComponentInjector serviceInjector;
+        private IArchitectureComponentInjector modelInjector;
+        private IArchitectureComponentInjector utilityInjector;
+
+        /// <summary>
+        /// ArchitectureInjecter初始化
+        /// 主要初始化四层 Controller、Model、Service、Utility的注入
+        /// </summary>
+        public ArchitectureInjecter()
+        {
+            controllerInjector = new ControllerInjector();
+            serviceInjector = new ServiceInjector();
+            modelInjector = new ModelInjector();
+            utilityInjector = new UtilityInjector();
+        }
+
+        public void PrepairInjectionData(Type processtype)
+        {
+            PrepairInjectionDataImpl(processtype);
+        }
+
+        /// <summary>
+        /// 根据传入的类型注入到指定的层注入
+        /// </summary>
+        /// <param name="baseType">传入的类型</param>
+        private void PrepairInjectionDataImpl(Type baseType)
+        {
+            if (!TypeChecker.Instance.IsCanInject(baseType))
+            {
+                return;
+            }
+
+            if (TypeChecker.Instance.IsController(baseType))
+            {
+                PrepairControllerInjectionData(baseType);
+            }
+            if (TypeChecker.Instance.IsService(baseType))
+            {
+                PrepairServiceInjectionData(baseType);
+            }
+            if (TypeChecker.Instance.IsModel(baseType))
+            {
+                PrepairModelInjectionData(baseType);
+            }
+            if (TypeChecker.Instance.IsUtility(baseType))
+            {
+                PrepairUtilityInjectionData(baseType);
+            }
+        }
+
+        /// <summary>
+        /// 设置 Architecture
+        /// Controller、Model、Service、Utility注入分别设置architecture
+        /// </summary>
+        public void Inject(IArchitecture architecture)
+        {
+            InjectImpl(architecture);
+        }
+
+        /// <summary>
+        /// 执行与释放或重置非托管资源相关的应用程序定义的任务
+        /// </summary>
+        public void Dispose()
+        {
+            controllerInjector.Dispose();
+            serviceInjector.Dispose();
+            modelInjector.Dispose();
+            utilityInjector.Dispose();
+            controllerInjector = null;
+            serviceInjector = null;
+            modelInjector = null;
+            utilityInjector = null;
+        }
+
+        /// <summary>
+        /// Controller、Model、Service、Utility注入设置architecture
+        /// </summary>
+        /// <param name="architecture"></param>
+        private void InjectImpl(IArchitecture architecture)
+        {
+            controllerInjector.Inject(architecture);
+            serviceInjector.Inject(architecture);
+            modelInjector.Inject(architecture);
+            utilityInjector.Inject(architecture);
+        }
+
+        /// <summary>
+        /// 预注入Controller数据
+        /// </summary>
+        private void PrepairControllerInjectionData(Type baseType)
+        {
+            controllerInjector.PrepairInjectionData(baseType);
+        }
+
+        /// <summary>
+        /// 预注入Model数据
+        /// </summary>
+        private void PrepairModelInjectionData(Type baseType)
+        {
+            modelInjector.PrepairInjectionData(baseType);
+        }
+
+        /// <summary>
+        /// 预注入Service数据
+        /// </summary>
+        private void PrepairServiceInjectionData(Type baseType)
+        {
+            serviceInjector.PrepairInjectionData(baseType);
+        }
+
+        /// <summary>
+        /// 预注入Utility数据
+        /// </summary>
+        private void PrepairUtilityInjectionData(Type baseType)
+        {
+            utilityInjector.PrepairInjectionData(baseType);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ArchitectureInjecter.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7e47abc65d2742c4ea267497fb2cff32
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 36 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/AutoInjectAttribute.cs

@@ -0,0 +1,36 @@
+using System;
+
+namespace Blue
+{
+    /// <summary>
+    /// 自动注入---可以对字段应用属性
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Field)]
+    public class AutoInjectAttribute : Attribute
+    {
+        private Type type;
+        private InjectScope scope;
+        public AutoInjectAttribute()
+        {
+            scope = InjectScope.Singleton;
+        }
+        public AutoInjectAttribute(Type injectType):base()
+        {
+            type = injectType;
+        }
+        public AutoInjectAttribute(Type injectType, InjectScope injectScope)
+        {
+            type = injectType;
+            scope = injectScope;
+        }
+        public Type GetInjectType()
+        {
+            return type;
+        }
+        public InjectScope GetInjectScope()
+        {
+            return scope;
+        }
+
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/AutoInjectAttribute.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 622e02399eec8d14ead869f91635ffab
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 54 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ControllerInjector.cs

@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+namespace Blue
+{
+
+    public class ControllerInjector : AbstractArchitectureComponentInjector
+    {
+        public ControllerInjector():base(typeof(IController))
+        {
+        }
+        private  object[] GetInjectObjects(Type baseType)
+        {
+            return GameObject.FindObjectsOfType(baseType, true);
+        }
+        public override void Inject(IArchitecture architecture)
+        {
+            SetArchitecture(architecture);
+            Dictionary<Type, List<InjectInfo>> injectionMap = GetInjectionMap();
+            if (injectionMap == null)
+            {
+                return;
+            }
+            int injectionCount = injectionMap.Count;
+            var types = injectionMap.Keys;
+            if (injectionCount > 0)
+            {
+                foreach (Type baseType in types)
+                {
+                    object[] injectObjects = GetInjectObjects(baseType);
+                    List<InjectInfo> typeInjectInfoList = injectionMap[baseType];
+                    foreach (InjectInfo injectInfo in typeInjectInfoList)
+                    {
+                        if (injectInfo.InjectScope == InjectScope.Prototype)
+                        {
+                            for (int i = 0; i < injectObjects.Length; i++)
+                            {
+                                InjectPrototype(injectObjects[i], injectInfo.InjectField, injectInfo.InjectType);
+                            }
+                        }
+                        else
+                        {
+                            object injectInstance = GetInjectInstance(injectInfo.InjectType);
+                            for (int i = 0; i < injectObjects.Length; i++)
+                            {
+                                InjectSingleton(injectObjects[i], injectInfo.InjectField, injectInstance);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ControllerInjector.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 144a0729d028e0e44a5c3f8f3e6518df
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 19 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/IArchitectureComponentInjector.cs

@@ -0,0 +1,19 @@
+using System;
+namespace Blue
+{
+    /// <summary>
+    /// 实现Architecture组件注入的接口
+    /// </summary>
+    public interface IArchitectureComponentInjector:IDisposable
+    {
+        /// <summary>
+        /// 根据类型预注入数据
+        /// </summary>
+        void PrepairInjectionData(Type baseType);
+
+        /// <summary>
+        /// architecture注入
+        /// </summary>
+        void Inject(IArchitecture architecture);
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/IArchitectureComponentInjector.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 105d465be23a30444bf454786de1b4b1
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 19 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/IInjector.cs

@@ -0,0 +1,19 @@
+using System;
+namespace Blue
+{
+    /// <summary>
+    /// 实现注入功能的接口
+    /// </summary>
+    public interface IInjector:IDisposable
+    {
+        /// <summary>
+        /// 根据类型预注入数据
+        /// </summary>
+        void PrepairInjectionData(Type processType);
+
+        /// <summary>
+        /// architectureInstance注入
+        /// </summary>
+        void Inject(IArchitecture architectureInstance);
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/IInjector.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: aa04e3a22ee33394aad98f1fc928cdc9
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 65 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/IOCContainer.cs

@@ -0,0 +1,65 @@
+using System.Collections.Generic;
+using System;
+
+namespace Blue
+{
+    /// <summary>
+    /// IOC容器---根据类型存储Object
+    /// </summary>
+    public class IOCContainer
+    {
+        private Dictionary<Type, object> container = new Dictionary<Type, object>();
+
+        /// <summary>
+        /// 将实例注入IOC容器
+        /// </summary>
+        public void Register<T>() where T:new()
+        {
+            Register(new T());
+        }
+
+        /// <summary>
+        /// 将实例注入IOC容器
+        /// </summary>
+        public void Register<T>(T instance)
+        {
+            Type t = typeof(T);
+            if (container.ContainsKey(t))
+            {
+                container[t] = instance;
+            }
+            else
+            {
+                container.Add(t,instance);
+            }
+        }
+
+        /// <summary>
+        /// 根据类型从IOC容器获取对象
+        /// </summary>
+        public object Get(Type type)
+        {
+            if (container.TryGetValue(type,out object instance))
+            {
+                return instance;
+            }
+            return default;
+        }
+
+        /// <summary>
+        /// 从IOC容器获取指定的实例
+        /// </summary>
+        public T Get<T>()
+        {
+            Type t = typeof(T);
+            if (container.TryGetValue(t, out object instance))
+            {
+                return (T)instance;
+            }
+            else
+            {
+                throw new Exception("Can Not Find Instance of type "+t.FullName+",Please Call Register At First!");
+            }
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/IOCContainer.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 2ebda3f9caf5b6c4d8643c4ca72881a7
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 13 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectInfo.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Reflection;
+
+namespace Blue
+{
+    public class InjectInfo
+    {
+        public Type BaseType { get; set; }
+        public FieldInfo InjectField { get; set; }
+        public Type InjectType { get; set; }
+        public InjectScope InjectScope { get; set; }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectInfo.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8eb598d89bd29854f9a9fe845b908385
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 40 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectRuleAttribute.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Blue
+{
+    /// <summary>
+    /// 注入规则属性---可以对接口应用属性
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Interface)]
+    public class InjectRuleAttribute : Attribute
+    {
+        private List<Type> canInjectList;
+        private Type baseInjectType;
+        public InjectRuleAttribute(params Type[] canInject)
+        {
+            baseInjectType = typeof(ICanInject);
+            canInjectList = new List<Type>(canInject.Length);
+            foreach (var item in canInject)
+            {
+                if (item.GetInterfaces().Contains(baseInjectType))
+                {
+                    canInjectList.Add(item);
+                }
+            }
+        }
+        public List<Type> GetCanInjectList()
+        {
+            return canInjectList;
+        }
+        public bool IfCanInject(Type canInject)
+        {
+            if (canInjectList.Contains(canInject))
+            {
+                return true;
+            }
+            return false;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectRuleAttribute.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 2ad7db74bb765af499b9cd9dc185e2f1
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectScope.cs

@@ -0,0 +1,11 @@
+namespace Blue
+{
+    /// <summary>
+    /// 注入范围
+    /// </summary>
+    public enum InjectScope
+    {
+        Singleton,
+        Prototype
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/InjectScope.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b71e99f9b37a39949ac4e3aa4a5e98a8
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 43 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ModelInjector.cs

@@ -0,0 +1,43 @@
+using System;
+
+namespace Blue
+{
+    /// <summary>
+    /// Model 层注入
+    /// </summary>
+    public class ModelInjector : AbstractArchitectureComponentInjector
+    {
+        private Type modelType;
+
+        /// <summary>
+        /// 获取 IModel 的类型
+        /// </summary>
+        public ModelInjector() : base(typeof(IModel)) {
+            modelType = typeof(IModel);
+        }
+
+        /// <summary>
+        /// 根据类型获取注入的Object
+        /// </summary>
+        protected override object GetInjectObject(Type baseType)
+        {
+            object instance = architectureInstance.GetModel(baseType);
+            if (instance == null)
+            {
+                var interfaces = baseType.GetInterfaces(); // 当在派生类中重写时,获取由当前 Type 实现或继承的所有接口
+                foreach (var type in interfaces)
+                {
+                    if (modelType.IsAssignableFrom(type)&&!modelType.Equals(type)) // 确定指定类型 type 的实例是否能分配给当前类型的变量
+                    {
+                        instance = architectureInstance.GetModel(type);
+                        if (instance != null)
+                        {
+                            break;
+                        }
+                    }
+                }
+            }
+            return instance;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ModelInjector.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7d35a136b3463e947a131ae517850345
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 43 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ServiceInjector.cs

@@ -0,0 +1,43 @@
+using System;
+namespace Blue
+{
+    /// <summary>
+    /// Service 层注入
+    /// </summary>
+    public class ServiceInjector : AbstractArchitectureComponentInjector
+    {
+        private Type serviceType;
+
+        /// <summary>
+        /// 获取 IService 的类型
+        /// </summary>
+        public ServiceInjector():base(typeof(IService)) {
+            serviceType = typeof(IService);
+        }
+
+        /// <summary>
+        /// 根据类型获取注入的Object
+        /// </summary>
+        protected override object GetInjectObject(Type baseType)
+        {
+            object instance= architectureInstance.GetService(baseType);
+            if (instance == null)
+            {
+                var interfaces = baseType.GetInterfaces();
+
+                foreach (var type in interfaces)
+                {
+                    if (serviceType.IsAssignableFrom(type)&&!serviceType.Equals(type))
+                    {
+                        instance = architectureInstance.GetService(type);
+                        if (instance != null)
+                        {
+                            break;
+                        }
+                    }
+                }
+            }
+            return instance;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/ServiceInjector.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 83a1500b493c1e34daae8bc88af224a5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 79 - 0
Assets/Scripts/Blue/0.FrameworkDesign/IOC/TypeChecker.cs

@@ -0,0 +1,79 @@
+using System;
+using UnityEngine.Scripting;
+
+namespace Blue
+{
+    /// <summary>
+    /// 类型检查 --- Preserve属性
+    /// 防止字节码剥离移除类、方法、字段或属性
+    /// </summary>
+    [Preserve]
+    public class TypeChecker:Singleton<TypeChecker>
+    {
+        private Type canInjectBaseType;
+        private Type controllerType;
+        private Type modelType;
+        private Type serviceType;
+        private Type utilityType;
+       // [RequiredMember]
+        private TypeChecker()
+        {
+            canInjectBaseType = typeof(ICanInject);
+            controllerType = typeof(IController);
+            modelType = typeof(IModel);
+            serviceType = typeof(IService);
+            utilityType = typeof(IUtility);
+        }
+
+        /// <summary>
+        /// 传入的类型是否来自ICanInject类型
+        /// </summary>
+        /// <param name="type">传入的类型</param>
+        public bool IsCanInject(Type type)
+        {
+            /*
+            TypeA.IsAssignableFrom
+            如果TypeA和TypeB类型一样则返回true
+            如果TypeA是TypeB的父类则返回true;
+            如果TypeB实现了接口TypeA则返回true;
+            */
+            return canInjectBaseType.IsAssignableFrom(type); // 确定指定类型 type 的实例是否能分配给当前类型的变量
+        }
+
+        /// <summary>
+        /// 传入的类型是否来自IController类型
+        /// </summary>
+        /// <param name="type">传入的类型</param>
+        public bool IsController(Type type)
+        {
+            return controllerType.IsAssignableFrom(type);
+        }
+
+        /// <summary>
+        /// 传入的类型是否来自IModel类型
+        /// </summary>
+        /// <param name="type">传入的类型</param>
+        public bool IsModel(Type type)
+        {
+            return modelType.IsAssignableFrom(type);
+        }
+
+        /// <summary>
+        /// 传入的类型是否来自IService类型
+        /// </summary>
+        /// <param name="type">传入的类型</param>
+        public bool IsService(Type type)
+        {
+            return serviceType.IsAssignableFrom(type);
+        }
+
+        /// <summary>
+        /// 传入的类型是否来自IUtility类型
+        /// </summary>
+        /// <param name="type">传入的类型</param>
+        public bool IsUtility(Type type)
+        {
+            return utilityType.IsAssignableFrom(type);
+        }
+    }
+}

Some files were not shown because too many files changed in this diff