提交 15b049d1 编写于 作者: T tanghai

去除了BsonClassMap注册方式,使用BsonKnownTypes标签注册,更简单方便

上级 d4a1ee58
{ "_t" : "StartConfig", "_id" : NumberLong("96832337674244"), "Type" : "Config", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832337674245"), "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832337674246"), "Host" : "127.0.0.1", "Port" : 10000 }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("96871765901315"), "Type" : "Config", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96871765901316"), "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "OuterConfig", "_id" : NumberLong("96871765901317"), "Host" : "127.0.0.1", "Port" : 10000 }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
......@@ -2,7 +2,7 @@
using Base;
using Model;
using NLog;
using Object = Base.Object;
using Object = Model.Object;
namespace App
{
......@@ -12,8 +12,6 @@ namespace App
{
try
{
BsonClassMapRegister.Register();
Object.ObjectManager.Register("Model", typeof(Game).Assembly);
Object.ObjectManager.Register("Controller", DllHelper.GetController());
......
......@@ -149,33 +149,6 @@
<Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\USocketManager.cs">
<Link>Network\UNet\USocketManager.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\Component.cs">
<Link>Object\Component.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\Entity.cs">
<Link>Object\Entity.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\IAwake.cs">
<Link>Object\IAwake.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\ILoader.cs">
<Link>Object\ILoader.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\IStart.cs">
<Link>Object\IStart.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\IUpdate.cs">
<Link>Object\IUpdate.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\Object.cs">
<Link>Object\Object.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\ObjectEventAttribute.cs">
<Link>Object\ObjectEventAttribute.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\Object\ObjectManager.cs">
<Link>Object\ObjectManager.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Plugins\Base\QueueDictionary.cs">
<Link>QueueDictionary.cs</Link>
</Compile>
......
......@@ -18,7 +18,7 @@ namespace Controller
}
// 随机分配一个Gate
Entity config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
StartConfig config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
//Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
string innerAddress = $"{config.GetComponent<InnerConfig>().Host}:{config.GetComponent<InnerConfig>().Port}";
Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
......
using System;
using Base;
using Model;
using Object = Base.Object;
using Object = Model.Object;
namespace Controller
{
......
......@@ -29,7 +29,7 @@ namespace Model
}
}
public Entity GetAddress()
public StartConfig GetAddress()
{
int n = RandomHelper.RandomNumber(0, this.GateAddress.Count);
return this.GateAddress[n];
......
......@@ -86,6 +86,9 @@
<Compile Include="..\..\Unity\Assets\Scripts\Config\AConfig.cs">
<Link>Config\AConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Config\AConfigComponent.cs">
<Link>Config\AConfigComponent.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Config\ConfigAttribute.cs">
<Link>Config\ConfigAttribute.cs</Link>
</Compile>
......@@ -155,8 +158,32 @@
<Compile Include="..\..\Unity\Assets\Scripts\Message\RpcException.cs">
<Link>Message\RpcException.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\BsonClassMapRegister.cs">
<Link>Other\BsonClassMapRegister.cs</Link>
<Compile Include="..\..\Unity\Assets\Scripts\Object\Component.cs">
<Link>Object\Component.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\Entity.cs">
<Link>Object\Entity.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\IAwake.cs">
<Link>Object\IAwake.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\ILoader.cs">
<Link>Object\ILoader.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\IStart.cs">
<Link>Object\IStart.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\IUpdate.cs">
<Link>Object\IUpdate.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\Object.cs">
<Link>Object\Object.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\ObjectEventAttribute.cs">
<Link>Object\ObjectEventAttribute.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Object\ObjectManager.cs">
<Link>Object\ObjectManager.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\EntityType.cs">
<Link>Other\EntityType.cs</Link>
......
......@@ -2,8 +2,8 @@
using Base;
using UnityEditor;
using UnityEngine;
using Object = Base.Object;
using Model;
using Object = Model.Object;
namespace MyEditor
{
......@@ -12,7 +12,6 @@ namespace MyEditor
{
static EditorInit()
{
BsonClassMapRegister.Register();
EditorApplication.update += Update;
}
......
using Base;
using Model;
using UnityEditor;
public class ObjectManagerToolsWindow : EditorWindow
......
using Base;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class ClientConfig: Component
public class ClientConfig: AConfigComponent
{
public string Host = "";
public int Port;
......
using Base;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class InnerConfig : Component
public class InnerConfig : AConfigComponent
{
public string Host { get; set; }
public int Port { get; set; }
......
using Base;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class OuterConfig : Component
public class OuterConfig : AConfigComponent
{
public string Host { get; set; }
public int Port { get; set; }
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Reflection;
using Base;
using Object = Base.Object;
using Object = Model.Object;
namespace Model
{
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Reflection;
using Base;
using Object = Base.Object;
using Object = Model.Object;
namespace Model
{
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Reflection;
using Base;
using Object = Base.Object;
using Object = Model.Object;
namespace Model
{
......
using Base;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
/// <summary>
/// 每个Config的基类
/// </summary>
[BsonKnownTypes(typeof(ClientConfig))]
[BsonKnownTypes(typeof(InnerConfig))]
[BsonKnownTypes(typeof(OuterConfig))]
public abstract class AConfigComponent: Component
{
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 3a286d83056068f4ba8dfcf7a37b926d
timeCreated: 1478145676
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Base;
using UnityEngine;
using Component = Base.Component;
using UnityEngine;
namespace Model
{
......
using System;
using Base;
using UnityEngine;
using Object = Base.Object;
namespace Model
{
......@@ -9,7 +8,6 @@ namespace Model
{
private void Start()
{
BsonClassMapRegister.Register();
Object.ObjectManager.Register("Model", typeof(Game).Assembly);
Object.ObjectManager.Register("Controller", DllHelper.GetController());
......
fileFormatVersion: 2
guid: bfb63bc23132cfe47aaac731331ca16e
guid: 600c9bb417aba1641897df52e4ea0eeb
folderAsset: yes
timeCreated: 1474942922
timeCreated: 1478146107
licenseType: Pro
DefaultImporter:
userData:
......
using MongoDB.Bson.Serialization.Attributes;
namespace Base
namespace Model
{
/// <summary>
/// Component的Id与Owner Entity Id一样
/// </summary>
[BsonKnownTypes(typeof(AConfigComponent))]
public abstract class Component : Object
{
[BsonIgnore]
......
using System;
using System.Collections.Generic;
using System.Linq;
using Base;
using MongoDB.Bson.Serialization.Attributes;
namespace Base
namespace Model
{
public class Entity: Object
{
......
namespace Base
namespace Model
{
/// <summary>
/// World的Componet实现该接口后,会在World.Start时调用该Start方法
......
namespace Base
namespace Model
{
/// <summary>
/// World的Componet实现该接口,World.Load会调用Load方法
......
namespace Base
namespace Model
{
/// <summary>
/// World的Componet实现该接口后,会在World.Start时调用该Start方法
......
namespace Base
namespace Model
{
/// <summary>
/// 实现了该接口的World Componet会每帧刷新
......
using System;
using System.ComponentModel;
using Base;
using MongoDB.Bson.Serialization.Attributes;
namespace Base
namespace Model
{
public abstract class Object: IDisposable, ISupportInitialize
{
......
using System;
namespace Base
namespace Model
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class ObjectEventAttribute: Attribute
......
......@@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Base;
namespace Base
namespace Model
{
public interface IObjectEvent
{
......
using MongoDB.Bson.Serialization;
namespace Model
{
public static class BsonClassMapRegister
{
private static bool isRegister;
public static void Register()
{
if (isRegister)
{
return;
}
isRegister = true;
BsonClassMap.RegisterClassMap<InnerConfig>();
BsonClassMap.RegisterClassMap<OuterConfig>();
BsonClassMap.RegisterClassMap<ClientConfig>();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 134d0d7bf9f397e48849fe72d43bee76
timeCreated: 1477036759
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -108,15 +108,6 @@
<Compile Include="Assets\Plugins\Base\Network\UNet\UService.cs" />
<Compile Include="Assets\Plugins\Base\Network\UNet\USocket.cs" />
<Compile Include="Assets\Plugins\Base\Network\UNet\USocketManager.cs" />
<Compile Include="Assets\Plugins\Base\Object\Component.cs" />
<Compile Include="Assets\Plugins\Base\Object\Entity.cs" />
<Compile Include="Assets\Plugins\Base\Object\IAwake.cs" />
<Compile Include="Assets\Plugins\Base\Object\ILoader.cs" />
<Compile Include="Assets\Plugins\Base\Object\IStart.cs" />
<Compile Include="Assets\Plugins\Base\Object\IUpdate.cs" />
<Compile Include="Assets\Plugins\Base\Object\Object.cs" />
<Compile Include="Assets\Plugins\Base\Object\ObjectEventAttribute.cs" />
<Compile Include="Assets\Plugins\Base\Object\ObjectManager.cs" />
<Compile Include="Assets\Plugins\Base\QueueDictionary.cs" />
<Compile Include="Assets\Plugins\Base\TryLocker.cs" />
<Compile Include="Assets\Plugins\MongoDB\MongoDB.Bson\BsonConstants.cs" />
......
......@@ -97,6 +97,7 @@
<Compile Include="Assets\Scripts\Component\TimeComponent.cs" />
<Compile Include="Assets\Scripts\Component\TimerComponent.cs" />
<Compile Include="Assets\Scripts\Config\ACategory.cs" />
<Compile Include="Assets\Scripts\Config\AConfigComponent.cs" />
<Compile Include="Assets\Scripts\Config\AConfig.cs" />
<Compile Include="Assets\Scripts\Config\ConfigAttribute.cs" />
<Compile Include="Assets\Scripts\Config\ConfigHelper.cs" />
......@@ -125,7 +126,15 @@
<Compile Include="Assets\Scripts\Message\RpcException.cs" />
<Compile Include="Assets\Scripts\Entity\Config\BuffConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Message\Message.cs" />
<Compile Include="Assets\Scripts\Other\BsonClassMapRegister.cs" />
<Compile Include="Assets\Scripts\Object\Component.cs" />
<Compile Include="Assets\Scripts\Object\Entity.cs" />
<Compile Include="Assets\Scripts\Object\IAwake.cs" />
<Compile Include="Assets\Scripts\Object\ILoader.cs" />
<Compile Include="Assets\Scripts\Object\IStart.cs" />
<Compile Include="Assets\Scripts\Object\IUpdate.cs" />
<Compile Include="Assets\Scripts\Object\Object.cs" />
<Compile Include="Assets\Scripts\Object\ObjectEventAttribute.cs" />
<Compile Include="Assets\Scripts\Object\ObjectManager.cs" />
<Compile Include="Assets\Scripts\Other\EntityType.cs" />
<Compile Include="Assets\Scripts\Other\GameException.cs" />
<Compile Include="Assets\Scripts\Other\Options.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册