using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TestQueut : MonoBehaviour {
Queue<int> firstQueue;
Queue<int> FirstQueue
{
get
{
return firstQueue;
}
set
{
firstQueue = value;
}
}
public delegate void QueueEventHandler(object sender, QueueEventArgs e);
public event QueueEventHandler QueueEvent;
void Start()
{
firstQueue = new Queue<int>();
QueueEvent += new QueueEventHandler(OnQueueEvent);
}
void OnQueueEvent(object sender, QueueEventArgs e)
{
if(e.count>0)
{
Debug.Log("队列不等于0:" + e.count);
}
else
{
Debug.Log("队列为空");
}
}
void AddListentEventQueue(int count,string context)
{
if (QueueEvent!=null)
{
QueueEvent(this,new QueueEventArgs(count, context));
}
}
void OnGUI()
{
if(GUI.Button(new Rect(100,100,100,100),"显示队列"))
{
Debug.Log("显示队列");
ShowQueuw();
AddListentEventQueue(FirstQueue.Count, FirstQueue.ToString());
}
if(GUI.Button(new Rect(200,100,100,100),"设置队列"))
{
Debug.Log("设置队列");
SetQueue();
AddListentEventQueue(FirstQueue.Count, FirstQueue.ToString());
}
if(GUI.Button(new Rect(300,100,100,100),"删除队列"))
{
Debug.Log("删除队列");
FirstQueue.Dequeue();
AddListentEventQueue(FirstQueue.Count, FirstQueue.ToString());
}
}
void SetQueue()
{
FirstQueue.Enqueue(1);
FirstQueue.Enqueue(2);
FirstQueue.Enqueue(3);
FirstQueue.Enqueue(4);
}
void ShowQueuw()
{
foreach (var temp in FirstQueue)
{
Debug.Log(temp);
}
}
}
public class QueueEventArgs : MonoBehaviour {
public int count;
public string context;
public QueueEventArgs(int cou,string con)
{
count = cou;
context = con;
}
}
网友评论