riversong code showcase
This commit is contained in:
40
Source/Riversong/Game/UI/Helpers/VisualElementExtensions.cs
Normal file
40
Source/Riversong/Game/UI/Helpers/VisualElementExtensions.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public static class VisualElementExtensions
|
||||
{
|
||||
public static VisualElement GetFirstAncestorOrSelf(this VisualElement element, Func<VisualElement, bool> predicate)
|
||||
{
|
||||
while (element != null)
|
||||
{
|
||||
if (predicate(element)) return element;
|
||||
element = element.parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void SetAbsoluteScreenPosition(this VisualElement element, Vector2 screenPoint)
|
||||
{
|
||||
element.style.position = Position.Absolute;
|
||||
element.style.left = screenPoint.x;
|
||||
element.style.top = Screen.height - screenPoint.y;
|
||||
}
|
||||
|
||||
public static void SetScale(this VisualElement element, float value)
|
||||
{
|
||||
element.style.scale = new StyleScale(new Scale(Vector2.one * value));
|
||||
}
|
||||
|
||||
public static void SetPickingModeRecursive(this VisualElement element, PickingMode pickingMode)
|
||||
{
|
||||
element.pickingMode = pickingMode;
|
||||
|
||||
var hierarchy = element.hierarchy;
|
||||
for (var i = 0; i < hierarchy.childCount; i++) hierarchy.ElementAt(i).SetPickingModeRecursive(pickingMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user