This commit is contained in:
MuHua-123
2025-09-05 18:02:13 +08:00
parent 9a20ee8ac5
commit f7fab248d4
53 changed files with 1499 additions and 64 deletions
@@ -21,8 +21,6 @@ namespace MuHua {
public VisualElement root => document.rootVisualElement;
/// <summary> 绑定文档 </summary>
public abstract VisualElement Element { get; }
/// <summary> 添加UI元素 </summary>
public void Add(VisualElement child) => Element.Add(child);
/// <summary> 查询UI元素 </summary>
public T Q<T>(string name = null, string className = null) where T : VisualElement => Element.Q<T>(name, className);
@@ -22,6 +22,18 @@ namespace MuHua {
#endif
}
/// <summary> 获取鼠标位置(元素中的鼠标位置) </summary>
public static Vector3 GetMousePosition(VisualElement element) {
Vector3 mousePosition = GetMousePosition();
float offsetX = mousePosition.x / Screen.width;
float offsetY = mousePosition.y / Screen.height;
float x = element.resolvedStyle.width * offsetX;
float y = element.resolvedStyle.height * (1 - offsetY);
return new Vector3(x, y);
}
/// <summary> 富文本: 颜色 </summary>
public static string RichTextColor(string value, Color color) {
string hexRGBA = ColorUtility.ToHtmlStringRGBA(color);