合理化服务器命名,使开发者更容易理解。

Scene的routeId更名为locationId
This commit is contained in:
ALEXTANGXIAO
2023-07-27 00:33:39 +08:00
parent d1c93f15d6
commit b7b2262d53
19 changed files with 134 additions and 150 deletions

View File

@@ -194,14 +194,14 @@ namespace TEngine
public static T Create<T>(Scene scene, bool isRunEvent = true) where T : Entity, new()
{
var entity = Create<T>(scene.RouteId, isRunEvent);
var entity = Create<T>(scene.LocationId, isRunEvent);
entity.Scene = scene;
return entity;
}
public static T Create<T>(Scene scene, long id, bool isRunEvent = true) where T : Entity, new()
{
var entity = Create<T>(id, scene.RouteId, isRunEvent);
var entity = Create<T>(id, scene.LocationId, isRunEvent);
entity.Scene = scene;
return entity;
}
@@ -235,12 +235,12 @@ namespace TEngine
return entity;
}
private static T Create<T>(long id, uint routeId, bool isRunEvent = true) where T : Entity, new()
protected static T Create<T>(long id, uint locationId, bool isRunEvent = true) where T : Entity, new()
{
return Create<T>(id, IdFactory.NextEntityId(routeId), isRunEvent);
return Create<T>(id, IdFactory.NextEntityId(locationId), isRunEvent);
}
private static T Create<T>(long id, long runtimeId, bool isRunEvent = true) where T : Entity, new()
protected static T Create<T>(long id, long runtimeId, bool isRunEvent = true) where T : Entity, new()
{
var entity = Rent<T>(typeof(T));
entity.Id = id;
@@ -264,13 +264,6 @@ namespace TEngine
return entity;
}
protected static Scene CreateScene(long id, bool isRunEvent = true)
{
var entity = Create<Scene>(id, id, isRunEvent);
entity.Scene = entity;
return entity;
}
#endregion
#region Members
@@ -293,12 +286,12 @@ namespace TEngine
[BsonIgnore]
[JsonIgnore]
[IgnoreDataMember]
public Scene Scene { get; private set; }
public Scene Scene { get; protected set; }
[BsonIgnore]
[JsonIgnore]
[IgnoreDataMember]
public Entity Parent { get; private set; }
public Entity Parent { get; protected set; }
[BsonElement("t")]
[BsonIgnoreIfNull]
@@ -321,7 +314,7 @@ namespace TEngine
public T AddComponent<T>() where T : Entity, new()
{
var entity = Create<T>(Id, Scene.RouteId, false);
var entity = Create<T>(Id, Scene.LocationId, false);
AddComponent(entity);
EntitiesSystem.Instance.Awake(entity);
EntitiesSystem.Instance.StartUpdate(entity);
@@ -330,7 +323,7 @@ namespace TEngine
public T AddComponent<T>(long id) where T : Entity, new()
{
var entity = Create<T>(id, Scene.RouteId, false);
var entity = Create<T>(id, Scene.LocationId, false);
AddComponent(entity);
EntitiesSystem.Instance.Awake(entity);
EntitiesSystem.Instance.StartUpdate(entity);
@@ -538,7 +531,7 @@ namespace TEngine
{
Scene = scene;
#if TENGINE_NET
RuntimeId = IdFactory.NextEntityId(scene.RouteId);
RuntimeId = IdFactory.NextEntityId(scene.LocationId);
#else
RuntimeId = IdFactory.NextRunTimeId();
#endif

View File

@@ -12,16 +12,15 @@ namespace TEngine
public sealed class Scene : Entity, INotSupportedPool
{
public string Name { get; private set; }
public uint RouteId { get; private set; }
public uint LocationId { get; private set; }
#if TENGINE_UNITY
public Session Session { get; private set; }
public SceneConfigInfo SceneInfo { get; private set; }
#endif
#if TENGINE_NET
public string SceneType { get; private set; }
public World World { get; private set; }
public Server Server { get; private set; }
public uint SceneConfigId { get; private set; }
public SceneConfigInfo SceneInfo => ConfigTableManage.SceneConfig(SceneConfigId);
#endif
public static readonly List<Scene> Scenes = new List<Scene>();
@@ -33,11 +32,11 @@ namespace TEngine
}
Name = null;
RouteId = 0;
this.LocationId = 0;
#if TENGINE_NET
World = null;
Server = null;
SceneConfigId = 0;
SceneType = null;
#endif
#if TENGINE_UNITY
SceneInfo = null;
@@ -61,8 +60,10 @@ namespace TEngine
#if TENGINE_UNITY
public static Scene Create(string name)
{
var runTimeId = IdFactory.NextRunTimeId();
var scene = CreateScene(runTimeId);
var sceneId = IdFactory.NextRunTimeId();
var scene = Create<Scene>(sceneId, sceneId);
scene.Scene = scene;
scene.Parent = scene;
scene.Name = name;
Scenes.Add(scene);
return scene;
@@ -77,41 +78,81 @@ namespace TEngine
}
#else
/// <summary>
/// 创建一个Scene
/// 创建一个Scene、但这个Scene是在某个Scene下面的Scene
/// </summary>
/// <param name="server"></param>
/// <param name="outerBindIp"></param>
/// <param name="sceneInfo"></param>
/// <param name="runEvent"></param>
/// <param name="onSetNetworkComplete"></param>
/// <param name="scene"></param>
/// <param name="sceneName"></param>
/// <param name="sceneType"></param>
/// <returns></returns>
public static async FTask<Scene> Create(Server server, string outerBindIp, SceneConfigInfo sceneInfo, Action<Session> onSetNetworkComplete = null, bool runEvent = true)
public static async FTask<Scene> Create(Scene scene, string sceneType, string sceneName)
{
var scene = CreateScene(sceneInfo.EntityId);
sceneInfo.Scene = scene;
scene.Name = sceneInfo.Name;
scene.RouteId = sceneInfo.RouteId;
scene.Server = server;
scene.SceneConfigId = sceneInfo.Id;
var newScene = Create<Scene>(scene);
newScene.Scene = scene;
newScene.Parent = scene;
newScene.Name = sceneName;
newScene.SceneType = sceneType;
newScene.Server = scene.Server;
newScene.LocationId = scene.Server.Id;
if (sceneInfo.WorldId != 0)
if (scene.World !=null)
{
// 有可能不需要数据库、所以这里默认0的情况下就不创建数据库了
scene.World = World.Create(sceneInfo.WorldId);
newScene.World = scene.World;
}
if (!string.IsNullOrEmpty(sceneInfo.NetworkProtocol) && !string.IsNullOrEmpty(outerBindIp) && sceneInfo.OuterPort != 0)
if (!string.IsNullOrEmpty(sceneType))
{
await EventSystem.Instance.PublishAsync(new OnCreateScene(scene));
}
Scenes.Add(scene);
return scene;
}
/// <summary>
/// 创建一个Scene。
/// </summary>
/// <param name="server"></param>
/// <param name="sceneType"></param>
/// <param name="sceneName"></param>
/// <param name="sceneId"></param>
/// <param name="worldId"></param>
/// <param name="networkProtocol"></param>
/// <param name="outerBindIp"></param>
/// <param name="outerPort"></param>
/// <returns></returns>
public static async FTask<Scene> Create(Server server, string sceneType, string sceneName, long sceneId =0, uint worldId =0, string networkProtocol = null, string outerBindIp = null, int outerPort = 0)
{
if (sceneId == 0)
{
sceneId = new EntityIdStruct(server.Id, 0, 0);
}
var scene = Create<Scene>(sceneId, sceneId);
scene.Scene = scene;
scene.Parent = scene;
scene.Name = sceneName;
scene.SceneType = sceneType;
scene.Server = server;
scene.LocationId = server.Id;
if (worldId != 0)
{
// 有可能不需要数据库、所以这里默认0的情况下就不创建数据库了
scene.World = World.Create(worldId);
}
if (!string.IsNullOrEmpty(networkProtocol) && !string.IsNullOrEmpty(outerBindIp) && outerPort != 0)
{
// 设置Scene的网络、目前只支持KCP和TCP
var networkProtocolType = Enum.Parse<NetworkProtocolType>(sceneInfo.NetworkProtocol);
var networkProtocolType = Enum.Parse<NetworkProtocolType>(networkProtocol);
var serverNetworkComponent = scene.AddComponent<ServerNetworkComponent>();
var address = NetworkHelper.ToIPEndPoint($"{outerBindIp}:{sceneInfo.OuterPort}");
var address = NetworkHelper.ToIPEndPoint($"{outerBindIp}:{outerPort}");
serverNetworkComponent.Initialize(networkProtocolType, NetworkTarget.Outer, address);
}
if (runEvent && sceneInfo.SceneType != null)
if (!string.IsNullOrEmpty(sceneType))
{
switch (sceneInfo.SceneType)
switch (sceneType)
{
case "Addressable":
{
@@ -121,7 +162,7 @@ namespace TEngine
default:
{
// 没有SceneType目前只有代码创建的Scene才会这样、目前只有Server的Scene是这样
await EventSystem.Instance.PublishAsync(new OnCreateScene(sceneInfo, onSetNetworkComplete));
await EventSystem.Instance.PublishAsync(new OnCreateScene(scene));
break;
}
}
@@ -131,42 +172,14 @@ namespace TEngine
return scene;
}
/// <summary>
/// 一般用于创建临时Scene、如果不是必要不建议使用这个接口
/// </summary>
/// <param name="name"></param>
/// <param name="server"></param>
/// <param name="entityId"></param>
/// <param name="sceneConfigId"></param>
/// <param name="networkProtocol"></param>
/// <param name="outerBindIp"></param>
/// <param name="outerPort"></param>
/// <param name="runEvent"></param>
/// <param name="onSetNetworkComplete"></param>
/// <returns></returns>
public static async FTask<Scene> Create(string name, Server server, long entityId, uint sceneConfigId = 0, string networkProtocol = null, string outerBindIp = null, int outerPort = 0, Action<Session> onSetNetworkComplete = null, bool runEvent = true)
{
var sceneInfo = new SceneConfigInfo()
{
Name = name,
EntityId = entityId,
Id = sceneConfigId,
NetworkProtocol = networkProtocol,
OuterPort = outerPort,
WorldId = ((EntityIdStruct)entityId).WordId
};
return await Create(server, outerBindIp, sceneInfo, onSetNetworkComplete, runEvent);
}
public static List<SceneConfigInfo> GetSceneInfoByRouteId(uint routeId)
public static List<SceneConfigInfo> GetSceneInfoByServerConfigId(uint serverConfigId)
{
var list = new List<SceneConfigInfo>();
var allSceneConfig = ConfigTableManage.AllSceneConfig();
foreach (var sceneConfigInfo in allSceneConfig)
{
if (sceneConfigInfo.RouteId != routeId)
if (sceneConfigInfo.ServerConfigId != serverConfigId)
{
continue;
}

View File

@@ -5,13 +5,11 @@ namespace TEngine
{
public struct OnCreateScene
{
public readonly SceneConfigInfo SceneInfo;
public readonly Action<Session> OnSetNetworkComplete;
public readonly Scene Scene;
public OnCreateScene(SceneConfigInfo sceneInfo, Action<Session> onSetNetworkComplete)
public OnCreateScene(Scene scene)
{
SceneInfo = sceneInfo;
OnSetNetworkComplete = onSetNetworkComplete;
Scene = scene;
}
}
}

View File

@@ -33,8 +33,6 @@ namespace TEngine.Core
{
var configFile = GetConfigPath(dataConfig);
var bytes = File.ReadAllBytes(configFile);
// var data = (AProto) ProtoBufHelper.FromBytes(typeof(T), bytes, 0, bytes.Length);
// var data = ProtoBufHelper.FromBytes<T>(bytes, 0, bytes.Length);
var data = (T)ProtoBufHelper.FromBytes(typeof(T), bytes, 0, bytes.Length);
data.AfterDeserialization();
ConfigDic[dataConfig] = data;

View File

@@ -14,26 +14,26 @@ namespace TEngine.Core
public uint Time{ get; private set; }
public uint Sequence{ get; private set; }
public uint RouteId { get; private set; }
public uint LocationId { get; private set; }
public ushort AppId => (ushort)(RouteId >> 10 & RouteIdStruct.MaskAppId);
public ushort WordId=> (ushort)(RouteId & RouteIdStruct.MaskWordId);
public ushort AppId => (ushort)(this.LocationId >> 10 & RouteIdStruct.MaskAppId);
public ushort WordId=> (ushort)(this.LocationId & RouteIdStruct.MaskWordId);
public const int MaskRouteId = 0x3FFFF;
public const int MaskSequence = 0xFFFF;
public EntityIdStruct(uint routeId, uint time, uint sequence)
public EntityIdStruct(uint locationId, uint time, uint sequence)
{
Time = time;
Sequence = sequence;
RouteId = routeId;
LocationId = locationId;
}
public static implicit operator long(EntityIdStruct entityIdStruct)
{
ulong result = 0;
result |= entityIdStruct.Sequence;
result |= (ulong)entityIdStruct.RouteId << 16;
result |= (ulong)entityIdStruct.LocationId << 16;
result |= (ulong)entityIdStruct.Time << 34;
return (long)result;
}
@@ -46,7 +46,7 @@ namespace TEngine.Core
Sequence = (uint) (result & MaskSequence)
};
result >>= 16;
idStruct.RouteId = (uint) (result & 0x3FFFF);
idStruct.LocationId = (uint) (result & 0x3FFFF);
result >>= 18;
idStruct.Time = (uint) result;
return idStruct;

View File

@@ -32,7 +32,7 @@ namespace TEngine.Core
return new RuntimeIdStruct(_lastRunTimeIdTime, _lastRunTimeIdSequence);
}
public static long NextEntityId(uint routeId)
public static long NextEntityId(uint locationId)
{
var time = (uint)((TimeHelper.Now - Epoch2023) / 1000);
@@ -47,7 +47,7 @@ namespace TEngine.Core
_lastEntityIdSequence = 0;
}
return new EntityIdStruct(routeId, _lastEntityIdTime, _lastEntityIdSequence);
return new EntityIdStruct(locationId, _lastEntityIdTime, _lastEntityIdSequence);
}
public static uint GetRouteId(long entityId)

View File

@@ -2,16 +2,14 @@ namespace TEngine
{
public class SceneConfigInfo
{
public Scene Scene;
public long EntityId;
public uint Id;
public string SceneType;
public string Name;
public string NetworkProtocol;
public uint RouteId;
public long EntityId;
public string SceneType;
public uint ServerConfigId;
public uint WorldId;
public int OuterPort;
public string NetworkProtocol;
}
}

View File

@@ -103,13 +103,13 @@ namespace TEngine
private static readonly Dictionary<uint, Server> Servers = new Dictionary<uint, Server>();
public static async FTask Create(uint routeId)
public static async FTask Create(uint serverConfigId)
{
var serverConfigInfo = ConfigTableManage.ServerConfig(routeId);
var serverConfigInfo = ConfigTableManage.ServerConfig(serverConfigId);
if (serverConfigInfo == null)
{
Log.Error($"not found server by Id:{routeId}");
Log.Error($"not found server by Id:{serverConfigId}");
return;
}
@@ -121,14 +121,14 @@ namespace TEngine
return;
}
var sceneInfos = Scene.GetSceneInfoByRouteId(routeId);
await Create(routeId, machineConfigInfo.InnerBindIP, serverConfigInfo.InnerPort, machineConfigInfo.OuterBindIP, sceneInfos);
// Log.Info($"ServerId:{routeId} is start complete");
var sceneInfos = Scene.GetSceneInfoByServerConfigId(serverConfigId);
await Create(serverConfigId, machineConfigInfo.InnerBindIP, serverConfigInfo.InnerPort, machineConfigInfo.OuterBindIP, sceneInfos);
// Log.Info($"ServerId:{serverConfigId} is start complete");
}
public static async FTask<Server> Create(uint routeId, string innerBindIp, int innerPort, string outerBindIp, List<SceneConfigInfo> sceneInfos)
public static async FTask<Server> Create(uint serverConfigId, string innerBindIp, int innerPort, string outerBindIp, List<SceneConfigInfo> sceneInfos)
{
if (Servers.TryGetValue(routeId, out var server))
if (Servers.TryGetValue(serverConfigId, out var server))
{
return server;
}
@@ -137,10 +137,10 @@ namespace TEngine
server = new Server
{
Id = routeId
Id = serverConfigId
};
server.Scene = await Scene.Create($"ServerScene{routeId}", server, new EntityIdStruct(routeId, 0, 0));
server.Scene = await Scene.Create(server,null,$"ServerScene{serverConfigId}");
// 创建网络、Server下的网络只能是内部网络、外部网络是在Scene中定义
@@ -155,16 +155,17 @@ namespace TEngine
foreach (var sceneConfig in sceneInfos)
{
await Scene.Create(server, outerBindIp, sceneConfig);
await Scene.Create(server, sceneConfig.SceneType, sceneConfig.Name, sceneConfig.EntityId,
sceneConfig.WorldId, sceneConfig.NetworkProtocol, outerBindIp, sceneConfig.OuterPort);
}
Servers.Add(routeId, server);
Servers.Add(serverConfigId, server);
return server;
}
public static Server Get(uint routeId)
public static Server Get(uint serverConfigId)
{
return Servers.TryGetValue(routeId, out var server) ? server : null;
return Servers.TryGetValue(serverConfigId, out var server) ? server : null;
}
#endregion

View File

@@ -41,7 +41,7 @@ namespace TEngine.Core.Network
scene = entity.Scene;
}
Log.Error($"SceneWorld:{session.Scene.World.Id} SceneRouteId:{scene.RouteId} SceneType:{scene.SceneInfo.SceneType} EntityId {tEntity.Id} : Error {e}");
Log.Error($"SceneWorld:{session.Scene.World.Id} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}");
}
}
@@ -100,7 +100,7 @@ namespace TEngine.Core.Network
scene = entity.Scene;
}
Log.Error($"SceneWorld:{session.Scene.World.Id} SceneRouteId:{scene.RouteId} SceneType:{scene.SceneInfo.SceneType} EntityId {tEntity.Id} : Error {e}");
Log.Error($"SceneWorld:{session.Scene.World?.Id} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}");
response.ErrorCode = CoreErrorCode.ErrRpcFail;
}
finally
@@ -144,7 +144,7 @@ namespace TEngine.Core.Network
scene = entity.Scene;
}
Log.Error($"SceneWorld:{session.Scene.World?.Id} SceneRouteId:{scene.RouteId} SceneType:{scene.SceneInfo.SceneType} EntityId {tEntity.Id} : Error {e}");
Log.Error($"SceneWorld:{session.Scene.World.Id} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}");
}
finally
{
@@ -207,7 +207,7 @@ namespace TEngine.Core.Network
scene = entity.Scene;
}
Log.Error($"SceneWorld:{session.Scene.World.Id} SceneRouteId:{scene.RouteId} SceneType:{scene.SceneInfo.SceneType} EntityId {tEntity.Id} : Error {e}");
Log.Error($"SceneWorld:{session.Scene.World?.Id} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}");
response.ErrorCode = CoreErrorCode.ErrRpcFail;
}
finally

