添加一些快捷用法。
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.UI;
|
using UnityEditor.UI;
|
||||||
|
|
||||||
@@ -6,8 +7,9 @@ using XericUI.OverrideUI;
|
|||||||
namespace XericUIEditor.OverrideUI
|
namespace XericUIEditor.OverrideUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// XericStyleImage 的 Inspector 编辑器——继承 GraphicEditor,
|
/// XericStyleImage 的 Inspector 编辑器——
|
||||||
/// 额外展示颜色、纹理、材质三个 StyleField 和自动刷新开关。
|
/// 仅显示颜色样式字段 + raycastTarget / raycastPadding / maskable。
|
||||||
|
/// 不展示原始 Color/Sprite/Material(被样式表接管)。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CustomEditor(typeof(XericStyleImage), true)]
|
[CustomEditor(typeof(XericStyleImage), true)]
|
||||||
[CanEditMultipleObjects]
|
[CanEditMultipleObjects]
|
||||||
@@ -16,30 +18,71 @@ namespace XericUIEditor.OverrideUI
|
|||||||
private SerializedProperty m_ColorStyleProp;
|
private SerializedProperty m_ColorStyleProp;
|
||||||
private SerializedProperty m_TextureStyleProp;
|
private SerializedProperty m_TextureStyleProp;
|
||||||
private SerializedProperty m_MaterialStyleProp;
|
private SerializedProperty m_MaterialStyleProp;
|
||||||
private SerializedProperty m_AutoRefreshProp;
|
private SerializedProperty m_RaycastTargetProp;
|
||||||
|
private SerializedProperty m_RaycastPaddingProp;
|
||||||
|
private SerializedProperty m_MaskableProp;
|
||||||
|
private SerializedProperty m_ColorProp;
|
||||||
|
|
||||||
|
// 折叠状态
|
||||||
|
private static bool s_ColorFoldout = false;
|
||||||
|
private static bool s_TextureFoldout = false;
|
||||||
|
private static bool s_MaterialFoldout = false;
|
||||||
|
|
||||||
protected override void OnEnable()
|
protected override void OnEnable()
|
||||||
{
|
{
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
|
|
||||||
m_ColorStyleProp = serializedObject.FindProperty("m_ColorStyle");
|
m_ColorStyleProp = serializedObject.FindProperty("m_ColorStyle");
|
||||||
m_TextureStyleProp = serializedObject.FindProperty("m_TextureStyle");
|
m_TextureStyleProp = serializedObject.FindProperty("m_TextureStyle");
|
||||||
m_MaterialStyleProp = serializedObject.FindProperty("m_MaterialStyle");
|
m_MaterialStyleProp = serializedObject.FindProperty("m_MaterialStyle");
|
||||||
m_AutoRefreshProp = serializedObject.FindProperty("m_AutoRefresh");
|
m_RaycastTargetProp = serializedObject.FindProperty("m_RaycastTarget");
|
||||||
|
m_RaycastPaddingProp = serializedObject.FindProperty("m_RaycastPadding");
|
||||||
|
m_MaskableProp = serializedObject.FindProperty("m_Maskable");
|
||||||
|
m_ColorProp = serializedObject.FindProperty("m_Color");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
base.OnInspectorGUI();
|
|
||||||
EditorGUILayout.Space();
|
|
||||||
|
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|
||||||
|
// === 颜色样式(主要展示) ===
|
||||||
EditorGUILayout.LabelField("样式表配置", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("样式表配置", EditorStyles.boldLabel);
|
||||||
EditorGUILayout.PropertyField(m_ColorStyleProp);
|
EditorGUILayout.Space(2);
|
||||||
EditorGUILayout.PropertyField(m_TextureStyleProp);
|
if (m_ColorStyleProp != null)
|
||||||
EditorGUILayout.PropertyField(m_MaterialStyleProp);
|
EditorGUILayout.PropertyField(m_ColorStyleProp, new GUIContent("颜色样式"));
|
||||||
EditorGUILayout.PropertyField(m_AutoRefreshProp);
|
|
||||||
|
// 纹理和材质样式折叠(通常不需要改动)
|
||||||
|
s_TextureFoldout = EditorGUILayout.Foldout(s_TextureFoldout, "纹理 / 材质样式(高级)", true);
|
||||||
|
if (s_TextureFoldout)
|
||||||
|
{
|
||||||
|
EditorGUI.indentLevel++;
|
||||||
|
if (m_TextureStyleProp != null)
|
||||||
|
EditorGUILayout.PropertyField(m_TextureStyleProp, new GUIContent("纹理样式"));
|
||||||
|
if (m_MaterialStyleProp != null)
|
||||||
|
EditorGUILayout.PropertyField(m_MaterialStyleProp, new GUIContent("材质样式"));
|
||||||
|
EditorGUI.indentLevel--;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.Space(8);
|
||||||
|
|
||||||
|
// === 颜色预览(只读) ===
|
||||||
|
if (m_ColorProp != null)
|
||||||
|
{
|
||||||
|
EditorGUI.BeginDisabledGroup(true);
|
||||||
|
EditorGUILayout.PropertyField(m_ColorProp, new GUIContent("颜色(预览)"));
|
||||||
|
EditorGUI.EndDisabledGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.Space(4);
|
||||||
|
|
||||||
|
// === Raycast 与 Mask ===
|
||||||
|
EditorGUILayout.LabelField("交互", EditorStyles.boldLabel);
|
||||||
|
if (m_RaycastTargetProp != null)
|
||||||
|
EditorGUILayout.PropertyField(m_RaycastTargetProp, new GUIContent("Raycast Target"));
|
||||||
|
if (m_RaycastPaddingProp != null)
|
||||||
|
EditorGUILayout.PropertyField(m_RaycastPaddingProp, new GUIContent("Raycast Padding"));
|
||||||
|
if (m_MaskableProp != null)
|
||||||
|
EditorGUILayout.PropertyField(m_MaskableProp, new GUIContent("Maskable"));
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ namespace XericUIEditor
|
|||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||||
{
|
{
|
||||||
|
var nsProp = property.FindPropertyRelative("Namespace");
|
||||||
|
var pathProp = property.FindPropertyRelative("StylePath");
|
||||||
|
if (nsProp == null || pathProp == null)
|
||||||
|
return LINE_HEIGHT + PADDING * 2;
|
||||||
|
|
||||||
string key = GetFoldKey(property);
|
string key = GetFoldKey(property);
|
||||||
bool expanded = s_FoldoutStates.TryGetValue(key, out bool f) && f;
|
bool expanded = s_FoldoutStates.TryGetValue(key, out bool f) && f;
|
||||||
|
|
||||||
@@ -37,7 +42,7 @@ namespace XericUIEditor
|
|||||||
|
|
||||||
// 有值才显示值类型行
|
// 有值才显示值类型行
|
||||||
string ns = GetNamespace(property);
|
string ns = GetNamespace(property);
|
||||||
string path = property.FindPropertyRelative("StylePath").stringValue;
|
string path = pathProp.stringValue;
|
||||||
StyleValue val = StyleManager.GetValue(ns, path);
|
StyleValue val = StyleManager.GetValue(ns, path);
|
||||||
if (val != null && val.ValueType != null)
|
if (val != null && val.ValueType != null)
|
||||||
rowCount++;
|
rowCount++;
|
||||||
@@ -59,6 +64,12 @@ namespace XericUIEditor
|
|||||||
SerializedProperty nsProp = property.FindPropertyRelative("Namespace");
|
SerializedProperty nsProp = property.FindPropertyRelative("Namespace");
|
||||||
SerializedProperty pathProp = property.FindPropertyRelative("StylePath");
|
SerializedProperty pathProp = property.FindPropertyRelative("StylePath");
|
||||||
|
|
||||||
|
if (nsProp == null || pathProp == null)
|
||||||
|
{
|
||||||
|
EditorGUI.LabelField(position, label, "(StyleField 未初始化)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// === 标题行:折叠箭头 + 标签 + 路径下拉 ===
|
// === 标题行:折叠箭头 + 标签 + 路径下拉 ===
|
||||||
Rect headerRect = new Rect(position.x, position.y + PADDING, position.width, LINE_HEIGHT);
|
Rect headerRect = new Rect(position.x, position.y + PADDING, position.width, LINE_HEIGHT);
|
||||||
|
|
||||||
@@ -213,7 +224,8 @@ namespace XericUIEditor
|
|||||||
|
|
||||||
private static string GetNamespace(SerializedProperty property)
|
private static string GetNamespace(SerializedProperty property)
|
||||||
{
|
{
|
||||||
string ns = property.FindPropertyRelative("Namespace").stringValue;
|
var nsProp = property.FindPropertyRelative("Namespace");
|
||||||
|
string ns = nsProp?.stringValue;
|
||||||
return string.IsNullOrEmpty(ns) ? "default" : ns;
|
return string.IsNullOrEmpty(ns) ? "default" : ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ namespace XericUI.XTable.Rendering.Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XTableCellData this[int row, int col] => TableData.GetOrCreateCell(row, col);
|
||||||
|
|
||||||
public float[] RowHeights => m_RowHeights;
|
public float[] RowHeights => m_RowHeights;
|
||||||
public float[] ColWidths => m_ColWidths;
|
public float[] ColWidths => m_ColWidths;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user