提交 a594cc50 编写于 作者: T tanghai

动态加载Controller Assembly,以后可以方便的Reload

上级 d2208d6c
......@@ -30,8 +30,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetTest", "Platform\ENetTe
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Game", "Game", "{D0CC1FF4-2747-4278-A51F-BE9AA959175B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorTree", "Game\BehaviorTree\BehaviorTree.csproj", "{C4E7A34A-095C-4983-AB63-FC2D20CD6824}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetExe", "Platform\ENetExe\ENetExe.csproj", "{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2814EB55-E1C2-4751-AC14-94116DA9D22B}"
......@@ -50,6 +48,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorTreeModule", "App\M
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDBTest", "Game\MongoDBTest\MongoDBTest.csproj", "{93FB20CF-827A-4CED-A273-90117EB7192F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{AAD111B8-4746-4445-A428-97A72A04FCCD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Login", "Server\Login\Login.csproj", "{2B3EC6BE-0920-4C93-934F-41DC76108818}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -126,18 +128,6 @@ Global
{901A8E5C-C4C6-4C3C-8E18-068D75119F5D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{901A8E5C-C4C6-4C3C-8E18-068D75119F5D}.Release|Win32.ActiveCfg = Release|Any CPU
{901A8E5C-C4C6-4C3C-8E18-068D75119F5D}.Release|x86.ActiveCfg = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Debug|Win32.ActiveCfg = Debug|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Debug|x86.ActiveCfg = Debug|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Any CPU.Build.0 = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Win32.ActiveCfg = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|x86.ActiveCfg = Release|Any CPU
{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
......@@ -234,6 +224,18 @@ Global
{93FB20CF-827A-4CED-A273-90117EB7192F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{93FB20CF-827A-4CED-A273-90117EB7192F}.Release|Win32.ActiveCfg = Release|Any CPU
{93FB20CF-827A-4CED-A273-90117EB7192F}.Release|x86.ActiveCfg = Release|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Debug|Win32.ActiveCfg = Debug|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Debug|x86.ActiveCfg = Debug|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Release|Any CPU.Build.0 = Release|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Release|Win32.ActiveCfg = Release|Any CPU
{2B3EC6BE-0920-4C93-934F-41DC76108818}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -245,7 +247,6 @@ Global
{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
{D0B4CFAC-A368-4742-9863-68776CFA9938} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
{901A8E5C-C4C6-4C3C-8E18-068D75119F5D} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
{C4E7A34A-095C-4983-AB63-FC2D20CD6824} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
{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}
......@@ -254,5 +255,6 @@ Global
{E69C1F22-E004-4D69-8667-787BD243454B} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
{6CD185D1-08E0-4729-A999-2D5B57BA8193} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
{93FB20CF-827A-4CED-A273-90117EB7192F} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
{2B3EC6BE-0920-4C93-934F-41DC76108818} = {AAD111B8-4746-4445-A428-97A72A04FCCD}
EndGlobalSection
EndGlobal
namespace BehaviorTree
{
public enum NodeType
{
Selector = 1,
Sequence = 2,
Not = 10,
}
}
\ No newline at end of file
using Model;
namespace BehaviorTree
namespace Controller
{
[Node(NodeType.Not)]
public class Not: Node
......
using Model;
namespace BehaviorTree
namespace Controller
{
[Node(NodeType.Selector)]
public class Selector: Node
......
using Model;
namespace BehaviorTree
namespace Controller
{
[Node(NodeType.Sequence)]
internal class Sequence: Node
......
......@@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......@@ -31,11 +33,25 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MongoDB.Bson, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="BehaviorTreeNode\Not.cs" />
<Compile Include="BehaviorTreeNode\Selector.cs" />
<Compile Include="BehaviorTreeNode\Sequence.cs" />
<Compile Include="BuffController.cs" />
<Compile Include="NodeType.cs" />
<Compile Include="Factories\UnitFactory.cs" />
<Compile Include="UnitType.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
......@@ -50,7 +66,17 @@
<Name>Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- 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">
......
namespace Model
{
public static class UnitFactory
{
public static Unit Create(int configId)
{
return World.Instance.GetComponent<FactoryComponent<Unit>>().Create(configId);
}
}
using Model;
[FactoryAttribute(typeof (Unit), (int) UnitType.Player)]
namespace Controller
{
[Factory(typeof (Unit), UnitType.Player)]
public class UnitPlayerFactory: IFactory<Unit>
{
public Unit Create(int configId)
......
namespace Controller
{
public static class NodeType
{
public const int Selector = 1;
public const int Sequence = 2;
public const int Not = 10;
}
}
\ No newline at end of file
namespace Controller
{
public static class UnitType
{
public const int Player = 1;
public const int Npc = 2;
public const int Dog = 3;
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="mongocsharpdriver" version="1.9.2" targetFramework="net45" />
<package id="mongocsharpdriver" version="1.9.2" targetFramework="net451" />
</packages>
\ No newline at end of file
namespace BehaviorTree
namespace Model
{
public class BehaviorTree
{
......
using System;
using System.Collections.Generic;
using System.Reflection;
using Model;
namespace BehaviorTree
namespace Model
{
public class BehaviorTreeFactory
{
......@@ -17,17 +16,16 @@ namespace BehaviorTree
}
}
private readonly Dictionary<NodeType, Func<NodeConfig, Node>> dictionary =
new Dictionary<NodeType, Func<NodeConfig, Node>>();
private Dictionary<int, Func<NodeConfig, Node>> dictionary;
private BehaviorTreeFactory()
{
Assembly assembly = typeof(BehaviorTreeFactory).Assembly;
this.RegisterNodes(assembly);
}
public void RegisterNodes(Assembly assembly)
public void Load(Assembly assembly)
{
this.dictionary = new Dictionary<int, Func<NodeConfig, Node>>();
Type[] types = assembly.GetTypes();
foreach (var type in types)
{
......@@ -40,19 +38,18 @@ namespace BehaviorTree
Type classType = type;
this.dictionary.Add(attribute.NodeType,
config =>
(Node)Activator.CreateInstance(classType, new object[] { config }));
config => (Node)Activator.CreateInstance(classType, new object[] { config }));
}
}
private Node CreateNode(NodeConfig config)
{
if (!this.dictionary.ContainsKey((NodeType) config.Id))
if (!this.dictionary.ContainsKey(config.Id))
{
throw new KeyNotFoundException(string.Format("CreateNode cannot found: {0}",
config.Id));
}
return this.dictionary[(NodeType) config.Id](config);
return this.dictionary[config.Id](config);
}
private Node CreateTreeNode(NodeConfig config)
......
using Common.Base;
namespace BehaviorTree
namespace Model
{
public class BlackBoard: Object
{
......
using System.Collections.Generic;
using Model;
namespace BehaviorTree
namespace Model
{
public abstract class Node
{
......
using System;
namespace BehaviorTree
namespace Model
{
[AttributeUsage(AttributeTargets.Class)]
public class NodeAttribute: Attribute
{
public NodeType NodeType { get; private set; }
public int NodeType { get; private set; }
public NodeAttribute(NodeType nodeType)
public NodeAttribute(int nodeType)
{
this.NodeType = nodeType;
}
......
using System.Collections.Generic;
using System.Reflection;
using Common.Base;
namespace Model
{
public class BehaviorTreeComponent: Component<World>
{
private Dictionary<int, BehaviorTree> trees = new Dictionary<int, BehaviorTree>();
public void Load(Assembly assembly)
{
BehaviorTreeFactory behaviorTreeFactory = BehaviorTreeFactory.Instance;
behaviorTreeFactory.Load(assembly);
NodeConfig[] nodeConfigs = World.Instance.GetComponent<ConfigComponent>().GetAll<NodeConfig>();
foreach (NodeConfig nodeConfig in nodeConfigs)
{
BehaviorTree behaviorTree = behaviorTreeFactory.CreateTree(nodeConfig);
this.trees[nodeConfig.Id] = behaviorTree;
}
}
}
}
......@@ -9,17 +9,17 @@ namespace Model
public class BuffComponent: Component<Unit>
{
[BsonElement]
private HashSet<Buff> buffs { get; set; }
private HashSet<Buff> buffs;
private Dictionary<ObjectId, Buff> buffIdDict { get; set; }
private Dictionary<ObjectId, Buff> idBuff;
private MultiMap<BuffType, Buff> buffTypeMMap { get; set; }
private MultiMap<BuffType, Buff> typeBuff;
public BuffComponent()
{
this.buffs = new HashSet<Buff>();
this.buffIdDict = new Dictionary<ObjectId, Buff>();
this.buffTypeMMap = new MultiMap<BuffType, Buff>();
this.idBuff = new Dictionary<ObjectId, Buff>();
this.typeBuff = new MultiMap<BuffType, Buff>();
}
public override void BeginInit()
......@@ -27,8 +27,8 @@ namespace Model
base.BeginInit();
this.buffs = new HashSet<Buff>();
this.buffIdDict = new Dictionary<ObjectId, Buff>();
this.buffTypeMMap = new MultiMap<BuffType, Buff>();
this.idBuff = new Dictionary<ObjectId, Buff>();
this.typeBuff = new MultiMap<BuffType, Buff>();
}
public override void EndInit()
......@@ -37,8 +37,8 @@ namespace Model
foreach (var buff in this.buffs)
{
this.buffIdDict.Add(buff.Id, buff);
this.buffTypeMMap.Add(buff.Config.Type, buff);
this.idBuff.Add(buff.Id, buff);
this.typeBuff.Add(buff.Config.Type, buff);
}
}
......@@ -49,34 +49,34 @@ namespace Model
throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id));
}
if (this.buffIdDict.ContainsKey(buff.Id))
if (this.idBuff.ContainsKey(buff.Id))
{
throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id));
}
this.buffs.Add(buff);
this.buffIdDict.Add(buff.Id, buff);
this.buffTypeMMap.Add(buff.Config.Type, buff);
this.idBuff.Add(buff.Id, buff);
this.typeBuff.Add(buff.Config.Type, buff);
}
public Buff GetById(ObjectId id)
{
if (!this.buffIdDict.ContainsKey(id))
if (!this.idBuff.ContainsKey(id))
{
return null;
}
return this.buffIdDict[id];
return this.idBuff[id];
}
public Buff GetOneByType(BuffType type)
{
return this.buffTypeMMap.GetOne(type);
return this.typeBuff.GetOne(type);
}
public Buff[] GetByType(BuffType type)
{
return this.buffTypeMMap.GetByKey(type);
return this.typeBuff.GetByKey(type);
}
private bool Remove(Buff buff)
......@@ -87,8 +87,8 @@ namespace Model
}
this.buffs.Remove(buff);
this.buffIdDict.Remove(buff.Id);
this.buffTypeMMap.Remove(buff.Config.Type, buff);
this.idBuff.Remove(buff.Id);
this.typeBuff.Remove(buff.Config.Type, buff);
return true;
}
......
......@@ -10,42 +10,31 @@ namespace Model
{
public Dictionary<Type, ICategory> allConfig;
private Assembly[] assemblies;
public void Load(Assembly[] ass)
public void Load(Assembly assembly)
{
allConfig = new Dictionary<Type, ICategory>();
this.assemblies = ass;
foreach (Assembly assembly in assemblies)
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
Type[] types = assembly.GetTypes();
foreach (Type type in types)
object[] attrs = type.GetCustomAttributes(typeof(ConfigAttribute), false);
if (attrs.Length == 0)
{
object[] attrs = type.GetCustomAttributes(typeof(ConfigAttribute), false);
if (attrs.Length == 0)
{
continue;
}
object obj = (Activator.CreateInstance(type));
continue;
}
ICategory iCategory = obj as ICategory;
if (iCategory == null)
{
throw new Exception(
string.Format("class: {0} not inherit from ACategory", type.Name));
}
iCategory.BeginInit();
iCategory.EndInit();
object obj = (Activator.CreateInstance(type));
allConfig[iCategory.ConfigType] = iCategory;
ICategory iCategory = obj as ICategory;
if (iCategory == null)
{
throw new Exception(
string.Format("class: {0} not inherit from ACategory", type.Name));
}
}
}
iCategory.BeginInit();
iCategory.EndInit();
public void Reload()
{
this.Load(this.assemblies);
allConfig[iCategory.ConfigType] = iCategory;
}
}
public T Get<T>(int id) where T : AConfig
......
......@@ -9,37 +9,34 @@ namespace Model
{
private Dictionary<int, IFactory<T>> allConfig;
public void Load(IEnumerable<Assembly> assemblies)
public void Load(Assembly assembly)
{
allConfig = new Dictionary<int, IFactory<T>>();
foreach (Assembly assembly in assemblies)
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
Type[] types = assembly.GetTypes();
foreach (Type type in types)
object[] attrs = type.GetCustomAttributes(typeof(FactoryAttribute), false);
if (attrs.Length == 0)
{
object[] attrs = type.GetCustomAttributes(typeof(FactoryAttribute), false);
if (attrs.Length == 0)
{
continue;
}
FactoryAttribute attribute = (FactoryAttribute)attrs[0];
if (attribute.ClassType != typeof (T))
{
continue;
}
continue;
}
object obj = (Activator.CreateInstance(type));
FactoryAttribute attribute = (FactoryAttribute)attrs[0];
if (attribute.ClassType != typeof (T))
{
continue;
}
IFactory<T> iFactory = obj as IFactory<T>;
if (iFactory == null)
{
throw new Exception(
string.Format("class: {0} not inherit from IFactory", type.Name));
}
object obj = (Activator.CreateInstance(type));
allConfig[attribute.Type] = iFactory;
IFactory<T> iFactory = obj as IFactory<T>;
if (iFactory == null)
{
throw new Exception(
string.Format("class: {0} not inherit from IFactory", type.Name));
}
allConfig[attribute.Type] = iFactory;
}
}
......
......@@ -11,8 +11,8 @@ namespace Model
private readonly Dictionary<ObjectId, Unit> units =
new Dictionary<ObjectId, Unit>();
private readonly Dictionary<UnitType, Dictionary<ObjectId, Unit>> typeUnits =
new Dictionary<UnitType, Dictionary<ObjectId, Unit>>();
private readonly Dictionary<int, Dictionary<ObjectId, Unit>> typeUnits =
new Dictionary<int, Dictionary<ObjectId, Unit>>();
public void Add(Unit unit)
{
......@@ -31,7 +31,7 @@ namespace Model
return unit;
}
public Unit[] GetOneType(UnitType type)
public Unit[] GetOneType(int type)
{
Dictionary<ObjectId, Unit> oneTypeUnits = null;
if (!this.typeUnits.TryGetValue(type, out oneTypeUnits))
......
......@@ -4,7 +4,7 @@ namespace Model
{
public class UnitConfig: AConfig
{
public UnitType Type { get; set; }
public int Type { get; set; }
}
[Config]
......
......@@ -45,19 +45,23 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Component\BehaviorTreeComponent.cs" />
<Compile Include="BehaviorTree\BehaviorTree.cs" />
<Compile Include="BehaviorTree\BehaviorTreeFactory.cs" />
<Compile Include="BehaviorTree\BlackBoard.cs" />
<Compile Include="BehaviorTree\Node.cs" />
<Compile Include="BehaviorTree\NodeAttribute.cs" />
<Compile Include="Buff.cs" />
<Compile Include="BuffComponent.cs" />
<Compile Include="ConfigComponent.cs" />
<Compile Include="Component\BuffComponent.cs" />
<Compile Include="Component\ConfigComponent.cs" />
<Compile Include="Config\UnitConfig.cs" />
<Compile Include="Config\BuffConfig.cs" />
<Compile Include="FactoryAttribute.cs" />
<Compile Include="FactoryComponent.cs" />
<Compile Include="Component\FactoryComponent.cs" />
<Compile Include="IFactory.cs" />
<Compile Include="UnitFactory.cs" />
<Compile Include="UnitType.cs" />
<Compile Include="Component\UnitComponent.cs" />
<Compile Include="BuffType.cs" />
<Compile Include="GameObject.cs" />
<Compile Include="UnitComponent.cs" />
<Compile Include="Config\GlobalConfig.cs" />
<Compile Include="Config\NodeConfig.cs" />
<Compile Include="Unit.cs" />
......
namespace Model
{
public enum UnitType
{
Player = 1,
Npc = 2,
Dog = 3,
}
}
......@@ -14,13 +14,6 @@
private World()
{
this.AddComponent<UnitComponent>();
ConfigComponent configComponent = this.AddComponent<ConfigComponent>();
configComponent.Load(new[] { typeof (World).Assembly });
FactoryComponent<Unit> factoryComponent = this.AddComponent<FactoryComponent<Unit>>();
factoryComponent.Load(new[] { typeof(World).Assembly });
}
}
}
\ No newline at end of file
using System;
using System.IO;
using System.Reflection;
using Common.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Model;
......@@ -19,7 +21,25 @@ namespace MongoDBTest
var database = server.GetDatabase("test");
var collection = database.GetCollection<Unit>("Unit");
Unit player1 = UnitFactory.Create(1);
World world = World.Instance;
// 加载配置
ConfigComponent configComponent = world.AddComponent<ConfigComponent>();
configComponent.Load(typeof(World).Assembly);
Assembly assembly = Assembly.Load(File.ReadAllBytes(@"./Controller.dll"));
// 构造工厂
FactoryComponent<Unit> factoryComponent = world.AddComponent<FactoryComponent<Unit>>();
factoryComponent.Load(assembly);
// 构造行为树
BehaviorTreeComponent behaviorTreeComponent = world.AddComponent<BehaviorTreeComponent>();
behaviorTreeComponent.Load(assembly);
Unit player1 = factoryComponent.Create(1);
Buff buff = new Buff(1);
player1.GetComponent<BuffComponent>().Add(buff);
player1["hp"] = 10;
......
......@@ -4,22 +4,19 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C4E7A34A-095C-4983-AB63-FC2D20CD6824}</ProjectGuid>
<ProjectGuid>{2B3EC6BE-0920-4C93-934F-41DC76108818}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BehaviorTree</RootNamespace>
<AssemblyName>BehaviorTree</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<RootNamespace>Login</RootNamespace>
<AssemblyName>Login</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Bin\Debug\</OutputPath>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
......@@ -27,56 +24,29 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Bin\Release\</OutputPath>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MongoDB.Bson, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver">
<HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference>
<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="BehaviorTree.cs" />
<Compile Include="BlackBoard.cs" />
<Compile Include="Node.cs" />
<Compile Include="BehaviorTreeFactory.cs" />
<Compile Include="NodeAttribute.cs" />
<Compile Include="NodeType.cs" />
<Compile Include="Not.cs" />
<Compile Include="Selector.cs" />
<Compile Include="Sequence.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Platform\Common\Common.csproj">
<Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\Model\Model.csproj">
<Project>{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}</Project>
<Name>Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.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>
<!-- 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>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Login")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Login")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("bef9bfd1-d7ec-45dd-95b1-7b4397ab4812")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册