Unity获取Inspector面板上的Rotation旋转值

UI和物体通用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;
public class UIRotate : MonoBehaviour {
    void Start()
    {
        System.Type transformType = transform.GetType();
        PropertyInfo m_propertyInfo_rotationOrder = transformType.GetProperty("rotationOrder", BindingFlags.Instance | BindingFlags.NonPublic);
        object m_OldRotationOrder = m_propertyInfo_rotationOrder.GetValue(transform, null);
        MethodInfo m_methodInfo_GetLocalEulerAngles = transformType.GetMethod("GetLocalEulerAngles", BindingFlags.Instance | BindingFlags.NonPublic);
        object value = m_methodInfo_GetLocalEulerAngles.Invoke(transform, new object[] { m_OldRotationOrder });
        //获取的真实值
        Debug.LogError("反射调用GetLocalEulerAngles方法获得的值:" + value.ToString());
        Debug.LogError("transform.localEulerAngles获取的值:" + transform.localEulerAngles.ToString());
    }
}

你可能感兴趣的:(Unity获取Inspector面板上的Rotation旋转值)