Jelajahi Sumber

行为树生成Json配置文件

tanghai 10 tahun lalu
induk
melakukan
acc65280f2

+ 8 - 8
CSharp/App/Modules/BehaviorTreeModule/AllTreeViewModel.cs

@@ -6,7 +6,7 @@ using Common.Helper;
 
 namespace Modules.BehaviorTreeModule
 {
-	[Export(typeof (AllTreeViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
+	[Export(typeof(AllTreeViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
 	public class AllTreeViewModel
 	{
 		public int MaxNodeId { get; set; }
@@ -33,8 +33,8 @@ namespace Modules.BehaviorTreeModule
 
 			var treeDict = new Dictionary<int, List<TreeNodeData>>();
 
-			byte[] bytes = File.ReadAllBytes(file);
-			AllTreeData allTreeData = ProtobufHelper.FromBytes<AllTreeData>(bytes);
+			string content = File.ReadAllText(file);
+			AllTreeData allTreeData = MongoHelper.FromJson<AllTreeData>(content);
 
 			this.MaxNodeId = 0;
 			this.MaxTreeId = 0;
@@ -71,14 +71,14 @@ namespace Modules.BehaviorTreeModule
 			AllTreeData allTreeData = new AllTreeData();
 			foreach (TreeViewModel value in this.treeViewModelsDict.Values)
 			{
-				List<TreeNodeData> list = value.GetDatas();
+				List<TreeNodeData> list = value.GetDatas();//
 				allTreeData.TreeNodeDatas.AddRange(list);
 			}
 
-			using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write))
+			using (StreamWriter stream = new StreamWriter(new FileStream(file, FileMode.Create, FileAccess.Write)))
 			{
-				byte[] bytes = ProtobufHelper.ToBytes(allTreeData);
-				stream.Write(bytes, 0, bytes.Length);
+				string content = MongoHelper.ToJson(allTreeData);
+				stream.Write(content);
 			}
 		}
 
@@ -99,7 +99,7 @@ namespace Modules.BehaviorTreeModule
 
 		public TreeViewModel Clone(TreeNodeViewModel treeNodeViewModel)
 		{
-			TreeViewModel treeViewModel = (TreeViewModel) treeNodeViewModel.TreeViewModel.Clone();
+			TreeViewModel treeViewModel = (TreeViewModel)treeNodeViewModel.TreeViewModel.Clone();
 			this.treeViewModelsDict[treeViewModel.TreeId] = treeViewModel;
 			this.rootList.Add(treeViewModel.Root);
 			return treeViewModel;

+ 3 - 45
CSharp/App/Modules/BehaviorTreeModule/NodeType.cs

@@ -8,50 +8,8 @@
 		Weight = 11,
 		True = 12,
 
-		// condition节点 10000开始
-		SelectTarget = 10000,
-		Roll = 10001,
-		Compare = 10002,
-		BulletDistance = 10003,
-		OwnBuff = 10004,
-		FriendDieInDistance = 10005,
-		LessHp = 10007,
-		InGlobalCD = 10008,
-		TargetDie = 100010,
-		TargetDistance = 100011,
-		UnitState = 100012,
-		// 与主角的距离
-		ProtagonistDistance = 100013,
-		OwnEffect = 100014,
-		// 属性比较
-		NumbericCompare = 100015,
-		// 连续受击数
-		ContinuousBeHitted = 100016,
-		// 携带的技能是否匹配前缀
-		HaveSpellWithPrefix = 100017,
-		// 匹配前缀的技能是否在cd中
-		SpellPrefixInCD = 100018,
-		// 开启了跟随模式
-		EnableFollow = 100019,
-		// 方形陷阱选择目标
-		RectTrapSelectTarget = 100020,
-
-		// action节点 20000开始
-		CastSpell = 20000,
-		Chase = 20001,
-		Empty = 20002,
-		Patrol = 20003,
-		Idle = 20004,
-		CastDefaultSpell = 20005,
-		Destroy = 20006,
-		Move = 20007,
-		CloseTarget = 20008,
-		LeaveTarget = 20009,
-		PathPatrol = 20010,
-		CastPrefixSpell = 20011,
-		// 跟随unit
-		FollowUnit = 20012,
-		LookAtTarget = 20013,
-		CastNumSpell = 20014,
+		MoveToTarget = 100,
+		Desdroy = 101,
+		DistanceWithTarget = 102,
 	}
 }

+ 6 - 2
CSharp/App/Modules/BehaviorTreeModule/TreeNodeData.cs

@@ -6,9 +6,9 @@ using Common.Helper;
 namespace Modules.BehaviorTreeModule
 {
 	[DataContract]
-	public class TreeNodeData: ICloneable
+	public class TreeNodeData : ICloneable
 	{
-		private readonly List<int> children = new List<int>();
+		private List<int> children = new List<int>();
 
 		/// <summary>
 		/// 节点唯一Id
@@ -44,6 +44,10 @@ namespace Modules.BehaviorTreeModule
 			{
 				return this.children;
 			}
+			set
+			{
+				this.children = value;
+			}
 		}
 
 		/// <summary>