C#遍历枚举

来源:互联网 发布:女性脱发知乎 编辑:程序博客网 时间:2024/06/07 18:30
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class TestKey : MonoBehaviour {
    public TextMesh t;
// Use this for initialization
void Start () {
        t = this.GetComponent<TextMesh>();
}

// Update is called once per frame
void Update () {
        if (Input.GetKey(KeyCode.A))
        {
            ergodicEnum1();
        }
}


    private void ergodicEnum1()
    {


        foreach (KeyCode suit in Enum.GetValues(typeof(KeyCode)))
        {
            Debug.Log((int)suit + ":" + suit);
           
        }
    }

}





using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class TestKey : MonoBehaviour {
    public TextMesh t;
// Use this for initialization
void Start () {
        t = this.GetComponent<TextMesh>();
}

// Update is called once per frame
void Update () {
        //if (Input.GetKey(KeyCode.A))
        //{
            ergodicEnum1();
        //}
}


    private void ergodicEnum1()
    {


        foreach (KeyCode suit in Enum.GetValues(typeof(KeyCode)))
        {
            
            if (Input.GetKeyDown(suit))
            {
                Debug.Log((int)suit + ":" + suit);
                t.text = (int)suit + ":" + suit;
            }
        }


    }
}