1
This commit is contained in:
@@ -22,7 +22,7 @@ namespace BITKit.UX
|
||||
this.visualElement = visualElement;
|
||||
contextLabel = visualElement.Q<Label>(UXConstant.ContextLabel);
|
||||
titleLabel = visualElement.Q<Label>(UXConstant.TitleLabel);
|
||||
numberLabel = visualElement.Q<Label>(UXConstant.TitleLabel);
|
||||
numberLabel = visualElement.Q<Label>(UXConstant.NumberLabel);
|
||||
descriptionLabel = visualElement.Q<Label>(UXConstant.DescriptionLabel);
|
||||
button = visualElement.Q<Button>(UXConstant.MainButton);
|
||||
secButton = visualElement.Q<Button>(UXConstant.SecButton);
|
||||
@@ -33,7 +33,15 @@ namespace BITKit.UX
|
||||
public T Get<T>(int index) where T : VisualElement => visualElement.Q<T>($"{typeof(T).Name}--{index}");
|
||||
public void SetProcess(float process)
|
||||
{
|
||||
visualElement.Q(UXConstant.ProcessBarFill).style.width =Length.Percent(Mathf.Clamp(process * 100,0,100)) ;
|
||||
var radialProgress = visualElement.Q<RadialProgress>();
|
||||
if (radialProgress is not null)
|
||||
{
|
||||
radialProgress.progress = Mathf.Clamp((int)(process*100), 0, 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
visualElement.Q(UXConstant.ProcessBarFill).style.width =Length.Percent(Mathf.Clamp(process * 100,0,100)) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
Src/Unity/Scripts/UX/Core/UXToolTips.cs
Normal file
62
Src/Unity/Scripts/UX/Core/UXToolTips.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXToolTips : MonoBehaviour
|
||||
{
|
||||
private VisualElement root;
|
||||
private Label label;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
root = GetComponent<UIDocument>().rootVisualElement;
|
||||
label = root.Q<Label>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var tooltip = CurrentToolTip(root.panel);
|
||||
if (tooltip != "")
|
||||
{
|
||||
var mouse = Mouse.current;
|
||||
if (mouse is null) return;
|
||||
var mousePos = mouse.position.ReadValue();
|
||||
mousePos.y = Screen.height - mousePos.y;
|
||||
var pos =RuntimePanelUtils.ScreenToPanel(label.panel,mousePos);
|
||||
pos.x += 24;
|
||||
if (pos.x + label.layout.width > label.panel.visualTree.layout.width)
|
||||
{
|
||||
//pos.x = label.panel.visualTree.layout.width - label.layout.width - label.layout.width;
|
||||
pos.x-=label.layout.width+48;
|
||||
}
|
||||
|
||||
label.visible = true;
|
||||
label.text = tooltip;
|
||||
label.transform.position = pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
label.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private string CurrentToolTip(IPanel panel)
|
||||
{
|
||||
// https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-faq-event-and-input-system.html
|
||||
|
||||
if (!EventSystem.current.IsPointerOverGameObject()) return "";
|
||||
|
||||
var screenPosition = Input.mousePosition;
|
||||
screenPosition.y = Screen.height - screenPosition.y;
|
||||
|
||||
VisualElement ve = panel.Pick(RuntimePanelUtils.ScreenToPanel(panel, screenPosition));
|
||||
return ve == null ? "" : ve.tooltip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Src/Unity/Scripts/UX/Core/UXToolTips.cs.meta
Normal file
11
Src/Unity/Scripts/UX/Core/UXToolTips.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98955702b98a11c4e8563958148f5719
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user