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