Update
This commit is contained in:
@@ -22,12 +22,15 @@ namespace UI
|
||||
public List<ScreenData> screens = new List<ScreenData>();
|
||||
public string initialScreen = "MainMenu";
|
||||
|
||||
[Header("Cursor Settings")]
|
||||
[Header("Cursor & Trail Settings")]
|
||||
public Sprite trailSprite;
|
||||
public float trailFadeSpeed = 3f;
|
||||
public int trailCount = 15;
|
||||
public float focusRadius = 500f;
|
||||
|
||||
private VisualElement _customCursor;
|
||||
private List<VisualElement> _trailPool = new List<VisualElement>();
|
||||
private int _trailIndex = 0;
|
||||
public int trailCount = 15;
|
||||
public float focusRadius = 500f;
|
||||
|
||||
[Header("Editor Preview")]
|
||||
[Range(0f, 1f)]
|
||||
@@ -37,7 +40,6 @@ namespace UI
|
||||
private string _currentScreenName;
|
||||
private VisualElement _lastHoveredElement;
|
||||
|
||||
// Flags for MainMenu state
|
||||
public bool isMainMenuActive = false;
|
||||
private bool _isSettingsOpen = false;
|
||||
|
||||
@@ -46,6 +48,9 @@ namespace UI
|
||||
if (Instance == null) Instance = this;
|
||||
else { Destroy(gameObject); return; }
|
||||
|
||||
var myDoc = GetComponent<UIDocument>();
|
||||
if (myDoc != null) myDoc.sortingOrder = 1000;
|
||||
|
||||
SetupCursor();
|
||||
foreach (var s in screens)
|
||||
{
|
||||
@@ -74,10 +79,18 @@ namespace UI
|
||||
for (int i = 0; i < trailCount; i++)
|
||||
{
|
||||
var trail = new VisualElement();
|
||||
trail.style.width = 18; trail.style.height = 18;
|
||||
trail.style.backgroundColor = new Color(1, 1, 1, 0.4f);
|
||||
trail.style.borderTopLeftRadius = 9; trail.style.borderTopRightRadius = 9;
|
||||
trail.style.borderBottomLeftRadius = 9; trail.style.borderBottomRightRadius = 9;
|
||||
trail.style.width = 20; trail.style.height = 20;
|
||||
if (trailSprite != null)
|
||||
{
|
||||
trail.style.backgroundImage = new StyleBackground(trailSprite);
|
||||
trail.style.backgroundColor = Color.clear;
|
||||
}
|
||||
else
|
||||
{
|
||||
trail.style.backgroundColor = new Color(1, 1, 1, 0.4f);
|
||||
trail.style.borderTopLeftRadius = 10; trail.style.borderTopRightRadius = 10;
|
||||
trail.style.borderBottomLeftRadius = 10; trail.style.borderBottomRightRadius = 10;
|
||||
}
|
||||
trail.style.position = Position.Absolute;
|
||||
trail.pickingMode = PickingMode.Ignore;
|
||||
root.Add(trail);
|
||||
@@ -89,14 +102,12 @@ namespace UI
|
||||
private void Update()
|
||||
{
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
|
||||
bool isMainMenu = (_currentScreenName == "MainMenu");
|
||||
bool restrictY = (isMainMenu && isMainMenuActive && !_isSettingsOpen);
|
||||
|
||||
float targetY = restrictY ? Screen.height / 2f : mousePos.y;
|
||||
Vector2 uiPos = new Vector2(mousePos.x, Screen.height - targetY);
|
||||
|
||||
bool showCursor = !isMainMenu || !isMainMenuActive || _isSettingsOpen;
|
||||
bool showCursor = !isMainMenu || _isSettingsOpen;
|
||||
DisplayStyle cursorDisplay = showCursor ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
|
||||
if (_customCursor != null)
|
||||
@@ -109,13 +120,16 @@ namespace UI
|
||||
if (_trailPool.Count > 0)
|
||||
{
|
||||
var currentTrail = _trailPool[_trailIndex];
|
||||
currentTrail.style.left = uiPos.x - 9;
|
||||
currentTrail.style.top = uiPos.y - 9;
|
||||
currentTrail.style.opacity = 0.5f;
|
||||
currentTrail.style.display = cursorDisplay;
|
||||
currentTrail.style.left = uiPos.x - 10;
|
||||
currentTrail.style.top = uiPos.y - 10;
|
||||
currentTrail.style.opacity = 0.6f;
|
||||
|
||||
foreach(var t in _trailPool)
|
||||
{
|
||||
t.style.display = cursorDisplay;
|
||||
t.style.opacity = Mathf.Max(0, t.style.opacity.value - Time.deltaTime * 4f);
|
||||
float currentOp = t.style.opacity.value;
|
||||
if (currentOp > 0) t.style.opacity = Mathf.Max(0, currentOp - Time.deltaTime * trailFadeSpeed);
|
||||
else t.style.display = DisplayStyle.None;
|
||||
}
|
||||
_trailIndex = (_trailIndex + 1) % _trailPool.Count;
|
||||
}
|
||||
@@ -132,12 +146,10 @@ namespace UI
|
||||
var settings = screens.Find(s => s.screenName == "Settings");
|
||||
if (_isSettingsOpen) activeDoc = settings.document;
|
||||
else activeDoc = screens.Find(s => s.screenName == _currentScreenName)?.document;
|
||||
|
||||
if (activeDoc == null) return;
|
||||
|
||||
VisualElement bestElement = null;
|
||||
float minDistance = float.MaxValue;
|
||||
|
||||
var interactables = activeDoc.rootVisualElement.Query<VisualElement>()
|
||||
.Where(e => e.focusable && e.pickingMode != PickingMode.Ignore).ToList();
|
||||
|
||||
@@ -219,11 +231,7 @@ namespace UI
|
||||
|
||||
_currentScreenName = _navigationStack.Peek();
|
||||
var prevData = screens.Find(s => s.screenName == _currentScreenName);
|
||||
if (prevData != null)
|
||||
{
|
||||
prevData.document.rootVisualElement.style.display = DisplayStyle.Flex;
|
||||
prevData.isActive = true;
|
||||
}
|
||||
if (prevData != null) prevData.document.rootVisualElement.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
|
||||
public void ToggleSettings()
|
||||
@@ -232,8 +240,6 @@ namespace UI
|
||||
if (settings == null) return;
|
||||
_isSettingsOpen = settings.document.rootVisualElement.style.display == DisplayStyle.None;
|
||||
settings.document.rootVisualElement.style.display = _isSettingsOpen ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
settings.isActive = _isSettingsOpen;
|
||||
|
||||
if (_isSettingsOpen) settings.document.sortingOrder = 999;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user