1、Scene.Create接口增加了一个泛型方法接口。 2、SceneConfig增加了SceneTypeConfig和SceneSubType

1、Scene.Create接口增加了一个泛型方法接口。 2、SceneConfig增加了SceneTypeConfig和SceneSubType
This commit is contained in:
ALEXTANGXIAO
2023-07-29 01:03:35 +08:00
parent f7c95d8216
commit 60a5caebae
21 changed files with 263 additions and 160 deletions

View File

@@ -9,7 +9,7 @@ using TEngine.Core.DataBase;
#pragma warning disable CS8618
namespace TEngine
{
public sealed class Scene : Entity, INotSupportedPool
public class Scene : Entity, INotSupportedPool
{
public string Name { get; private set; }
public uint LocationId { get; private set; }
@@ -18,7 +18,8 @@ namespace TEngine
public SceneConfigInfo SceneInfo { get; private set; }
#endif
#if TENGINE_NET
public string SceneType { get; private set; }
public int SceneType { get; private set; }
public int SceneSubType { get; private set; }
public World World { get; private set; }
public Server Server { get; private set; }
#endif
@@ -36,7 +37,8 @@ namespace TEngine
#if TENGINE_NET
World = null;
Server = null;
SceneType = null;
SceneType = 0;
SceneSubType = 0;
#endif
#if TENGINE_UNITY
SceneInfo = null;
@@ -58,6 +60,16 @@ namespace TEngine
}
}
#if TENGINE_UNITY
public static Scene Create()
{
var sceneId = IdFactory.NextRunTimeId();
var scene = Create<Scene>(sceneId, sceneId);
scene.Scene = scene;
scene.Parent = scene;
Scenes.Add(scene);
return scene;
}
public static Scene Create(string name)
{
var sceneId = IdFactory.NextRunTimeId();
@@ -68,6 +80,7 @@ namespace TEngine
Scenes.Add(scene);
return scene;
}
public void CreateSession(string remoteAddress, NetworkProtocolType networkProtocolType, Action onConnectComplete, Action onConnectFail,Action onConnectDisconnect, int connectTimeout = 5000)
{
var address = NetworkHelper.ToIPEndPoint(remoteAddress);
@@ -78,19 +91,20 @@ namespace TEngine
}
#else
/// <summary>
/// 创建一个Scene、但这个Scene是在某个Scene下面的Scene
/// 创建一个Scene、但这个Scene是在某个Scene下面的Scene
/// </summary>
/// <param name="scene"></param>
/// <param name="sceneName"></param>
/// <param name="sceneType"></param>
/// <param name="sceneSubType"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static async FTask<Scene> Create(Scene scene, string sceneType, string sceneName)
public static async FTask<T> Create<T>(Scene scene, int sceneType, int sceneSubType) where T : Scene, new()
{
var newScene = Create<Scene>(scene);
var newScene = Create<T>(scene);
newScene.Scene = scene;
newScene.Parent = scene;
newScene.Name = sceneName;
newScene.SceneType = sceneType;
newScene.SceneSubType = sceneSubType;
newScene.Server = scene.Server;
newScene.LocationId = scene.Server.Id;
@@ -99,13 +113,13 @@ namespace TEngine
newScene.World = scene.World;
}
if (!string.IsNullOrEmpty(sceneType))
if (sceneType > 0)
{
await EventSystem.Instance.PublishAsync(new OnCreateScene(scene));
}
Scenes.Add(scene);
return scene;
return newScene;
}
/// <summary>
@@ -113,14 +127,14 @@ namespace TEngine
/// </summary>
/// <param name="server"></param>
/// <param name="sceneType"></param>
/// <param name="sceneName"></param>
/// <param name="sceneSubType"></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)
public static async FTask<Scene> Create(Server server, int sceneType = 0, int sceneSubType = 0, long sceneId = 0, uint worldId = 0, string networkProtocol = null, string outerBindIp = null, int outerPort = 0)
{
if (sceneId == 0)
{
@@ -130,8 +144,8 @@ namespace TEngine
var scene = Create<Scene>(sceneId, sceneId);
scene.Scene = scene;
scene.Parent = scene;
scene.Name = sceneName;
scene.SceneType = sceneType;
scene.SceneSubType = sceneSubType;
scene.Server = server;
scene.LocationId = server.Id;
@@ -150,22 +164,9 @@ namespace TEngine
serverNetworkComponent.Initialize(networkProtocolType, NetworkTarget.Outer, address);
}
if (!string.IsNullOrEmpty(sceneType))
if (sceneType > 0)
{
switch (sceneType)
{
case "Addressable":
{
scene.AddComponent<AddressableManageComponent>();
break;
}
default:
{
// 没有SceneType目前只有代码创建的Scene才会这样、目前只有Server的Scene是这样
await EventSystem.Instance.PublishAsync(new OnCreateScene(scene));
break;
}
}
await EventSystem.Instance.PublishAsync(new OnCreateScene(scene));
}
Scenes.Add(scene);

View File

@@ -0,0 +1,89 @@
#if TENGINE_NET
using System.Text;
using TEngine.Core;
using TEngine.Helper;
namespace TEngine.CustomExport;
public sealed class SceneTypeConfigToEnum : ACustomExport
{
public override void Run()
{
var fullPath = FileHelper.GetFullPath("../../../Config/Excel/Server/SceneConfig.xlsx");
using var excelPackage = ExcelHelper.LoadExcel(fullPath);
var sceneType = new Dictionary<string, string>();
var sceneSubType = new Dictionary<string, string>();
var sceneTypeConfig = excelPackage.Workbook.Worksheets["SceneTypeConfig"];
for (var row = 3; row <= sceneTypeConfig.Dimension.Rows; row++)
{
var sceneTypeId = sceneTypeConfig.GetCellValue(row, 1);
var sceneTypeStr = sceneTypeConfig.GetCellValue(row, 2);
if (string.IsNullOrEmpty(sceneTypeId) || string.IsNullOrEmpty(sceneTypeStr))
{
continue;
}
sceneType.Add(sceneTypeId, sceneTypeStr);
}
var sceneSubTypeConfig = excelPackage.Workbook.Worksheets["SceneSubTypeConfig"];
for (var row = 3; row <= sceneSubTypeConfig.Dimension.Rows; row++)
{
var sceneSubTypeId = sceneSubTypeConfig.GetCellValue(row, 1);
var sceneSubTypeStr = sceneSubTypeConfig.GetCellValue(row, 2);
if (string.IsNullOrEmpty(sceneSubTypeId) || string.IsNullOrEmpty(sceneSubTypeStr))
{
continue;
}
sceneSubType.Add(sceneSubTypeId, sceneSubTypeStr);
}
if (sceneType.Count > 0 || sceneSubType.Count > 0)
{
Write(CustomExportType.Server, sceneType, sceneSubType);
}
}
private void Write(CustomExportType customExportType, Dictionary<string, string> sceneTypes, Dictionary<string, string> sceneSubType)
{
var strBuilder = new StringBuilder();
var dicBuilder = new StringBuilder();
strBuilder.AppendLine("namespace TEngine\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
strBuilder.AppendLine("\tpublic static class SceneType\n\t{");
dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary<string, int> SceneTypeDic = new Dictionary<string, int>()\n\t\t{");
foreach (var (sceneTypeId, sceneTypeStr) in sceneTypes)
{
dicBuilder.AppendLine($"\t\t\t{{ \"{sceneTypeStr}\", {sceneTypeId} }},");
strBuilder.AppendLine($"\t\tpublic const int {sceneTypeStr} = {sceneTypeId};");
}
dicBuilder.AppendLine("\t\t};");
strBuilder.Append(dicBuilder);
strBuilder.AppendLine("\t}\n");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
strBuilder.AppendLine("\tpublic static class SceneSubType\n\t{");
dicBuilder.Clear();
dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary<string, int> SceneSubTypeDic = new Dictionary<string, int>()\n\t\t{");
foreach (var (sceneSubTypeId, sceneSubTypeStr) in sceneSubType)
{
dicBuilder.AppendLine($"\t\t\t{{ \"{sceneSubTypeStr}\", {sceneSubTypeId} }},");
strBuilder.AppendLine($"\t\tpublic const int {sceneSubTypeStr} = {sceneSubTypeId};");
}
dicBuilder.AppendLine("\t\t};");
strBuilder.Append(dicBuilder);
strBuilder.AppendLine("\t}\n}");
Write("SceneType.cs", strBuilder.ToString(), customExportType);
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d254c1aefb624046ab545bd8cebbe57c
timeCreated: 1690561569