版本: Unity 6 (6000.0)
语言英语
  • C#

SerializedProperty.numericType

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们会阅读用户提出的每个建议更改,并在必要时进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请 <a>稍后重试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

public SerializedPropertyNumericType numericType;

描述

返回整数和浮点属性的精确类型。(只读)

The propertyType 属性将所有支持的整数类型归类为 SerializedPropertyType.Integer,并将单精度和双精度浮点类型归类为 SerializedPropertyType.Float。此属性公开了精确类型,例如 SerializedPropertyNumericType.UInt8SerializedPropertyNumericType.Double,比使用基于字符串的 type 属性更有效。对于枚举属性 (SerializedPropertyType.Enum),它返回基础类型。对于非数值类型,它返回 SerializedPropertyNumericType.Unknown

using System;
using System.Text;
using UnityEditor;
using UnityEngine;

public class NumericTypeExample : ScriptableObject { public byte m_byte; public int m_int; public long m_long; public float m_float; public double m_double;

[Flags] public enum UIntFlags : uint { None = 0, Flag31 = 1 << 30, Flag32 = 1u << 31, } public UIntFlags m_uintFlags; public string m_string;

[MenuItem("Example/SerializedProperty NumericType API")] static void TestMethod() { // This example demonstrates how numericType exposes more precise details of the type NumericTypeExample obj = ScriptableObject.CreateInstance<NumericTypeExample>(); SerializedObject serializedObject = new SerializedObject(obj);

var serializedProperty = serializedObject.FindProperty("m_byte"); var sb = new StringBuilder(); do { sb.AppendLine(String.Format("Name: {0,-11} propertyType: {1,-7} numericType: {2}", serializedProperty.name, serializedProperty.propertyType, serializedProperty.numericType)); } while (serializedProperty.Next(false));

//Expected output: //Name: m_byte propertyType: Integer numericType: UInt8 //Name: m_int propertyType: Integer numericType: Int32 //Name: m_long propertyType: Integer numericType: Int64 //Name: m_float propertyType: Float numericType: Float //Name: m_double propertyType: Float numericType: Double //Name: m_uintFlags propertyType: Enum numericType: UInt32 //Name: m_string propertyType: String numericType: Unknown Debug.Log(sb.ToString()); } }