美文网首页
Unity 堆栈

Unity 堆栈

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

相关文章

  • Unity 堆栈

  • unity crash in iOS 13.4 system

    unity crash in iOS 13.4 system xcode堆栈: Uncaughtexception...

  • [RS] Unity Crash记录 - 02 TerrainD

    AB包模式下加载Terrain崩溃 1、环境 Unity 2020.3.25f1 2、Android堆栈 3、Un...

  • [RS] Unity Crash记录 - 03

    手机上进入副本闪退 1、环境 Unity 2021.3.4f1 2、Android堆栈 3、原因&解决 用64位的...

  • IsaacSim Unity3D - 工具类

    工具类 本节概述了IsaacSim Unity3D中可用的工具。 地图生成 艾萨克(Isaac)导航堆栈需要2D占...

  • unity保存log堆栈到本地

  • Unity3D堆栈内存

    1:unity内存管理,基本上是自动管理,分为两个:堆内存,栈内存。 2:栈内存:主要存储小而短得数据。主要是一些...

  • XR Plug-in Framework

    Unity 2019.3和更高版本使用新的统一插件框架,该框架可实现多个平台的直接集成。 该技术堆栈由一个API组...

  • Go 堆栈的理解

    在讲Go的堆栈之前,先温习一下堆栈基础知识。 什么是堆栈?在计算机中堆栈的概念分为:数据结构的堆栈和内存分配中堆栈...

  • 三种常见的计算模型

    堆栈机 堆栈机,全称为“堆栈结构机器”,即英文的 “Stack Machine”。基于堆栈机模型实现的计算机,无论...

网友评论

      本文标题:Unity 堆栈

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