Sfoglia il codice sorgente

1.配置类放到Common里
2.数据和控制逻辑分离,数据放到Model里,控制逻辑放到Control里,Control以后可以Reload

tanghai 11 anni fa
parent
commit
95a8e65a5a

+ 30 - 15
CSharp/CSharp.sln

@@ -34,8 +34,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorTree", "Game\Behavi
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "World", "Game\World\World.csproj", "{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Component", "Game\Component\Component.csproj", "{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tree", "App\Modules\Tree\Tree.csproj", "{6CD185D1-08E0-4729-A999-2D5B57BA8193}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetExe", "Platform\ENetExe\ENetExe.csproj", "{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}"
@@ -48,6 +46,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TNetTest", "Platform\TNetTe
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Platform\Common\Common.csproj", "{19F8F043-1F99-4550-99DF-DEA5C7D77E55}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Game\Model\Model.csproj", "{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controller", "Game\Controller\Controller.csproj", "{E69C1F22-E004-4D69-8667-787BD243454B}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -148,18 +150,6 @@ Global
 		{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Win32.ActiveCfg = Release|Any CPU
 		{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|x86.ActiveCfg = Release|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Win32.ActiveCfg = Debug|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Any CPU.Build.0 = Release|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Win32.ActiveCfg = Release|Any CPU
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|x86.ActiveCfg = Release|Any CPU
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -220,6 +210,30 @@ Global
 		{19F8F043-1F99-4550-99DF-DEA5C7D77E55}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{19F8F043-1F99-4550-99DF-DEA5C7D77E55}.Release|Win32.ActiveCfg = Release|Any CPU
 		{19F8F043-1F99-4550-99DF-DEA5C7D77E55}.Release|x86.ActiveCfg = Release|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|Win32.ActiveCfg = Debug|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|Win32.ActiveCfg = Release|Any CPU
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}.Release|x86.ActiveCfg = Release|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Debug|Win32.ActiveCfg = Debug|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Release|Win32.ActiveCfg = Release|Any CPU
+		{E69C1F22-E004-4D69-8667-787BD243454B}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -233,11 +247,12 @@ Global
 		{901A8E5C-C4C6-4C3C-8E18-068D75119F5D} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{C4E7A34A-095C-4983-AB63-FC2D20CD6824} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
 		{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
-		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{B42D431A-3A54-4649-942A-C5356D7F9FBC} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{F176D1FA-63E5-4B89-9A03-D44CCCCC069A} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{19F8F043-1F99-4550-99DF-DEA5C7D77E55} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
+		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
+		{E69C1F22-E004-4D69-8667-787BD243454B} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
 	EndGlobalSection
 EndGlobal

+ 0 - 4
CSharp/Game/BehaviorTree/BehaviorTree.csproj

@@ -61,10 +61,6 @@
       <Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
       <Name>Common</Name>
     </ProjectReference>
-    <ProjectReference Include="..\Component\Component.csproj">
-      <Project>{0fa529d1-d0a9-4a8e-90f5-117ce80f2ede}</Project>
-      <Name>Component</Name>
-    </ProjectReference>
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />

+ 0 - 15
CSharp/Game/Component/ConfigAttribute.cs

@@ -1,15 +0,0 @@
-using System;
-
-namespace Component
-{
-    [AttributeUsage(AttributeTargets.Class)]
-    public class ConfigAttribute: Attribute
-    {
-        public string RelativeDirectory { get; set; }
-
-        public ConfigAttribute()
-        {
-            this.RelativeDirectory = @"..\Config";
-        }
-    }
-}

+ 0 - 96
CSharp/Game/Component/ConfigManager.cs

@@ -1,96 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.IO;
-
-namespace Component
-{
-    public class ConfigManager
-    {
-        private static readonly ConfigManager instance = new ConfigManager();
-
-        public static ConfigManager Instance
-        {
-            get
-            {
-                return instance;
-            }
-        }
-
-        public Dictionary<string, object> allConfig;
-
-        private ConfigManager()
-        {
-            this.Load();
-        }
-
-        private void Load()
-        {
-            var localAllConfig = new Dictionary<string, object>();
-            string currentDir = AppDomain.CurrentDomain.BaseDirectory;
-            Type[] types = typeof (ConfigManager).Assembly.GetTypes();
-            foreach (var type in types)
-            {
-                object[] attrs = type.GetCustomAttributes(typeof (ConfigAttribute), false);
-                if (attrs.Length == 0)
-                {
-                    continue;
-                }
-
-                object obj = (Activator.CreateInstance(type));
-
-                var iInit = obj as IConfigInitialize;
-                if (iInit == null)
-                {
-                    throw new Exception(string.Format("class {0} is not IConfigInitialize",
-                            type.Name));
-                }
-
-                var iSupportInitialize = obj as ISupportInitialize;
-                if (iSupportInitialize != null)
-                {
-                    iSupportInitialize.BeginInit();
-                }
-
-                string configDir = Path.Combine(currentDir,
-                        ((ConfigAttribute) attrs[0]).RelativeDirectory);
-
-                if (!Directory.Exists(configDir))
-                {
-                    throw new Exception(string.Format("not found config dir: {0}", configDir));
-                }
-                iInit.Init(configDir);
-
-                if (iSupportInitialize != null)
-                {
-                    iSupportInitialize.EndInit();
-                }
-
-                localAllConfig[iInit.ConfigName] = obj;
-            }
-            this.allConfig = localAllConfig;
-        }
-
-        public void Reload()
-        {
-            this.Load();
-        }
-
-        public T Get<T>(int type) where T : IType
-        {
-            var configManager = (ConfigCategory<T>) this.allConfig[typeof (T).Name];
-            return configManager[type];
-        }
-
-        public Dictionary<int, T> GetAll<T>() where T : IType
-        {
-            var configManager = (ConfigCategory<T>) this.allConfig[typeof (T).Name];
-            return configManager.GetAll();
-        }
-
-        public ConfigCategory<T> GetConfigManager<T>() where T : IType
-        {
-            return (ConfigCategory<T>) this.allConfig[typeof (T).Name];
-        }
-    }
-}

+ 0 - 8
CSharp/Game/Component/IConfigInitialize.cs

@@ -1,8 +0,0 @@
-namespace Component
-{
-    public interface IConfigInitialize
-    {
-        string ConfigName { get; }
-        void Init(string dir);
-    }
-}

+ 0 - 7
CSharp/Game/Component/KeyDefine.cs

@@ -1,7 +0,0 @@
-namespace Component
-{
-    public static class KeyDefine
-    {
-        public const string KMessage = "message";
-    }
-}

+ 15 - 0
CSharp/Game/Controller/BuffController.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Controller
+{
+    /// <summary>
+    /// 控制复杂的buff逻辑,可以reload
+    /// </summary>
+    public class BuffController
+    {
+    }
+}

+ 53 - 0
CSharp/Game/Controller/Controller.csproj

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{E69C1F22-E004-4D69-8667-787BD243454B}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Controller</RootNamespace>
+    <AssemblyName>Controller</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\Bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\Bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="BuffController.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 36 - 0
CSharp/Game/Controller/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过以下
+// 特性集控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Controller")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Controller")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("2857e4a1-f2c1-4c17-8b67-6d25f98265ed")]
+
+// 程序集的版本信息由下面四个值组成: 
+//
+//      主版本
+//      次版本 
+//      生成号
+//      修订号
+//
+// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”: 
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 1 - 1
CSharp/Game/Component/Buff.cs → CSharp/Game/Model/Buff.cs

@@ -1,6 +1,6 @@
 using Common.Component;
 
-namespace Component
+namespace Model
 {
     public class Buff: Object
     {

+ 1 - 1
CSharp/Game/Component/BuffManager.cs → CSharp/Game/Model/BuffManager.cs

@@ -3,7 +3,7 @@ using System.ComponentModel;
 using MongoDB.Bson;
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Component
+namespace Model
 {
     public class BuffManager: ISupportInitialize
     {

+ 1 - 1
CSharp/Game/Component/Character.cs → CSharp/Game/Model/Character.cs

@@ -1,4 +1,4 @@
-namespace Component
+namespace Model
 {
     /// <summary>
     /// 角色对象

+ 1 - 1
CSharp/Game/Component/GameObject.cs → CSharp/Game/Model/GameObject.cs

@@ -1,6 +1,6 @@
 using Common.Component;
 
-namespace Component
+namespace Model
 {
     public class GameObject: Object
     {

+ 1 - 1
CSharp/Game/Component/GameObjectManager.cs → CSharp/Game/Model/GameObjectManager.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using MongoDB.Bson;
 
-namespace Component
+namespace Model
 {
     public class GameObjectManager
     {

+ 0 - 6
CSharp/Game/Component/Component.csproj → CSharp/Game/Model/Model.csproj

@@ -49,13 +49,7 @@
     <Compile Include="BuffManager.cs" />
     <Compile Include="Character.cs" />
     <Compile Include="GameObject.cs" />
-    <Compile Include="ConfigAttribute.cs" />
-    <Compile Include="ConfigCategory.cs" />
-    <Compile Include="ConfigManager.cs" />
     <Compile Include="GameObjectManager.cs" />
-    <Compile Include="IConfigInitialize.cs" />
-    <Compile Include="IType.cs" />
-    <Compile Include="KeyDefine.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Properties\" />

+ 0 - 0
CSharp/Game/Component/packages.config → CSharp/Game/Model/packages.config


+ 1 - 1
CSharp/Game/World/Config/GlobalConfig.cs

@@ -1,4 +1,4 @@
-namespace Component.Config
+namespace Model.Config
 {
     public class GlobalConfig: IType
     {

+ 7 - 3
CSharp/Game/World/World.cs

@@ -1,12 +1,12 @@
-using Component;
+using Model;
 
 namespace World
 {
     public class World
     {
         private static readonly World instance = new World();
-        
-        private readonly ConfigManager configManager = ConfigManager.Instance;
+
+        private readonly ConfigManager configManager = new ConfigManager(typeof(World).Assembly);
 
         private readonly GameObjectManager gameObjectManager = new GameObjectManager();
 
@@ -18,6 +18,10 @@ namespace World
             }
         }
 
+        private World()
+        {
+        }
+
         public ConfigManager ConfigManager
         {
             get

+ 2 - 2
CSharp/Game/World/World.csproj

@@ -46,9 +46,9 @@
       <Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
       <Name>Common</Name>
     </ProjectReference>
-    <ProjectReference Include="..\Component\Component.csproj">
+    <ProjectReference Include="..\Model\Model.csproj">
       <Project>{0fa529d1-d0a9-4a8e-90f5-117ce80f2ede}</Project>
-      <Name>Component</Name>
+      <Name>Model</Name>
     </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 4 - 0
CSharp/Platform/Common/Common.csproj

@@ -63,6 +63,10 @@
     <Compile Include="Component\IEventAttribute.cs" />
     <Compile Include="Component\IEvent.cs" />
     <Compile Include="Component\Object.cs" />
+    <Compile Include="Config\ConfigAttribute.cs" />
+    <Compile Include="Config\ConfigCategory.cs" />
+    <Compile Include="Config\ConfigManager.cs" />
+    <Compile Include="Config\IType.cs" />
     <Compile Include="Helper\BigIntegerHelper.cs" />
     <Compile Include="Helper\ByteHelper.cs" />
     <Compile Include="Helper\EnumHelper.cs" />

+ 9 - 0
CSharp/Platform/Common/Config/ConfigAttribute.cs

@@ -0,0 +1,9 @@
+using System;
+
+namespace Model
+{
+    [AttributeUsage(AttributeTargets.Class)]
+    public class ConfigAttribute: Attribute
+    {
+    }
+}

+ 18 - 18
CSharp/Game/Component/ConfigCategory.cs → CSharp/Platform/Common/Config/ConfigCategory.cs

@@ -4,12 +4,28 @@ using System.ComponentModel;
 using System.IO;
 using Common.Helper;
 
-namespace Component
+namespace Model
 {
-    public abstract class ConfigCategory<T>: ISupportInitialize, IConfigInitialize where T : IType
+    public abstract class ConfigCategory<T>: ISupportInitialize where T : IType
     {
         protected readonly Dictionary<int, T> dict = new Dictionary<int, T>();
 
+        protected ConfigCategory()
+        {
+            string path = Path.Combine(@"./Config/", this.ConfigName);
+
+            if (!Directory.Exists(path))
+            {
+                throw new Exception(string.Format("not found config path: {0}", path));
+            }
+
+            foreach (var file in Directory.GetFiles(path))
+            {
+                var t = MongoHelper.FromJson<T>(File.ReadAllText(file));
+                this.dict.Add(t.Type, t);
+            }
+        }
+
         public T this[int type]
         {
             get
@@ -31,22 +47,6 @@ namespace Component
             return this.dict;
         }
 
-        public void Init(string configsDir)
-        {
-            string path = Path.Combine(configsDir, this.ConfigName);
-
-            if (!Directory.Exists(path))
-            {
-                throw new Exception(string.Format("not found config path: {0}", path));
-            }
-
-            foreach (var file in Directory.GetFiles(path))
-            {
-                var t = MongoHelper.FromJson<T>(File.ReadAllText(file));
-                this.dict.Add(t.Type, t);
-            }
-        }
-
         public void BeginInit()
         {
         }

+ 60 - 0
CSharp/Platform/Common/Config/ConfigManager.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Reflection;
+
+namespace Model
+{
+    public class ConfigManager
+    {
+        public Dictionary<string, object> allConfig;
+
+        public ConfigManager(Assembly assembly)
+        {
+            Load(assembly);
+        }
+
+        public void Load(Assembly assembly)
+        {
+            var localAllConfig = new Dictionary<string, object>();
+            Type[] types = assembly.GetTypes();
+            foreach (var type in types)
+            {
+                object[] attrs = type.GetCustomAttributes(typeof (ConfigAttribute), false);
+                if (attrs.Length == 0)
+                {
+                    continue;
+                }
+                
+                object obj = (Activator.CreateInstance(type));
+
+                var iSupportInitialize = obj as ISupportInitialize;
+
+                if (iSupportInitialize != null)
+                {
+                    iSupportInitialize.EndInit();
+                }
+
+                localAllConfig[type.Name] = obj;
+            }
+            this.allConfig = localAllConfig;
+        }
+
+        public T Get<T>(int type) where T : IType
+        {
+            var configCategory = (ConfigCategory<T>)this.allConfig[typeof(T).Name];
+            return configCategory[type];
+        }
+
+        public Dictionary<int, T> GetAll<T>() where T : IType
+        {
+            var configCategory = (ConfigCategory<T>)this.allConfig[typeof(T).Name];
+            return configCategory.GetAll();
+        }
+
+        public ConfigCategory<T> GetConfigCategory<T>() where T : IType
+        {
+            return (ConfigCategory<T>) this.allConfig[typeof (T).Name];
+        }
+    }
+}

+ 1 - 1
CSharp/Game/Component/IType.cs → CSharp/Platform/Common/Config/IType.cs

@@ -1,4 +1,4 @@
-namespace Component
+namespace Model
 {
     public interface IType
     {