狗屎Minimax坏我代码
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using SickscoreGames;
|
||||
|
||||
namespace SickscoreGames.HUDNavigationSystem
|
||||
{
|
||||
@@ -55,6 +48,20 @@ namespace SickscoreGames.HUDNavigationSystem
|
||||
}
|
||||
|
||||
|
||||
public static Vector3 KeepInCircleBounds (this RectTransform rect, Vector3 markerPos, out bool outOfBounds)
|
||||
{
|
||||
Vector3 center = rect.rect.center;
|
||||
float radius = Mathf.Min(rect.rect.width, rect.rect.height) * 0.5f;
|
||||
|
||||
Vector3 offset = markerPos - center;
|
||||
Vector3 clamped = Vector3.ClampMagnitude(offset, radius);
|
||||
|
||||
outOfBounds = offset != clamped;
|
||||
|
||||
return center + clamped;
|
||||
}
|
||||
|
||||
|
||||
public static float GetIconRadius (this HUDNavigationElement element, NavigationElementType elementType)
|
||||
{
|
||||
float radius = (elementType == NavigationElementType.Radar) ? element.Radar.PrefabRect.sizeDelta.x : element.Minimap.PrefabRect.sizeDelta.x;
|
||||
@@ -163,7 +170,7 @@ namespace SickscoreGames.HUDNavigationSystem
|
||||
#region CompassBar Extension Methods
|
||||
public static void ShowCompassBarDistance (this HUDNavigationElement element, int distance = 0)
|
||||
{
|
||||
if (element.CompassBar.DistanceText == null)
|
||||
if (!element.CompassBar.DistanceText)
|
||||
return;
|
||||
|
||||
// only update if value has changed
|
||||
@@ -172,8 +179,8 @@ namespace SickscoreGames.HUDNavigationSystem
|
||||
element.CompassBar.DistanceText.gameObject.SetActive (useDistanceText);
|
||||
|
||||
// update distance text if active
|
||||
if (useDistanceText) // TODO add TextMeshPro support?
|
||||
element.CompassBar.DistanceText.text = string.Format (element.compassBarDistanceTextFormat, distance);
|
||||
if (useDistanceText)
|
||||
element.CompassBar.DistanceText.SetText(string.Format (element.compassBarDistanceTextFormat, distance));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -198,17 +205,17 @@ namespace SickscoreGames.HUDNavigationSystem
|
||||
public static void ShowIndicatorDistance (this HUDNavigationElement element, bool onScreen, int distance = 0)
|
||||
{
|
||||
// show/hide distance text
|
||||
Text distanceText = (onScreen) ? element.Indicator.OnscreenDistanceText : element.Indicator.OffscreenDistanceText;
|
||||
if (distanceText != null) {
|
||||
bool showDistance = (onScreen) ? element.useIndicatorDistanceText : element.useIndicatorDistanceText && element.showOffscreenIndicatorDistance;
|
||||
var distanceText = onScreen ? element.Indicator.OnscreenDistanceText : element.Indicator.OffscreenDistanceText;
|
||||
if (distanceText) {
|
||||
bool showDistance = onScreen ? element.useIndicatorDistanceText : element.useIndicatorDistanceText && element.showOffscreenIndicatorDistance;
|
||||
|
||||
// only update if value has changed
|
||||
if (showDistance != distanceText.gameObject.activeSelf)
|
||||
distanceText.gameObject.SetActive (showDistance);
|
||||
|
||||
// update distance text if active
|
||||
if (showDistance) // TODO add TextMeshPro support?
|
||||
distanceText.text = string.Format ((onScreen) ? element.indicatorOnscreenDistanceTextFormat : element.indicatorOffscreenDistanceTextFormat, distance);
|
||||
if (showDistance)
|
||||
distanceText.SetText(string.Format (onScreen ? element.indicatorOnscreenDistanceTextFormat : element.indicatorOffscreenDistanceTextFormat, distance));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,5 +298,36 @@ namespace SickscoreGames.HUDNavigationSystem
|
||||
return (float)profile.MapTextureSize.x / (float)profile.MapTextureSize.y;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region General Extension Methods
|
||||
public static T FindFirst<T>() where T : Object
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
return GameObject.FindFirstObjectByType<T>();
|
||||
#else
|
||||
return Object.FindObjectOfType<T>();
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool TryGet<T>(Component component, out T result) where T : Component
|
||||
{
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
return component.TryGetComponent(out result);
|
||||
#else
|
||||
result = component.GetComponent<T>();
|
||||
return result != null;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static Object EntityOrInstanceIdToObject(int id)
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
return EditorUtility.EntityIdToObject(id);
|
||||
#else
|
||||
return EditorUtility.InstanceIDToObject(id);
|
||||
#endif
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user