1
This commit is contained in:
@@ -10,6 +10,7 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.UIElements;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -206,30 +207,11 @@ namespace BITKit
|
||||
}
|
||||
public static float GetLength(this Vector2 self)
|
||||
{
|
||||
return Mathf.Max(Mathf.Abs(self.x), Mathf.Abs(self.y));
|
||||
return math.max(math.abs(self.x), math.abs(self.y));
|
||||
}
|
||||
public static float GetLength(this Vector3 self)
|
||||
{
|
||||
return Mathf.Max(Mathf.Abs(self.x), Mathf.Abs(self.y), Mathf.Abs(self.z));
|
||||
}
|
||||
public static float GetValue(this Vector3 self)
|
||||
{
|
||||
var addValue = self.x + self.y + self.z;
|
||||
var subtractValue = self.x - self.y - self.z;
|
||||
if (Math.Abs(MathF.Abs(addValue) - Mathf.Abs(subtractValue)) < 0.01f)
|
||||
{
|
||||
return addValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("Not a valid vector");
|
||||
sb.AppendLine($"{self.x}+{self.y}+{self.z} = {addValue}");
|
||||
sb.AppendLine($"{self.x}-{self.y}-{self.z} = {subtractValue}");
|
||||
sb.AppendLine($"{addValue}");
|
||||
sb.AppendLine($"{subtractValue}");
|
||||
throw new Exception(sb.ToString());
|
||||
}
|
||||
return math.max(math.abs(self.x),math.max(math.abs(self.y), math.abs(self.z)));
|
||||
}
|
||||
public static bool InRange(this Vector2Int self, Vector2Int other)
|
||||
{
|
||||
@@ -607,6 +589,8 @@ namespace BITKit
|
||||
}
|
||||
public static partial class UIToolkitExtensions
|
||||
{
|
||||
private static Camera Camera => _camera ? _camera : _camera = Camera.main;
|
||||
private static Camera _camera;
|
||||
public static VisualElement Create(this VisualElement self, VisualTreeAsset asset)
|
||||
{
|
||||
var clone = asset.CloneTree();
|
||||
@@ -689,38 +673,21 @@ namespace BITKit
|
||||
}
|
||||
public static bool IsVisible(this VisualElement self,Vector3 worldPosition)
|
||||
{
|
||||
var cameraTrans = Camera.main.transform;
|
||||
var cameraTrans = Camera.transform;
|
||||
return Vector3.Dot(cameraTrans.forward, worldPosition - cameraTrans.position) > 0;
|
||||
}
|
||||
|
||||
public static Vector2 GetScreenPosition(this VisualElement self, Vector3 worldPosition)
|
||||
{
|
||||
try
|
||||
{
|
||||
var panel = self.panel;
|
||||
if (panel is null)
|
||||
{
|
||||
panel = self.parent.panel;
|
||||
}
|
||||
var panel = (self.panel ?? self.parent.panel) ?? self.parent.parent.panel;
|
||||
|
||||
if (panel is null)
|
||||
{
|
||||
panel = self.parent.parent.panel;
|
||||
}
|
||||
var pos = RuntimePanelUtils
|
||||
.CameraTransformWorldToPanel(panel, worldPosition, Camera);
|
||||
|
||||
var pos = RuntimePanelUtils
|
||||
.CameraTransformWorldToPanel(panel, worldPosition, Camera.main);
|
||||
pos.x -= self.layout.width / 2;
|
||||
pos.y -= self.layout.height / 2;
|
||||
|
||||
pos.x -= self.layout.width / 2;
|
||||
pos.y -= self.layout.height / 2;
|
||||
|
||||
return pos;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
return default;
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static Vector2 GetPosition(this VisualElement self)
|
||||
@@ -736,7 +703,7 @@ namespace BITKit
|
||||
self.style.left = screenPosition.x;
|
||||
self.style.top = screenPosition.y;
|
||||
}
|
||||
public static void SetPosition(this VisualElement self,Vector3 worldPosition)
|
||||
public static Vector2 SetPosition(this VisualElement self,Vector3 worldPosition)
|
||||
{
|
||||
var pos = self.GetScreenPosition(worldPosition);
|
||||
var visible = self.IsVisible(worldPosition);
|
||||
@@ -749,6 +716,8 @@ namespace BITKit
|
||||
self.style.top = pos.y;
|
||||
|
||||
self.SetOpacity(visible ? 1 : 0);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static void ClearTooltipsOnPointerLeave(this VisualElement visualElement)
|
||||
|
Reference in New Issue
Block a user