|
@@ -0,0 +1,229 @@
|
|
|
+using CommonAI.RTS.Manhattan;
|
|
|
+using CommonAI.Zone;
|
|
|
+using CommonAI.Zone.Helper;
|
|
|
+using CommonAI.Zone.ZoneEditor;
|
|
|
+using CommonAI.ZoneClient;
|
|
|
+using CommonLang.Geometry.SceneGraph2D;
|
|
|
+using ET;
|
|
|
+using NLog.Fluent;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using UnityEngine.Scripting;
|
|
|
+using XmdsCommon.EditorData;
|
|
|
+using XmdsCommon.Plugin;
|
|
|
+using Log = ET.Log;
|
|
|
+
|
|
|
+[FriendOf(typeof(BattleResComponent))]
|
|
|
+public static class BattleResourceMgr
|
|
|
+{
|
|
|
+ [ObjectSystem]
|
|
|
+ public class BattleResComponentAwakeSystem : AwakeSystem<BattleResComponent>
|
|
|
+ {
|
|
|
+ protected override void Awake(BattleResComponent self)
|
|
|
+ {
|
|
|
+ self.GameEditorData = new EditorTemplates("", TemplateManager.MessageCodec);
|
|
|
+ TemplateManager.setFactory(new XmdsUnityLocalFactory());
|
|
|
+
|
|
|
+ LoadGameEditorBin(self).Coroutine();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static async ETTask LoadGameEditorBin(BattleResComponent self)
|
|
|
+ {
|
|
|
+ var op = await YooAssetProxy.GetRawFileAsync("GameEditor_e1");
|
|
|
+ var e1 = op.GetRawBytes();
|
|
|
+ if (e1 == null)
|
|
|
+ {
|
|
|
+ Log.Error("not found GameEditor e1 data.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log.Debug("to load e1");
|
|
|
+
|
|
|
+ //var zippedStream = new MemoryStream(e1);
|
|
|
+ var binLoadStream = new MemoryStream(e1);
|
|
|
+ //LZMAHelper.Decompress(zippedStream, e1.Length, binLoadStream);
|
|
|
+ var binMemDic = InitBinFilePostionDic(binLoadStream);
|
|
|
+
|
|
|
+ var editorData = self.GameEditorData;
|
|
|
+ editorData.LoadAllCFG(binMemDic["config"]);
|
|
|
+ LoadTemplates<CommonAI.Zone.UnitInfo>(editorData, binMemDic["units"]);
|
|
|
+ LoadTemplates<SkillTemplate>(editorData, binMemDic["skills"]);
|
|
|
+ LoadTemplates<SpellTemplate>(editorData, binMemDic["spells"]);
|
|
|
+ LoadTemplates<BuffTemplate>(editorData, binMemDic["buffs"]);
|
|
|
+ LoadTemplates<ItemTemplate>(editorData, binMemDic["items"]);
|
|
|
+ LoadTemplates<UnitEventTemplate>(editorData, binMemDic["unit_events"]);
|
|
|
+ LoadTemplates<UnitTriggerTemplate>(editorData, binMemDic["unit_triggers"]);
|
|
|
+ LoadSceneSnapData(binMemDic["snaps"]);
|
|
|
+ LoadNewSceneSnapData(binMemDic["newsnaps"]);
|
|
|
+
|
|
|
+ TemplateManager.Formula.InitPluginsData(editorData);
|
|
|
+ editorData.Templates.RehashAll();
|
|
|
+ Log.Info("load e1 end");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Dictionary<string, MemoryStream> InitBinFilePostionDic(MemoryStream binLoadStream)
|
|
|
+ {
|
|
|
+ var binMemDic = new Dictionary<string, MemoryStream>();
|
|
|
+ var br = new BinaryReader(binLoadStream);
|
|
|
+ binLoadStream.Position = 0;
|
|
|
+ var count = br.ReadByte();
|
|
|
+ var names = new string[count];
|
|
|
+ var sizes = new int[count];
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
+ {
|
|
|
+ names[i] = br.ReadString();
|
|
|
+ sizes[i] = br.ReadInt32();
|
|
|
+ }
|
|
|
+
|
|
|
+ var offset = (int) binLoadStream.Position;
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
+ {
|
|
|
+ var name = names[i];
|
|
|
+ var size = sizes[i];
|
|
|
+ binMemDic[name] = new MemoryStream();
|
|
|
+ binLoadStream.Position = offset;
|
|
|
+ binLoadStream.CopyTo(binMemDic[name], size);
|
|
|
+ binMemDic[name].Position = 0;
|
|
|
+ offset += size;
|
|
|
+ }
|
|
|
+
|
|
|
+ return binMemDic;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void LoadTemplates<T>(EditorTemplates template, Stream stream) where T : class, ITemplateData
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var br = new BinaryReader(stream);
|
|
|
+ var n = br.ReadInt32();
|
|
|
+ for (var i = 0; i < n; i++)
|
|
|
+ {
|
|
|
+ var name = br.ReadString();
|
|
|
+ var len = br.ReadInt32();
|
|
|
+ var rpos = stream.Position;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ template.LoadTemplate<T>(stream);
|
|
|
+ }
|
|
|
+ catch (Exception err)
|
|
|
+ {
|
|
|
+ Log.Error("LoadTemplate:{0},{1}", typeof(T), name);
|
|
|
+ Log.Error(err);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ stream.Position = rpos + len;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Log.Error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void LoadSceneSnapData(Stream stream)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var br = new BinaryReader(stream);
|
|
|
+ var n = br.ReadInt32();
|
|
|
+ for (var i = 0; i < n; i++)
|
|
|
+ {
|
|
|
+ var _id = br.ReadInt32();
|
|
|
+ var _len = br.ReadInt32();
|
|
|
+ var _dat = br.ReadBytes(_len);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SceneSnapManager.LoadSceneSnapData(_id, _dat);
|
|
|
+ }
|
|
|
+ catch (Exception err)
|
|
|
+ {
|
|
|
+ Log.Error(err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Log.Error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void LoadNewSceneSnapData(Stream stream)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var br = new BinaryReader(stream);
|
|
|
+ var n = br.ReadInt32();
|
|
|
+ for (var i = 0; i < n; i++)
|
|
|
+ {
|
|
|
+ var _id = br.ReadInt32();
|
|
|
+ var _len = br.ReadInt32();
|
|
|
+ var _dat = br.ReadBytes(_len);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SceneSnapManager.LoadBinUnitSnapData(_id, _dat);
|
|
|
+ }
|
|
|
+ catch (Exception err)
|
|
|
+ {
|
|
|
+ Log.Error(err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Log.Error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class XmdsUnityLocalFactory : XmdsZoneFactory
|
|
|
+ {
|
|
|
+ public override ZoneLayer CreateClientZoneLayer(EditorTemplates templates, ILayerClient listener)
|
|
|
+ {
|
|
|
+ return new HZUnityZoneLayer(templates, listener);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //-----------------------------------------------------------------------------------------------------
|
|
|
+ #region 接入Untiy寻路
|
|
|
+ public class HZUnityZoneLayer : XmdsCommon.ZoneClient.HZZoneLayer
|
|
|
+ {
|
|
|
+ public HZUnityZoneLayer(EditorTemplates dataroot, ILayerClient client)
|
|
|
+ : base(dataroot, client)
|
|
|
+ {
|
|
|
+ Log.Debug("in=====================");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void InitTerrain(ClientEnterScene msg, out ZoneManhattanMap terrain_data,
|
|
|
+ out AstarManhattan path_finder, out ManhattanMapAreaGenerator area_gen)
|
|
|
+ {
|
|
|
+ var data = TerrainSrc.Clone() as ZoneInfo;
|
|
|
+ terrain_data = new ZoneManhattanMap(data, Templates.TerrainDefinition);
|
|
|
+ path_finder = new HZUnityAstarManhattan(msg.sceneID, terrain_data, true, 0);
|
|
|
+ area_gen = new ManhattanMapAreaGenerator(terrain_data.Data);
|
|
|
+ this.Data.Terrain = null;
|
|
|
+ this.IsShareTerrain = false;
|
|
|
+ this.IsIgnoreTerrainTouch = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class HZUnityAstarManhattan : AstarManhattan
|
|
|
+ {
|
|
|
+ public HZUnityAstarManhattan(int sceneId, IManhattanMap map_data, bool inclined = true, int space_size = 0)
|
|
|
+ : base(sceneId, map_data, inclined, space_size)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public override FindPathResult findPath(float sx, float sy, float dx, float dy, out MWayPoint ret,
|
|
|
+ bool optimize = true)
|
|
|
+ {
|
|
|
+ // TODO 接入Untiy寻路
|
|
|
+ // NavMesh.CalculatePath();
|
|
|
+ return base.findPath(sx, sy, dx, dy, out ret, optimize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+}
|