当前位置:网站首页>Unity中队列(Queue)的简单使用
Unity中队列(Queue)的简单使用
2022-07-28 06:33:00 【dzj2021】
queue----队列:容器,像一个单向的隧道,从一端(尾部)进入,
从另一端(头部)出去,先进的先出,类似高速公路上的车流通过一个隧道。
重要的操作:
- 入队——Enqueue():加入队列,进入隧道
- 出队——Dequeue():从队列中弃除,从隧道钻出
其它操作请参考API:
- First()——队列里最先入队的item,位于头部
- Last()——队列里最后入队的item,位于尾部
案例:
#if UNITY_EDITOR
[ContextMenu("测试队列First()和Last()")]
#endif
void TestQueue()
{
/************************************************************************ * * queue----队列:容器,像一个单向的隧道,从一端(尾部)进入, * 从另一端(头部)出去,先进的先出,类似高速公路上的车流通过一个隧道。 * 重要的操作: * 入队——Enqueue():加入队列,进入隧道 * 出队——Dequeue():从队列中弃除,从隧道钻出 * * 其它操作请参考API: * First()——队列里最先入队的item,位于头部 * Last()——队列里最后入队的item,位于尾部 * ************************************************************************/
//int队列
Queue<int> myquene = new Queue<int>();
//添加一个item
myquene.Enqueue(1);
Debug.Log($"入队添加了一个元素1,count = {
myquene.Count}");
//再添加一个item
myquene.Enqueue(2);
Debug.Log($"入队添加了一个元素2,count = {
myquene.Count}");
//再添加一个item
myquene.Enqueue(3);
Debug.Log($"入队添加了一个元素3,count = {
myquene.Count}");
//查看first和last的item
Debug.Log($"first item is = {
myquene.First()}");
Debug.Log($"last item is = {
myquene.Last()}");
//【出队】一个item
var t = myquene.Dequeue();
Debug.Log($"出队删除一个item:{
t} ,count = {
myquene.Count}");
//查看first和last的item
Debug.Log($"first item is = {
myquene.First()}");
Debug.Log($"last item is = {
myquene.Last()}");
}
输出:
入队添加了一个元素1,count = 1
入队添加了一个元素2,count = 2
入队添加了一个元素3,count = 3
first item is = 1
last item is = 3
出队删除一个item:1 ,count = 2
first item is = 2
last item is = 3
边栏推荐
- [environment configuration] ppyoole trains its own data set (for its own use)
- Swm32 series tutorial 5-adc application
- js卡通英文字母打字小游戏源码
- CarSim simulation quick start (XIII) - steering system
- Mechanical revolution Jiaolong P wired network card driver can't play
- Understand CDN
- Discrimination coverage index / index coverage / Samsung index
- 【活动报名】云原生技术交流 Meetup,8 月 6 日广州见
- 豪华版h5俄罗斯方块小游戏源码
- The core packages and middleware required for golang development cover all areas of the project and are worth collecting
猜你喜欢

Understanding of spark operator aggregatebykey

MPLS -- multi protocol label switching technology

Meituan Er Mian: why does redis have sentinels?

"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary question record (dghjkl)
![MySQL query error [err] 1046 - no database selected](/img/32/7d877571397c1e2024ec488b783e87.png)
MySQL query error [err] 1046 - no database selected

EMC EMI磁珠的特性

Solve the inherent defects of CNN! Common CNN architecture ccnn is coming | icml2022

XSS knowledge points and 20 character short domain name bypass
![Chapter 01 introduction of [notes of Huashu]](/img/11/cc405a730822305f02f05678f6a9d1.png)
Chapter 01 introduction of [notes of Huashu]

OSPF comprehensive experiment (7.12)
随机推荐
金属质感登录框样式
Deluxe H5 Tetris game source code
Autodesk desktop licensing service error 1067 handling method
Recommend a fully open source, feature rich, beautiful interface mall system
uniapp上下滑屏切换支持视频和图片轮播实现,类似抖音效果
The core packages and middleware required for golang development cover all areas of the project and are worth collecting
Can a flinksql script write insert statements for two tables?
Common solutions for distributed ID - take one
Prescan quick start to master the transportation elements in lesson 14, prescan
Mechanical revolution Jiaolong P wired network card driver can't play
Exception handling in SQL Server
记录一次mycat连接Communications link failure问题解决
PostgreSQL is the world's most advanced open source relational database
Mysql, how many columns can be used to create an index?
Prescan quick start to proficient in lecture 17, speed curve editor
Talk about row storage and column storage of database
MPLS -- multi protocol label switching technology
JS candy xiaoxiaole game source code
protobuf 基本语法总结
MySQL query error [err] 1046 - no database selected