View File

@@ -35,7 +35,7 @@ public static class MessageHelper
}
EntityIdStruct entityIdStruct = entityId;
var session = scene.Server.GetSession(entityIdStruct.RouteId);
var session = scene.Server.GetSession(entityIdStruct.LocationId);
session.Send(message, 0, entityId);
}
@@ -48,7 +48,7 @@ public static class MessageHelper
}
EntityIdStruct entityIdStruct = entityId;
var session = scene.Server.GetSession(entityIdStruct.RouteId);
var session = scene.Server.GetSession(entityIdStruct.LocationId);
session.Send(message, 0, routeTypeOpCode, entityId);
}
@@ -81,7 +81,7 @@ public static class MessageHelper
EntityIdStruct entityIdStruct = entityId;
var rpcId = ++_rpcId;
var session = scene.Server.GetSession(entityIdStruct.RouteId);
var session = scene.Server.GetSession(entityIdStruct.LocationId);
var requestCallback = FTask<IResponse>.Create(false);
RequestCallback.Add(rpcId, MessageSender.Create(rpcId, requestType, requestCallback));
session.Send(request, rpcId, routeTypeOpCode, entityId);
@@ -98,7 +98,7 @@ public static class MessageHelper
EntityIdStruct entityIdStruct = entityId;
var rpcId = ++_rpcId;
var session = scene.Server.GetSession(entityIdStruct.RouteId);
var session = scene.Server.GetSession(entityIdStruct.LocationId);
var requestCallback = FTask<IResponse>.Create(false);
RequestCallback.Add(rpcId, MessageSender.Create(rpcId, request, requestCallback));
session.Send(request, rpcId, entityId);

