Ver código fonte

尽量将代码移动到Controller中,因为controller可以reload

tanghai 11 anos atrás
pai
commit
f2813f94d7

+ 10 - 0
CSharp/Game/Controller/ConfigCategory/BuffCategory.cs

@@ -0,0 +1,10 @@
+using Common.Config;
+using Model;
+
+namespace Controller
+{
+    [Config]
+    public class BuffCategory : ACategory<BuffConfig>
+    {
+    }
+}

+ 10 - 0
CSharp/Game/Controller/ConfigCategory/GlobalCategory.cs

@@ -0,0 +1,10 @@
+using Common.Config;
+using Model;
+
+namespace Controller
+{
+    [Config]
+    public class GlobalCategory : ACategory<GlobalConfig>
+    {
+    }
+}

+ 10 - 0
CSharp/Game/Controller/ConfigCategory/NodeCategory.cs

@@ -0,0 +1,10 @@
+using Common.Config;
+using Model;
+
+namespace Controller
+{
+    [Config]
+    public class NodeCategory : ACategory<NodeConfig>
+    {
+    }
+}

+ 10 - 0
CSharp/Game/Controller/ConfigCategory/UnitCategory.cs

@@ -0,0 +1,10 @@
+using Common.Config;
+using Model;
+
+namespace Controller
+{
+    [Config]
+    public class UnitCategory : ACategory<UnitConfig>
+    {
+    }
+}

+ 5 - 1
CSharp/Game/Controller/Controller.csproj

@@ -49,8 +49,12 @@
     <Compile Include="BehaviorTreeNode\Selector.cs" />
     <Compile Include="BehaviorTreeNode\Sequence.cs" />
     <Compile Include="BuffController.cs" />
+    <Compile Include="ConfigCategory\BuffCategory.cs" />
+    <Compile Include="ConfigCategory\GlobalCategory.cs" />
+    <Compile Include="ConfigCategory\NodeCategory.cs" />
+    <Compile Include="ConfigCategory\UnitCategory.cs" />
     <Compile Include="NodeType.cs" />
-    <Compile Include="Factories\UnitFactory.cs" />
+    <Compile Include="Factory\UnitFactory.cs" />
     <Compile Include="UnitType.cs" />
   </ItemGroup>
   <ItemGroup>

+ 0 - 0
CSharp/Game/Controller/Factories/UnitFactory.cs → CSharp/Game/Controller/Factory/UnitFactory.cs


+ 1 - 6
CSharp/Game/Model/Config/BuffConfig.cs

@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+ using System.Collections.Generic;
 using Common.Config;
 
 namespace Model
@@ -16,9 +16,4 @@ namespace Model
             this.Effects = new List<int>();
         }
     }
-
-    [Config]
-    public class BuffCategory : ACategory<BuffConfig>
-    {
-    }
 }

+ 0 - 5
CSharp/Game/Model/Config/GlobalConfig.cs

@@ -6,9 +6,4 @@ namespace Model
     {
         public int Type { get; set; }
     }
-
-    [Config]
-    public class GlobalCategory: ACategory<GlobalConfig>
-    {
-    }
 }

+ 0 - 5
CSharp/Game/Model/Config/NodeConfig.cs

@@ -8,9 +8,4 @@ namespace Model
         public List<string> Args { get; set; }
         public List<NodeConfig> SubConfigs { get; set; }
     }
-
-    [Config]
-    public class NodeCategory: ACategory<NodeConfig>
-    {
-    }
 }

+ 0 - 5
CSharp/Game/Model/Config/UnitConfig.cs

@@ -6,9 +6,4 @@ namespace Model
     {
         public int Type { get; set; }
     }
-
-    [Config]
-    public class UnitCategory : ACategory<UnitConfig>
-    {
-    }
 }

+ 5 - 9
CSharp/Game/MongoDBTest/MongoDBTest.cs

@@ -23,23 +23,19 @@ namespace MongoDBTest
 
 
             World world = World.Instance;
+            Assembly assembly = Assembly.Load(File.ReadAllBytes(@"./Controller.dll"));
 
             // 加载配置
-            ConfigComponent configComponent = world.AddComponent<ConfigComponent>();
-            configComponent.Load(typeof(World).Assembly);
-
-            Assembly assembly = Assembly.Load(File.ReadAllBytes(@"./Controller.dll"));
+            world.AddComponent<ConfigComponent>().Load(assembly);
 
             // 构造工厂
-            FactoryComponent<Unit> factoryComponent = world.AddComponent<FactoryComponent<Unit>>();
-            factoryComponent.Load(assembly);
+            world.AddComponent<FactoryComponent<Unit>>().Load(assembly);
 
             // 构造行为树
-            BehaviorTreeComponent behaviorTreeComponent = world.AddComponent<BehaviorTreeComponent>();
-            behaviorTreeComponent.Load(assembly);
+            world.AddComponent<BehaviorTreeComponent>().Load(assembly);
 
 
-            Unit player1 = factoryComponent.Create(1);
+            Unit player1 = world.GetComponent<FactoryComponent<Unit>>().Create(1);
             Buff buff = new Buff(1);
             player1.GetComponent<BuffComponent>().Add(buff);
             player1["hp"] = 10;

+ 3 - 1
CSharp/Platform/Common/Config/ACategory.cs

@@ -8,10 +8,12 @@ namespace Common.Config
 {
     public abstract class ACategory<T>: ICategory where T : AConfig
     {
-        protected readonly Dictionary<int, T> dict = new Dictionary<int, T>();
+        protected Dictionary<int, T> dict;
 
         public virtual void BeginInit()
         {
+            dict = new Dictionary<int, T>();
+
             string path = Path.Combine(@"../../Config/", typeof(T).Name);
 
             if (!Directory.Exists(path))