using UnityEngine;
using System.Collections;
//堆栈
public class TestStack : MonoBehaviour {
public delegate void DeleStackHandle(object senter,QueueEventArgs e);
public event DeleStackHandle EventStack;
Stack st;
Stack St
{
get
{
return st;
}
set
{
st = value;
}
}
void OnStackEvent(object sent,QueueEventArgs e)
{
if(e.count>0)
{
Debug.Log("堆栈中的数量不为空:" + e.count);
}
else
{
Debug.Log("堆栈中的元素为空");
}
}
void Start()
{
st = new Stack();
EventStack += new DeleStackHandle(OnStackEvent);
st.Push(1);
st.Push(2);
st.Push(3);
}
void OnListentEventStack(int count,string con)
{
if(EventStack!=null)
{
EventStack(this, new QueueEventArgs(count, con));
}
}
void OnGUI()
{
if(GUI.Button(new Rect(300,300,100,100),"显示堆栈"))
{
Debug.Log("显示堆栈中的元素");
ShowSt();
OnListentEventStack(st.Count, st.ToString());
}
if (GUI.Button(new Rect(400, 300, 100, 100), "删除堆栈"))
{
Debug.Log("删除堆栈中的元素");
PopSt();
OnListentEventStack(st.Count, st.ToString());
}
}
//显示堆栈
void ShowSt()
{
foreach(var temp in st)
{
Debug.Log(temp);
}
}
void PopSt()
{
st.Pop();
}
}
public class QueueEventArgs : MonoBehaviour {
public int count;
public string context;
public QueueEventArgs(int cou,string con)
{
count = cou;
context = con;
}
}