View File

@@ -1 +1 @@
{"MachineConfig":1689771956715,"SceneConfig":1689619864417,"ServerConfig":1689620185714,"WorldConfig":1689267887552}
{"MachineConfig":1690328264682,"SceneConfig":1690415187917,"ServerConfig":1690328264682,"WorldConfig":1690328264683}

View File

@@ -1,7 +1,6 @@
{"List":[
{"Id":1,"EntityId":17246978048,"RouteId":1024,"WorldId":0,"SceneType":"Gate","Name":"Gate","NetworkProtocol":"KCP","OuterPort":20000},
{"Id":2,"EntityId":34493956096,"RouteId":2048,"WorldId":0,"SceneType":"Addressable","Name":"Addressable1","NetworkProtocol":null,"OuterPort":0},
{"Id":4,"EntityId":68920803328,"RouteId":3072,"WorldId":0,"SceneType":"Map","Name":"Map1","NetworkProtocol":null,"OuterPort":0},
{"Id":5,"EntityId":86167781376,"RouteId":4096,"WorldId":0,"SceneType":"Chat","Name":"Chat1","NetworkProtocol":null,"OuterPort":0},
{"Id":6,"EntityId":103414759424,"RouteId":5120,"WorldId":0,"SceneType":"Gameplay","Name":"Gameplay1","NetworkProtocol":null,"OuterPort":0}
{"Id":1,"EntityId":17246978048,"ServerConfigId":1024,"WorldId":0,"SceneType":"Gate","Name":"Gate","NetworkProtocol":"KCP","OuterPort":20000},
{"Id":2,"EntityId":34493956096,"ServerConfigId":2048,"WorldId":0,"SceneType":"Addressable","Name":"Addressable1","NetworkProtocol":null,"OuterPort":0},
{"Id":4,"EntityId":68920803328,"ServerConfigId":3072,"WorldId":0,"SceneType":"Map","Name":"Map1","NetworkProtocol":null,"OuterPort":0},
{"Id":5,"EntityId":86167781376,"ServerConfigId":4096,"WorldId":0,"SceneType":"Chat","Name":"Chat1","NetworkProtocol":null,"OuterPort":0}
]}

