修复stylefield显示为红色字段的问题。
This commit is contained in:
@@ -24,9 +24,7 @@ namespace XericUIEditor.OverrideUI
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -1,247 +1,248 @@
|
||||
using UnityEditor;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.SuperStyleSheet;
|
||||
|
||||
namespace XericUIEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// StyleField 的自定义 Inspector 属性绘制器。
|
||||
///
|
||||
/// 默认折叠状态:仅显示样式路径下拉框。
|
||||
/// 展开状态:显示命名空间、路径、资源值类型(有值时)、注解描述(有注解时)。
|
||||
/// 无值/无注解的行不显示。
|
||||
/// </summary>
|
||||
[CustomPropertyDrawer(typeof(StyleField))]
|
||||
public class StyleFieldDrawer : PropertyDrawer
|
||||
{
|
||||
private const float LINE_HEIGHT = 18f;
|
||||
private const float PADDING = 2f;
|
||||
private const float FOLD_BUTTON_WIDTH = 14f;
|
||||
/// <summary>
|
||||
/// StyleField 的自定义 Inspector 属性绘制器。
|
||||
///
|
||||
/// 默认折叠状态:仅显示样式路径下拉框。
|
||||
/// 展开状态:显示命名空间、路径、资源值类型(有值时)、注解描述(有注解时)。
|
||||
/// 无值/无注解的行不显示。
|
||||
/// </summary>
|
||||
[CustomPropertyDrawer(typeof(StyleField))]
|
||||
public class StyleFieldDrawer : PropertyDrawer
|
||||
{
|
||||
private const float LINE_HEIGHT = 18f;
|
||||
private const float PADDING = 2f;
|
||||
private const float FOLD_BUTTON_WIDTH = 14f;
|
||||
|
||||
/// <summary>折叠状态(按 property path 缓存)</summary>
|
||||
private static readonly System.Collections.Generic.Dictionary<string, bool> s_FoldoutStates
|
||||
= new System.Collections.Generic.Dictionary<string, bool>();
|
||||
private const string PROP_NAMESPACE = "_namespace";
|
||||
private const string PROP_STYLEPATH = "_stylePath";
|
||||
|
||||
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;
|
||||
/// <summary>折叠状态(按 property path 缓存)</summary>
|
||||
private static readonly System.Collections.Generic.Dictionary<string, bool> s_FoldoutStates
|
||||
= new System.Collections.Generic.Dictionary<string, bool>();
|
||||
|
||||
string key = GetFoldKey(property);
|
||||
bool expanded = s_FoldoutStates.TryGetValue(key, out bool f) && f;
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var nsProp = property.FindPropertyRelative(PROP_NAMESPACE);
|
||||
var pathProp = property.FindPropertyRelative(PROP_STYLEPATH);
|
||||
if (nsProp == null || pathProp == null)
|
||||
return LINE_HEIGHT + PADDING * 2;
|
||||
|
||||
if (!expanded)
|
||||
return LINE_HEIGHT + PADDING * 2;
|
||||
string key = GetFoldKey(property);
|
||||
bool expanded = s_FoldoutStates.TryGetValue(key, out bool f) && f;
|
||||
|
||||
// 基础:命名空间 + 路径 = 2 行
|
||||
int rowCount = 2;
|
||||
if (!expanded)
|
||||
return LINE_HEIGHT + PADDING * 2;
|
||||
|
||||
// 有值才显示值类型行
|
||||
string ns = GetNamespace(property);
|
||||
string path = pathProp.stringValue;
|
||||
StyleValue val = StyleManager.GetValue(ns, path);
|
||||
if (val != null && val.ValueType != null)
|
||||
rowCount++;
|
||||
// 基础:命名空间 + 路径 = 2 行
|
||||
int rowCount = 2;
|
||||
|
||||
// 有注解才显示注解行
|
||||
var annotations = StyleManager.GetAnnotations(ns, path);
|
||||
if (annotations != null && annotations.Count > 0)
|
||||
rowCount++;
|
||||
// 有值才显示值类型行
|
||||
string ns = GetNamespace(property);
|
||||
string path = pathProp.stringValue;
|
||||
StyleValue val = StyleManager.GetValue(ns, path);
|
||||
if (val != null && val.ValueType != null)
|
||||
rowCount++;
|
||||
|
||||
return (LINE_HEIGHT + PADDING) * rowCount + PADDING;
|
||||
}
|
||||
// 有注解才显示注解行
|
||||
var annotations = StyleManager.GetAnnotations(ns, path);
|
||||
if (annotations != null && annotations.Count > 0)
|
||||
rowCount++;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
string key = GetFoldKey(property);
|
||||
bool expanded = s_FoldoutStates.TryGetValue(key, out bool fold) && fold;
|
||||
return (LINE_HEIGHT + PADDING) * rowCount + PADDING;
|
||||
}
|
||||
|
||||
// 获取子属性
|
||||
SerializedProperty nsProp = property.FindPropertyRelative("Namespace");
|
||||
SerializedProperty pathProp = property.FindPropertyRelative("StylePath");
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
string key = GetFoldKey(property);
|
||||
bool expanded = s_FoldoutStates.TryGetValue(key, out bool fold) && fold;
|
||||
|
||||
if (nsProp == null || pathProp == null)
|
||||
{
|
||||
EditorGUI.LabelField(position, label, "(StyleField 未初始化)");
|
||||
return;
|
||||
}
|
||||
// 获取子属性
|
||||
SerializedProperty nsProp = property.FindPropertyRelative(PROP_NAMESPACE);
|
||||
SerializedProperty pathProp = property.FindPropertyRelative(PROP_STYLEPATH);
|
||||
|
||||
// === 标题行:折叠箭头 + 标签 + 路径下拉 ===
|
||||
Rect headerRect = new Rect(position.x, position.y + PADDING, position.width, LINE_HEIGHT);
|
||||
if (nsProp == null || pathProp == null)
|
||||
{
|
||||
EditorGUI.LabelField(position, label != null ? label.text : "Style Field", " (未初始化)");
|
||||
return;
|
||||
}
|
||||
|
||||
// 折叠按钮
|
||||
Rect foldRect = new Rect(headerRect.x, headerRect.y, FOLD_BUTTON_WIDTH, LINE_HEIGHT);
|
||||
bool newFold = EditorGUI.Foldout(foldRect, expanded, GUIContent.none, true);
|
||||
if (newFold != expanded)
|
||||
{
|
||||
s_FoldoutStates[key] = newFold;
|
||||
expanded = newFold;
|
||||
}
|
||||
// === 标题行:折叠箭头 + 标签 + 路径下拉 ===
|
||||
Rect headerRect = new Rect(position.x, position.y + PADDING, position.width, LINE_HEIGHT);
|
||||
|
||||
// 标签
|
||||
Rect labelRect = new Rect(headerRect.x + FOLD_BUTTON_WIDTH, headerRect.y,
|
||||
EditorGUIUtility.labelWidth - FOLD_BUTTON_WIDTH, LINE_HEIGHT);
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
// 折叠按钮
|
||||
Rect foldRect = new Rect(headerRect.x, headerRect.y, FOLD_BUTTON_WIDTH, LINE_HEIGHT);
|
||||
bool newFold = EditorGUI.Foldout(foldRect, expanded, GUIContent.none, true);
|
||||
if (newFold != expanded)
|
||||
{
|
||||
s_FoldoutStates[key] = newFold;
|
||||
expanded = newFold;
|
||||
}
|
||||
|
||||
// 路径下拉框(始终可见)
|
||||
Rect pathRect = new Rect(headerRect.x + EditorGUIUtility.labelWidth + 4f, headerRect.y,
|
||||
headerRect.width - EditorGUIUtility.labelWidth - 8f, LINE_HEIGHT);
|
||||
// 标签
|
||||
Rect labelRect = new Rect(headerRect.x + FOLD_BUTTON_WIDTH, headerRect.y,
|
||||
EditorGUIUtility.labelWidth - FOLD_BUTTON_WIDTH, LINE_HEIGHT);
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
|
||||
string currentNs = GetNamespace(property);
|
||||
// 路径下拉框(始终可见)
|
||||
Rect pathRect = new Rect(headerRect.x + EditorGUIUtility.labelWidth + 4f, headerRect.y,
|
||||
headerRect.width - EditorGUIUtility.labelWidth - 8f, LINE_HEIGHT);
|
||||
|
||||
DrawPathDropdown(pathRect, pathProp, currentNs);
|
||||
string currentNs = GetNamespace(property);
|
||||
|
||||
if (!expanded)
|
||||
return;
|
||||
DrawPathDropdown(pathRect, pathProp, currentNs);
|
||||
|
||||
// === 展开区域 ===
|
||||
float y = headerRect.y + LINE_HEIGHT + PADDING;
|
||||
float indent = 16f;
|
||||
float fieldWidth = position.width - indent;
|
||||
if (!expanded)
|
||||
return;
|
||||
|
||||
// --- 命名空间 ---
|
||||
Rect nsLabelRect = new Rect(position.x + indent, y, 60f, LINE_HEIGHT);
|
||||
Rect nsFieldRect = new Rect(position.x + indent + 64f, y, fieldWidth - 64f, LINE_HEIGHT);
|
||||
EditorGUI.LabelField(nsLabelRect, "命名空间");
|
||||
DrawNamespaceDropdown(nsFieldRect, nsProp);
|
||||
y += LINE_HEIGHT + PADDING;
|
||||
// === 展开区域 ===
|
||||
float y = headerRect.y + LINE_HEIGHT + PADDING;
|
||||
float indent = 16f;
|
||||
float fieldWidth = position.width - indent;
|
||||
|
||||
// --- 路径 ---
|
||||
Rect pathLabelRect = new Rect(position.x + indent, y, 60f, LINE_HEIGHT);
|
||||
Rect pathFieldRect = new Rect(position.x + indent + 64f, y, fieldWidth - 64f, LINE_HEIGHT);
|
||||
EditorGUI.LabelField(pathLabelRect, "路径");
|
||||
DrawPathDropdown(pathFieldRect, pathProp, currentNs);
|
||||
y += LINE_HEIGHT + PADDING;
|
||||
// --- 命名空间 ---
|
||||
Rect nsLabelRect = new Rect(position.x + indent, y, 60f, LINE_HEIGHT);
|
||||
Rect nsFieldRect = new Rect(position.x + indent + 64f, y, fieldWidth - 64f, LINE_HEIGHT);
|
||||
EditorGUI.LabelField(nsLabelRect, "命名空间");
|
||||
DrawNamespaceDropdown(nsFieldRect, nsProp);
|
||||
y += LINE_HEIGHT + PADDING;
|
||||
|
||||
// --- 资源值类型(仅在有值时显示) ---
|
||||
StyleValue currentValue = StyleManager.GetValue(currentNs, pathProp.stringValue);
|
||||
if (currentValue != null && currentValue.ValueType != null)
|
||||
{
|
||||
Rect valLabelRect = new Rect(position.x + indent, y, 80f, LINE_HEIGHT);
|
||||
Rect valFieldRect = new Rect(position.x + indent + 84f, y, fieldWidth - 84f, LINE_HEIGHT);
|
||||
// --- 路径 ---
|
||||
Rect pathLabelRect = new Rect(position.x + indent, y, 60f, LINE_HEIGHT);
|
||||
Rect pathFieldRect = new Rect(position.x + indent + 64f, y, fieldWidth - 64f, LINE_HEIGHT);
|
||||
EditorGUI.LabelField(pathLabelRect, "路径");
|
||||
DrawPathDropdown(pathFieldRect, pathProp, currentNs);
|
||||
y += LINE_HEIGHT + PADDING;
|
||||
|
||||
EditorGUI.LabelField(valLabelRect, "值类型");
|
||||
// --- 资源值类型(仅在有值时显示) ---
|
||||
StyleValue currentValue = StyleManager.GetValue(currentNs, pathProp.stringValue);
|
||||
if (currentValue != null && currentValue.ValueType != null)
|
||||
{
|
||||
Rect valLabelRect = new Rect(position.x + indent, y, 80f, LINE_HEIGHT);
|
||||
Rect valFieldRect = new Rect(position.x + indent + 84f, y, fieldWidth - 84f, LINE_HEIGHT);
|
||||
|
||||
string typeDisplay = GetShortTypeName(currentValue.ValueType);
|
||||
string valuePreview = currentValue.RawValue != null
|
||||
? currentValue.RawValue.ToString()
|
||||
: "";
|
||||
EditorGUI.LabelField(valLabelRect, "值类型");
|
||||
|
||||
EditorGUI.LabelField(valFieldRect, $"{typeDisplay} = {valuePreview}");
|
||||
y += LINE_HEIGHT + PADDING;
|
||||
}
|
||||
string typeDisplay = GetShortTypeName(currentValue.ValueType);
|
||||
string valuePreview = currentValue.RawValue != null
|
||||
? currentValue.RawValue.ToString()
|
||||
: "";
|
||||
|
||||
// --- 注解描述(仅在有注解时显示) ---
|
||||
var annotations = StyleManager.GetAnnotations(currentNs, pathProp.stringValue);
|
||||
if (annotations != null && annotations.Count > 0)
|
||||
{
|
||||
Rect annoLabelRect = new Rect(position.x + indent, y, 80f, LINE_HEIGHT);
|
||||
Rect annoFieldRect = new Rect(position.x + indent + 84f, y, fieldWidth - 84f, LINE_HEIGHT);
|
||||
EditorGUI.LabelField(valFieldRect, $"{typeDisplay} = {valuePreview}");
|
||||
y += LINE_HEIGHT + PADDING;
|
||||
}
|
||||
|
||||
EditorGUI.LabelField(annoLabelRect, "注解");
|
||||
// --- 注解描述(仅在有注解时显示) ---
|
||||
var annotations = StyleManager.GetAnnotations(currentNs, pathProp.stringValue);
|
||||
if (annotations != null && annotations.Count > 0)
|
||||
{
|
||||
Rect annoLabelRect = new Rect(position.x + indent, y, 80f, LINE_HEIGHT);
|
||||
Rect annoFieldRect = new Rect(position.x + indent + 84f, y, fieldWidth - 84f, LINE_HEIGHT);
|
||||
|
||||
// 优先显示 @Desc
|
||||
annotations.TryGetValue("Desc", out string desc);
|
||||
if (!string.IsNullOrEmpty(desc))
|
||||
EditorGUI.LabelField(annoFieldRect, desc);
|
||||
else
|
||||
{
|
||||
foreach (var a in annotations)
|
||||
{
|
||||
EditorGUI.LabelField(annoFieldRect, $"@{a.Key}: {a.Value}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUI.LabelField(annoLabelRect, "注解");
|
||||
|
||||
// 变更检测
|
||||
if (GUI.changed)
|
||||
{
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
// 优先显示 @Desc
|
||||
annotations.TryGetValue("Desc", out string desc);
|
||||
if (!string.IsNullOrEmpty(desc))
|
||||
EditorGUI.LabelField(annoFieldRect, desc);
|
||||
else
|
||||
{
|
||||
foreach (var a in annotations)
|
||||
{
|
||||
EditorGUI.LabelField(annoFieldRect, $"@{a.Key}: {a.Value}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 下拉框绘制
|
||||
// 变更检测
|
||||
if (GUI.changed)
|
||||
{
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawNamespaceDropdown(Rect rect, SerializedProperty nsProp)
|
||||
{
|
||||
var namespaces = StyleManager.GetAvailableNamespaces();
|
||||
if (namespaces.Count == 0)
|
||||
namespaces.Add("default");
|
||||
#region 下拉框绘制
|
||||
|
||||
int currentIndex = namespaces.IndexOf(nsProp.stringValue);
|
||||
if (currentIndex < 0) currentIndex = 0;
|
||||
private void DrawNamespaceDropdown(Rect rect, SerializedProperty nsProp)
|
||||
{
|
||||
var namespaces = StyleManager.GetAvailableNamespaces();
|
||||
if (namespaces.Count == 0)
|
||||
namespaces.Add("default");
|
||||
|
||||
int newIndex = EditorGUI.Popup(rect, currentIndex, namespaces.ToArray());
|
||||
if (newIndex >= 0 && newIndex < namespaces.Count)
|
||||
{
|
||||
nsProp.stringValue = namespaces[newIndex];
|
||||
}
|
||||
}
|
||||
int currentIndex = namespaces.IndexOf(nsProp.stringValue);
|
||||
if (currentIndex < 0) currentIndex = 0;
|
||||
|
||||
private void DrawPathDropdown(Rect rect, SerializedProperty pathProp, string namespace_)
|
||||
{
|
||||
var paths = StyleManager.GetPathsForNamespace(namespace_);
|
||||
int newIndex = EditorGUI.Popup(rect, currentIndex, namespaces.ToArray());
|
||||
if (newIndex >= 0 && newIndex < namespaces.Count)
|
||||
{
|
||||
nsProp.stringValue = namespaces[newIndex];
|
||||
}
|
||||
}
|
||||
|
||||
var displayOptions = new System.Collections.Generic.List<string>();
|
||||
if (paths.Count == 0)
|
||||
{
|
||||
displayOptions.Add("(无可用路径)");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var p in paths)
|
||||
{
|
||||
StyleValue val = StyleManager.GetValue(namespace_, p);
|
||||
string typeStr = val?.ValueType != null ? GetShortTypeName(val.ValueType) : "?";
|
||||
string valStr = val?.RawValue != null ? val.RawValue.ToString() : "";
|
||||
if (valStr.Length > 20) valStr = valStr.Substring(0, 17) + "...";
|
||||
displayOptions.Add($"{p} [{typeStr}] {valStr}");
|
||||
}
|
||||
}
|
||||
private void DrawPathDropdown(Rect rect, SerializedProperty pathProp, string namespace_)
|
||||
{
|
||||
var paths = StyleManager.GetPathsForNamespace(namespace_);
|
||||
|
||||
int currentIndex = System.Math.Max(0, paths.IndexOf(pathProp.stringValue));
|
||||
var displayOptions = new System.Collections.Generic.List<string>();
|
||||
if (paths.Count == 0)
|
||||
{
|
||||
displayOptions.Add("(无可用路径)");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var p in paths)
|
||||
{
|
||||
StyleValue val = StyleManager.GetValue(namespace_, p);
|
||||
string typeStr = val?.ValueType != null ? GetShortTypeName(val.ValueType) : "?";
|
||||
string valStr = val?.RawValue != null ? val.RawValue.ToString() : "";
|
||||
if (valStr.Length > 20) valStr = valStr.Substring(0, 17) + "...";
|
||||
displayOptions.Add($"{p} [{typeStr}] {valStr}");
|
||||
}
|
||||
}
|
||||
|
||||
int newIndex = EditorGUI.Popup(rect, currentIndex, displayOptions.ToArray());
|
||||
if (newIndex >= 0 && newIndex < paths.Count)
|
||||
{
|
||||
pathProp.stringValue = paths[newIndex];
|
||||
}
|
||||
}
|
||||
int currentIndex = System.Math.Max(0, paths.IndexOf(pathProp.stringValue));
|
||||
|
||||
#endregion
|
||||
int newIndex = EditorGUI.Popup(rect, currentIndex, displayOptions.ToArray());
|
||||
if (newIndex >= 0 && newIndex < paths.Count)
|
||||
{
|
||||
pathProp.stringValue = paths[newIndex];
|
||||
}
|
||||
}
|
||||
|
||||
#region 工具方法
|
||||
#endregion
|
||||
|
||||
private static string GetFoldKey(SerializedProperty property)
|
||||
{
|
||||
return $"{property.serializedObject.targetObject.GetInstanceID()}_{property.propertyPath}";
|
||||
}
|
||||
#region 工具方法
|
||||
|
||||
private static string GetNamespace(SerializedProperty property)
|
||||
{
|
||||
var nsProp = property.FindPropertyRelative("Namespace");
|
||||
string ns = nsProp?.stringValue;
|
||||
return string.IsNullOrEmpty(ns) ? "default" : ns;
|
||||
}
|
||||
private static string GetFoldKey(SerializedProperty property)
|
||||
{
|
||||
return $"{property.serializedObject.targetObject.GetInstanceID()}_{property.propertyPath}";
|
||||
}
|
||||
|
||||
private static string GetShortTypeName(System.Type type)
|
||||
{
|
||||
if (type == null) return "?";
|
||||
switch (type.Name)
|
||||
{
|
||||
case "Single": return "float";
|
||||
case "Int32": return "int";
|
||||
case "String": return "string";
|
||||
case "Boolean": return "bool";
|
||||
default: return type.Name;
|
||||
}
|
||||
}
|
||||
private static string GetNamespace(SerializedProperty property)
|
||||
{
|
||||
var nsProp = property.FindPropertyRelative(PROP_NAMESPACE);
|
||||
string ns = nsProp?.stringValue;
|
||||
return string.IsNullOrEmpty(ns) ? "default" : ns;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
private static string GetShortTypeName(System.Type type)
|
||||
{
|
||||
if (type == null) return "?";
|
||||
switch (type.Name)
|
||||
{
|
||||
case "Single": return "float";
|
||||
case "Int32": return "int";
|
||||
case "String": return "string";
|
||||
case "Boolean": return "bool";
|
||||
default: return type.Name;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ namespace XericUIEditor.XTable
|
||||
private static string s_EditText = "";
|
||||
private static string s_SizeEditText = ""; // 气泡输入框当前编辑文本
|
||||
private static int s_SizeEditTargetIndex = -1;
|
||||
private static bool s_SizeEditIsColumn;
|
||||
private static string s_LastFocusedControl = "";
|
||||
|
||||
// 拖拽框选状态
|
||||
@@ -120,7 +119,6 @@ namespace XericUIEditor.XTable
|
||||
{
|
||||
if (int.TryParse(newFocus.Substring("XTableColSizeEdit_".Length), out int idx))
|
||||
{
|
||||
s_SizeEditIsColumn = true;
|
||||
s_SizeEditTargetIndex = idx;
|
||||
s_SizeEditText = s_ColWidths != null && idx < s_ColWidths.Length
|
||||
? s_ColWidths[idx].ToString("F0") : "";
|
||||
@@ -130,7 +128,6 @@ namespace XericUIEditor.XTable
|
||||
{
|
||||
if (int.TryParse(newFocus.Substring("XTableRowSizeEdit_".Length), out int idx))
|
||||
{
|
||||
s_SizeEditIsColumn = false;
|
||||
s_SizeEditTargetIndex = idx;
|
||||
s_SizeEditText = s_RowHeights != null && idx < s_RowHeights.Length
|
||||
? s_RowHeights[idx].ToString("F0") : "";
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace XericUI.Core.StyleSheetUI
|
||||
|
||||
#region 序列化字段
|
||||
|
||||
[Header("五态样式路径")]
|
||||
[SerializeField]
|
||||
[Tooltip("正常状态")]
|
||||
private StyleField m_Normal = new StyleField { Namespace = k_DefaultNamespace, StylePath = k_DefaultColorBasePath + "/NormalColor" };
|
||||
@@ -40,7 +39,6 @@ namespace XericUI.Core.StyleSheetUI
|
||||
[Tooltip("禁用状态")]
|
||||
private StyleField m_Disabled = new StyleField { Namespace = k_DefaultNamespace, StylePath = k_DefaultColorBasePath + "/DisabledColor" };
|
||||
|
||||
[Header("过渡")]
|
||||
[SerializeField]
|
||||
[Range(0.001f, 1f)]
|
||||
[Tooltip("渐变持续时间")]
|
||||
|
||||
@@ -184,11 +184,11 @@ namespace XericUI.OverrideUI
|
||||
t.onClick = d.onClick;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Native)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericButton;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Native)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericButton, Button,
|
||||
(Graphic targetGraphic, ButtonClickedEvent onClick)>(
|
||||
|
||||
@@ -41,11 +41,11 @@ namespace XericUI.OverrideUI
|
||||
t.sprite = d;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Native)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericImage;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Native)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericImage, Image, Sprite>(
|
||||
o =>
|
||||
|
||||
@@ -198,11 +198,11 @@ namespace XericUI.OverrideUI
|
||||
t.navigation = d.navigation;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Style)", true)]
|
||||
private static bool ValidateReplaceStyleToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericStyleButton;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Style)", false, 100)]
|
||||
private static void ReplaceStyleToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericStyleButton, Button,
|
||||
(Graphic targetGraphic, ButtonClickedEvent onClick, Navigation navigation)>(
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace XericUI.OverrideUI
|
||||
{
|
||||
#region 序列化字段
|
||||
|
||||
[Header("图像样式")]
|
||||
[SerializeField]
|
||||
[Tooltip("颜色样式路径")]
|
||||
private StyleField m_ColorStyle = new StyleField();
|
||||
@@ -176,11 +175,11 @@ namespace XericUI.OverrideUI
|
||||
o => o.sprite,
|
||||
(t, d) => { t.sprite = d; });
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Style)", true)]
|
||||
private static bool ValidateReplaceStyleImageToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericStyleImage;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Style)", false, 100)]
|
||||
private static void ReplaceStyleImageToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericStyleImage, Image, Sprite>(
|
||||
o => o.sprite,
|
||||
|
||||
@@ -253,11 +253,11 @@ namespace XericUI.OverrideUI
|
||||
o => (o.graphic, o.group, o.onValueChanged, o.navigation),
|
||||
(t, d) => { t.graphic = d.graphic; t.group = d.group; t.onValueChanged = d.onValueChanged; t.navigation = d.navigation; });
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Style)", true)]
|
||||
private static bool ValidateReplaceStyleToggleToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericStyleToggle;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Style)", false, 100)]
|
||||
private static void ReplaceStyleToggleToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericStyleToggle, Toggle,
|
||||
(Graphic graphic, ToggleGroup group, ToggleEvent onValueChanged, Navigation navigation)>(
|
||||
|
||||
@@ -299,11 +299,11 @@ namespace XericUI
|
||||
Debug.Log("请手动替换toggle下的Checkmark Image组件为XericImage,这样Toggle关闭时取消选中的状态会保持为ison状态");
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Native)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericToggle;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Native)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericToggle, Toggle,
|
||||
(Graphic graphic, ToggleGroup group, ToggleEvent onValueChanged)>(
|
||||
|
||||
@@ -38,11 +38,11 @@ namespace XericUI.OverrideUI
|
||||
o => (o.targetGraphic, o.onClick),
|
||||
(t, d) => { t.targetGraphic = d.targetGraphic; t.onClick = d.onClick; });
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Attribute)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeButton;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Attribute)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeButton, Button,
|
||||
(Graphic targetGraphic, Button.ButtonClickedEvent onClick)>(
|
||||
|
||||
@@ -55,11 +55,11 @@ namespace XericUI.OverrideUI
|
||||
o => o.sprite,
|
||||
(t, d) => { t.sprite = d; });
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Attribute)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeText;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Attribute)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeText, Image, Sprite>(
|
||||
o => o.sprite,
|
||||
|
||||
@@ -42,11 +42,11 @@ namespace XericUI.OverrideUI
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle", true)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Attribute)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeToggle;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle", false, 100)]
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Attribute)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeToggle, Toggle,
|
||||
(Graphic graphic, ToggleGroup group, Toggle.ToggleEvent onValueChanged)>(
|
||||
|
||||
@@ -66,7 +66,6 @@ namespace XericUI.XTable.Rendering.Elements
|
||||
RegisterField("/cell/font/size", OnStyleChanged);
|
||||
RegisterField("/cell/font/alignment", OnStyleChanged);
|
||||
RegisterField("/cell/font/richText", OnStyleChanged);
|
||||
RegisterField("/cell/font/fontAsset", OnStyleChanged);
|
||||
|
||||
m_IsBound = true;
|
||||
RefreshAll();
|
||||
@@ -123,20 +122,6 @@ namespace XericUI.XTable.Rendering.Elements
|
||||
StyleValue richVal = GetStyleValue("/cell/font/richText");
|
||||
if (richVal != null && TextComponent != null)
|
||||
TextComponent.richText = (bool)richVal;
|
||||
|
||||
// 字体资源
|
||||
StyleValue fontVal = GetStyleValue("/cell/font/fontAsset");
|
||||
if (fontVal != null && TextComponent != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
TextComponent.font = fontVal.GetValueAs<TMP_FontAsset>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
/* 类型不匹配时忽略 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -47,3 +47,21 @@ cell/default/ {
|
||||
height = 40:System.Single @Desc:默认行高
|
||||
width = 100:System.Single @Desc:默认列宽
|
||||
}
|
||||
|
||||
|
||||
/button/TargetGraphic/ColorTint:UnityEngine.UI.ColorBlock/ {
|
||||
.NormalColor = (1,1,1,1)
|
||||
.HighlightedColor = (0.96,0.96,0.96,1)
|
||||
.PressedColor = (0.78,0.78,0.78,1)
|
||||
.SelectedColor = (0.96,0.96,0.96,1)
|
||||
.DisabledColor = (0.6,0.6,0.6,0.8)
|
||||
}
|
||||
|
||||
/toggle/TargetGraphic/ColorTint:UnityEngine.UI.ColorBlock/ {
|
||||
.NormalColor = (1,1,1,1)
|
||||
.HighlightedColor = (0.96,0.96,0.96,1)
|
||||
.PressedColor = (0.78,0.78,0.78,1)
|
||||
.SelectedColor = (0.96,0.96,0.96,1)
|
||||
.DisabledColor = (0.6,0.6,0.6,0.8)
|
||||
.DisabledColor = (0.6,0.6,0.6,0.8)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user