|
@@ -51,11 +51,11 @@ namespace KairoEngine.Utility
|
|
|
return worldPosition;
|
|
|
}
|
|
|
|
|
|
- public static Vector3 GetMouseWorldPosition(int mouseColliderLayerMask)
|
|
|
+ public static Vector3 GetMouseWorldPosition(int mouseColliderLayerMask, float distance = 999f)
|
|
|
{
|
|
|
if(Camera.main == null) return new Vector3();
|
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
|
- if(Physics.Raycast(ray, out RaycastHit raycastHit, 999f, mouseColliderLayerMask))
|
|
|
+ if(Physics.Raycast(ray, out RaycastHit raycastHit, distance, mouseColliderLayerMask))
|
|
|
{
|
|
|
return raycastHit.point;
|
|
|
}
|
|
@@ -78,6 +78,14 @@ namespace KairoEngine.Utility
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static Collider GetMouseWorldPositionCollider(int mouseColliderLayerMask)
|
|
|
+ {
|
|
|
+ if(Camera.main == null) return null;
|
|
|
+ Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
|
+ if(Physics.Raycast(ray, out RaycastHit raycastHit, 999f, mouseColliderLayerMask)) return raycastHit.collider;
|
|
|
+ else return null;
|
|
|
+ }
|
|
|
+
|
|
|
// Create a Text Popup in the World, no parent
|
|
|
public static void CreateWorldTextPopup(string text, Vector3 localPosition) {
|
|
|
CreateWorldTextPopup(null, text, localPosition, 40, Color.white, localPosition + new Vector3(0, 20), 1f, true);
|
|
@@ -115,6 +123,38 @@ namespace KairoEngine.Utility
|
|
|
public static Vector3 ApplyRotationToVector(Vector3 vec, float angle) {
|
|
|
return Quaternion.Euler(0,0,angle) * vec;
|
|
|
}
|
|
|
+
|
|
|
+ public static List<Vector2Int> GetPointsInRadius(int radius, bool includeOrigin = true)
|
|
|
+ {
|
|
|
+ List<Vector2Int> points = new List<Vector2Int>();
|
|
|
+ if(includeOrigin) points.Add(new Vector2Int(0, 0));
|
|
|
+ for (int i = 1; i < radius; i++)
|
|
|
+ {
|
|
|
+ for (int j = 1; j < radius; j++)
|
|
|
+ {
|
|
|
+ if (i * i + j * j < (radius * radius))
|
|
|
+ {
|
|
|
+ points.Add(new Vector2Int(i,j));
|
|
|
+ points.Add(new Vector2Int(-i,j));
|
|
|
+ points.Add(new Vector2Int(i,-j));
|
|
|
+ points.Add(new Vector2Int(-i,-j));
|
|
|
+ points.Add(new Vector2Int(i, 0));
|
|
|
+ points.Add(new Vector2Int(-i, 0));
|
|
|
+ points.Add(new Vector2Int(0, j));
|
|
|
+ points.Add(new Vector2Int(0, -j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return points;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static float SuperLerp(float from, float to, float from2, float to2, float value) {
|
|
|
+ if (value <= from2)
|
|
|
+ return from;
|
|
|
+ else if (value >= to2)
|
|
|
+ return to;
|
|
|
+ return (to - from) * ((value - from2) / (to2 - from2)) + from;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|