View File

@@ -29,9 +29,9 @@ namespace TEngine
public SceneConfig Get(uint id, bool check = true)
{
if (this._configs.TryGetValue(id, out SceneConfig? config))
if (_configs.ContainsKey(id))
{
return config;
return _configs[id];
}
if (check)
@@ -79,7 +79,7 @@ namespace TEngine
[ProtoMember(2, IsRequired = true)]
public long EntityId { get; set; } // 实体Id
[ProtoMember(3, IsRequired = true)]
public uint RouteId { get; set; } // 路由Id
public uint ServerConfigId { get; set; } // 服务配置Id
[ProtoMember(4, IsRequired = true)]
public uint WorldId { get; set; } // 世界Id
[ProtoMember(5, IsRequired = true)]

View File

@@ -7,7 +7,6 @@ namespace TEngine
public const int Addressable = 2;
public const int Map = 3;
public const int Chat = 4;
public const int Gameplay = 5;
public static readonly Dictionary<string, int> SceneDic = new Dictionary<string, int>()
{
@@ -15,7 +14,6 @@ namespace TEngine
{ "Addressable", 2 },
{ "Map", 3 },
{ "Chat", 4 },
{ "Gameplay", 5 },
};
}
}

View File

@@ -10,7 +10,7 @@ public static class AddressableSceneHelper
var sceneEntityId = 0L;
foreach (var sceneConfig in SceneConfigData.Instance.List)
{
if (sceneConfig.RouteId == 3072)
if (sceneConfig.ServerConfigId == 3072)
{
sceneEntityId = sceneConfig.EntityId;
break;

View File

@@ -74,7 +74,7 @@ public static class ConfigTableSystem
SceneType = sceneConfig.SceneType,
Name = sceneConfig.Name,
NetworkProtocol = sceneConfig.NetworkProtocol,
RouteId = sceneConfig.RouteId,
ServerConfigId = sceneConfig.ServerConfigId,
WorldId = sceneConfig.WorldId,
OuterPort = sceneConfig.OuterPort
};
@@ -126,7 +126,7 @@ public static class ConfigTableSystem
SceneType = sceneConfig.SceneType,
Name = sceneConfig.Name,
NetworkProtocol = sceneConfig.NetworkProtocol,
RouteId = sceneConfig.RouteId,
ServerConfigId = sceneConfig.ServerConfigId,
WorldId = sceneConfig.WorldId,
OuterPort = sceneConfig.OuterPort
});

