Files
Cielonos/Assets/OtherPlugins/Le Tai's Asset/Common/Editor/EditorInternal.cs
SoulliesOfficial f7af60351b 阶段性完成
2025-12-08 05:27:53 -05:00

70 lines
2.1 KiB
C#

using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace LeTai.Common.Editor
{
static class EditorInternal
{
static readonly MethodInfo DO_FLOAT_FIELD_METHOD;
#if UNITY_6000_0_OR_NEWER
static readonly PropertyInfo RECYCLED_EDITOR_PROPERTY;
#else
static readonly FieldInfo RECYCLED_EDITOR_PROPERTY;
#endif
static readonly FieldInfo FLOAT_FIELD_FORMAT_STRING_CONST;
static EditorInternal()
{
var editorGUIType = typeof(EditorGUI);
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Static;
Type[] argumentTypes = {
Assembly.GetAssembly(editorGUIType).GetType("UnityEditor.EditorGUI+RecycledTextEditor"),
typeof(Rect),
typeof(Rect),
typeof(int),
typeof(float),
typeof(string),
typeof(GUIStyle),
typeof(bool)
};
DO_FLOAT_FIELD_METHOD = editorGUIType.GetMethod("DoFloatField", flags, null, argumentTypes, null);
#if UNITY_6000_0_OR_NEWER
RECYCLED_EDITOR_PROPERTY = editorGUIType.GetProperty("s_RecycledEditor", flags);
#else
RECYCLED_EDITOR_PROPERTY = editorGUIType.GetField("s_RecycledEditor", flags);
#endif
FLOAT_FIELD_FORMAT_STRING_CONST = editorGUIType.GetField("kFloatFieldFormatString", flags);
}
internal static float DoFloatFieldInternal(
Rect position,
Rect dragHotZone,
int id,
float value,
string formatString = null,
GUIStyle style = null,
bool draggable = true
)
{
style = style ?? EditorStyles.numberField;
formatString = formatString ?? (string)FLOAT_FIELD_FORMAT_STRING_CONST.GetValue(null);
var editor = RECYCLED_EDITOR_PROPERTY.GetValue(null);
return (float)DO_FLOAT_FIELD_METHOD.Invoke(null, new[] {
editor,
position,
dragHotZone,
id,
value,
formatString,
style,
draggable
});
}
}
}