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

public class Test01 : MonoBehaviour {

    void Start ()
    {
        FieldInfo[] array =  GetComponent<Test01>().GetType().GetFields();
        foreach (var item in array)
        {
            print("字段名称:" + item);
        }
    }

    [DataStoreSave]
    public string str = "abc";
    [DataStoreSave]
    public int i = 5;
    [DataStoreSave]
    public bool b = true;
    [DataStoreSave]
    public Vector3 V3 = new Vector3(4, 5, 6);
}

结果如下图:

C# 反射 Type.GetFields 方法

 

Type.GetFields

返回当前 Type 的所有公共字段。

注意要引用命名空间:using System.Reflection;

 

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2021-12-10
  • 2021-07-27
  • 2018-08-15
  • 2022-02-07
  • 2021-06-18
  • 2022-02-09
猜你喜欢
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案