View File

@@ -22,21 +22,15 @@ public enum SceneType: long
/// </summary>
Addressable = 1 << 2,
/// <summary>
/// 场景GamePlay
/// <remarks>游戏玩法服。</remarks>
/// </summary>
Gameplay = 1 << 3,
/// <summary>
/// 游戏场景服。
/// </summary>
Map = 1 << 4,
Map = 1 << 3,
/// <summary>
/// 游戏聊天服。
/// </summary>
Chat = 1 << 5,
Chat = 1 << 4,
}
/// <summary>
@@ -51,24 +45,16 @@ public class OnCreateScene : AsyncEventSystem<TEngine.OnCreateScene>
// OnCreateScene这个事件就是给开发者使用的
// 比如Address协议这里、我就是做了一个管理Address地址的一个组件挂在到Address这个Scene下面了
// 比如Map下你需要一些自定义组件、你也可以在这里操作
var sceneConfigInfo = self.SceneInfo;
switch (sceneConfigInfo.SceneType.Parse<SceneType>())
var scene = self.Scene;
switch (scene.SceneType.Parse<SceneType>())
{
case SceneType.Addressable:
{
sceneConfigInfo.Scene.AddComponent<AddressableManageComponent>();
break;
}
case SceneType.Gate:
{
sceneConfigInfo.Scene.AddComponent<AccountComponent>();
self.Scene.AddComponent<AccountComponent>();
break;
}
case SceneType.Gameplay:
break;
}
Log.Info($"scene create: {self.SceneInfo.SceneType} {self.SceneInfo.Name} SceneId:{self.SceneInfo.Id} ServerId:{self.SceneInfo.RouteId} WorldId:{self.SceneInfo.WorldId}");
Log.Info($"scene create: {self.Scene.SceneType} {self.Scene.Name} SceneId:{self.Scene.Id} LocationId:{self.Scene.LocationId} WorldId:{self.Scene.World?.Id}");
await FTask.CompletedTask;
}