堆栈(Stack):
代表了一个后进先出的对象集合。当向堆栈列表中添加一项,称为推入元素。当从堆栈列表中移除一项时,称为弹出元素。
堆栈使用方法如下:
Stack<GameObject> objs = new Stack<GameObject>();
objs.Clear(); //移除 堆栈objs 所有元素
bool isCon = objs.Contains(gameObject); //判断 堆栈objs 里是否包含此元素
GameObject obj_00 = objs.Peek(); //返回在 堆栈objs 顶部的物体。(不移除)
GameObject obj_01 = objs.Pop(); //移除并返回在 堆栈objs 的顶部的对象。
objs.Push(gameObject); //向 堆栈objs 的顶部添加一个对象。
object[] newArray = objs.ToArray(); //复制 堆栈objs 到一个新的数组中。