mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|