美文网首页
Unity 队列

Unity 队列

作者: 青鱼谷雨 | 来源:发表于2017-10-13 14:48 被阅读0次
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;
    }
}

相关文章

网友评论

      本文标题:Unity 队列

      本文链接:https://www.haomeiwen.com/subject/hezayxtx.html