UP-Viagg-io/Viagg-io/Assets/Packages/MyBT/BT/NodeList.cs

98 lines
2.4 KiB
C#

//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
//
// Purpose: Part of the My Behaviour Tree Code
//
//=============================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MyBT {
[System.Serializable]
public class NodeList : IEnumerator, IEnumerable {
[SerializeField]
List<Node> array = new List<Node>();
public NodeList(List<Node> nArray) {
for (int i = 0; i < nArray.Count; i++) {
array.Add(nArray[i]);
}
}
public NodeList() { }
public Node this[int param] {
get {
if ((param < array.Count) && (param >= 0))
return array[param];
Debug.LogError($"TaskController.this: invalid index {param.ToString()} in {((array != null) ? array.Count.ToString() : "undefined")}");
return null;
}
set { array[param] = value; }
}
public int Count {
get {
return array.Count;
}
}
public void Add(Node t) {
array.Add(t);
}
int position = -1;
public bool MoveNext() {
position++;
return (position < array.Count);
}
public void Reset() {
position = -1;
}
public void Clear() {
Destroy();
}
public void Destroy() {
array = new List<Node>();
Reset();
}
object IEnumerator.Current {
get {
return Current;
}
}
public Node Current {
get {
try {
return array[position];
}
catch (IndexOutOfRangeException) {
throw new InvalidOperationException();
}
}
}
IEnumerator IEnumerable.GetEnumerator() {
return (IEnumerator)GetEnumerator();
}
public NodeList GetEnumerator() {
return new NodeList(array);
}
public NodeList Copy() {
List<Node> newArray = new List<Node>();
ExtensionMethods.DeepCopy<List<Node>>(array, ref newArray);
return new NodeList(newArray);
}
}
}