public void Update() { if (root != null) { root.Run(); // 每帧调用行为树根节点,行为树入口 } }
public override ResultType Execute() { List <int> randomList = GetRandom(nodeChildList.Count); int index = -1; if (lastRunningNode != null) { index = lastRunningNode.NodeIndex; } lastRunningNode = null; ResultType resultType = ResultType.Fail; while ((randomList.Count > 0)) { if (index < 0) { index = randomList[randomList.Count - 1]; randomList.RemoveAt(randomList.Count - 1); } NodeRoot nodeRoot = nodeChildList[index]; index = -1; resultType = nodeRoot.Run(); if (resultType == ResultType.Fail) { continue; } if (resultType == ResultType.Success) { break; } if (resultType == ResultType.Running) { lastRunningNode = nodeRoot; break; } } return(resultType); }