mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
临时提交
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
|
||||
public class Entry : Sequence
|
||||
{
|
||||
public string Serielize(TreeNode node)
|
||||
{
|
||||
string s = UnityEngine.JsonUtility.ToJson(node);
|
||||
if (node is ComponentNode)
|
||||
{
|
||||
ComponentNode cp = node as ComponentNode;
|
||||
int count = cp.childs.Count;
|
||||
if (count > 0)
|
||||
{
|
||||
string c = "\"childs\":[";
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
c += Serielize(cp.childs[i]);
|
||||
if (i < count - 1)
|
||||
{
|
||||
c += ",";
|
||||
}
|
||||
}
|
||||
c += "],";
|
||||
int idx = s.IndexOf("Sid");
|
||||
s = s.Insert(idx - 1, c);
|
||||
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d696c6aad8fd4f343affd37d2d186384
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2974397684917235467, guid: 0000000000000000d000000000000000, type: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
public class MagicQueue : CompositeNode
|
||||
{
|
||||
TreeNode last;
|
||||
public override void Enter(object args)
|
||||
{
|
||||
|
||||
}
|
||||
public override void Exit(object args)
|
||||
{
|
||||
|
||||
}
|
||||
public override TaskResult Tick(double dt, object args = null)
|
||||
{
|
||||
childs.Sort((a, b) => a.x < b.x ? -1 : 1);
|
||||
if (childs.Count == 0)
|
||||
{
|
||||
return TaskResult.Fail;
|
||||
}
|
||||
TreeNode curNode = childs[Index];
|
||||
if (last != curNode)
|
||||
{
|
||||
curNode.Enter(args);
|
||||
}
|
||||
TaskResult result = curNode.Tick(dt, args);
|
||||
last = curNode;
|
||||
curNode.state = result;
|
||||
if (result == TaskResult.Running)
|
||||
{
|
||||
return TaskResult.Running;
|
||||
}
|
||||
if (result == TaskResult.OK)
|
||||
{
|
||||
curNode.Exit(args);
|
||||
Index = (Index + 1) % childs.Count;
|
||||
return TaskResult.OK;
|
||||
}
|
||||
return TaskResult.Fail;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0a3bd4c80e1a724c86971760131c651
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 6519382022992737161, guid: 0000000000000000d000000000000000, type: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
public class MagicRandom : CompositeNode
|
||||
{
|
||||
[OutField]
|
||||
public int[] Power;
|
||||
TreeNode last;
|
||||
public override TaskResult Tick(double dt, object args = null)
|
||||
{
|
||||
if (childs.Count == 0) return TaskResult.Fail;
|
||||
|
||||
childs.Sort((a, b) => a.x < b.x ? -1 : 1);
|
||||
|
||||
if (last == null)
|
||||
{
|
||||
Index = CheckRandom();
|
||||
}
|
||||
if (last != childs[Index])
|
||||
{
|
||||
childs[Index].Enter(args);
|
||||
}
|
||||
TreeNode curNode = childs[Index];
|
||||
TaskResult result = curNode.Tick(dt, args);
|
||||
last = curNode;
|
||||
curNode.state = result;
|
||||
if (result == TaskResult.Running)
|
||||
{
|
||||
return TaskResult.Running;
|
||||
}
|
||||
curNode.Exit(args);
|
||||
Index = CheckRandom();
|
||||
return result;
|
||||
}
|
||||
int CheckRandom()
|
||||
{
|
||||
int sum = 0;
|
||||
int length = Power.Length <= childs.Count ? Power.Length : childs.Count;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
sum += Power[i];
|
||||
}
|
||||
double r = new Random().NextDouble() * sum;
|
||||
int cache = 0;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
cache += Power[i];
|
||||
if (cache > r)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return length - 1;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c8836dec99f8324a859ff3a06b603b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 7174288486110832750, guid: 0000000000000000d000000000000000, type: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,68 @@
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
public class Selector : CompositeNode
|
||||
{
|
||||
public override void Enter(object args)
|
||||
{
|
||||
Index = 0;
|
||||
}
|
||||
private TreeNode last;
|
||||
public override void Add(TreeNode component)
|
||||
{
|
||||
base.Add(component);
|
||||
Index = 0;
|
||||
state = TaskResult.None;
|
||||
}
|
||||
public override TaskResult Tick(double dt, object args = null)
|
||||
{
|
||||
childs.Sort((a, b) => a.x < b.x ? -1 : 1);
|
||||
for (int i = Index; i < childs.Count; i++)
|
||||
{
|
||||
if (last != childs[i])
|
||||
{
|
||||
childs[i].Enter(args);
|
||||
}
|
||||
TaskResult rst = childs[i].Tick(dt, args);
|
||||
childs[i].state = rst;
|
||||
last = childs[i];
|
||||
if (rst == TaskResult.OK)
|
||||
{
|
||||
childs[i].Exit(args);
|
||||
return TaskResult.OK;
|
||||
}
|
||||
else if (rst == TaskResult.Running)
|
||||
{
|
||||
bool cdt = false;
|
||||
int cdtCount = 0;
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
if (childs[j] is ConditionalNode)
|
||||
{
|
||||
cdtCount++;
|
||||
cdt |= (childs[j] as ConditionalNode).Check(dt, args);
|
||||
}
|
||||
}
|
||||
if (cdt && cdtCount > 0)
|
||||
{
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
if (childs[j] is ConditionalNode)
|
||||
{
|
||||
(childs[j] as ConditionalNode).IsConditionOK = false;
|
||||
}
|
||||
}
|
||||
childs[i].Exit(args);
|
||||
return TaskResult.OK;
|
||||
}
|
||||
return TaskResult.Running;
|
||||
}
|
||||
else
|
||||
{
|
||||
childs[i].Exit(args);
|
||||
Index = i + 1;
|
||||
}
|
||||
}
|
||||
return TaskResult.Fail;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc8f80689c7eda542ba6223140cb2ed3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 1206586993520771344, guid: 0000000000000000d000000000000000, type: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,72 @@
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
public class Sequence : CompositeNode
|
||||
{
|
||||
private TreeNode last;
|
||||
|
||||
public override void Enter(object args)
|
||||
{
|
||||
Index = 0;
|
||||
}
|
||||
public override void Add(TreeNode component)
|
||||
{
|
||||
base.Add(component);
|
||||
Index = 0;
|
||||
state = TaskResult.None;
|
||||
}
|
||||
public override TaskResult Tick(double dt, object args = null)
|
||||
{
|
||||
childs.Sort((a, b) => a.x < b.x ? -1 : 1);
|
||||
for (int i = Index; i < childs.Count; i++)
|
||||
{
|
||||
if (last != childs[i])
|
||||
{
|
||||
childs[i].Enter(args);
|
||||
}
|
||||
TaskResult rst = childs[i].Tick(dt, args);
|
||||
childs[i].state = rst;
|
||||
last = childs[i];
|
||||
if (rst == TaskResult.OK || rst == TaskResult.None)
|
||||
{
|
||||
childs[i].Exit(args);
|
||||
Index = i + 1;
|
||||
}
|
||||
else if (rst == TaskResult.Running)
|
||||
{
|
||||
bool cdt = true;
|
||||
int cdtCount = 0;
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
if (childs[j] is ConditionalNode)
|
||||
{
|
||||
cdtCount++;
|
||||
cdt &= (childs[j] as ConditionalNode).Check(dt, args);
|
||||
}
|
||||
}
|
||||
if (cdt && cdtCount > 0)
|
||||
{
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
if (childs[j] is ConditionalNode)
|
||||
{
|
||||
(childs[j] as ConditionalNode).IsConditionOK = false;
|
||||
}
|
||||
}
|
||||
childs[i].Exit(args);
|
||||
Index = i + 1;
|
||||
return TaskResult.OK;
|
||||
}
|
||||
return TaskResult.Running;
|
||||
}
|
||||
else
|
||||
{
|
||||
childs[i].Exit(args);
|
||||
Index = i + 1;
|
||||
return TaskResult.Fail;
|
||||
}
|
||||
}
|
||||
return TaskResult.OK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e339237f68bd0f3409e91f5c2fea38b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: -5487077368411116049, guid: 0000000000000000d000000000000000, type: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user