3 Incheckningar ac32f98833 ... 36d5b9ea5e

Upphovsman SHA1 Meddelande Datum
  James Peret 36d5b9ea5e Bumped package version to 0.2.1 2 år sedan
  James Peret bd011c6adc Added SuperLerp function 2 år sedan
  James Peret 3b1a918ea2 Added GetPointsInRadius function 2 år sedan
3 ändrade filer med 46 tillägg och 5 borttagningar
  1. 3 2
      Readme.md
  2. 42 2
      Runtime/Utilities.cs
  3. 1 1
      package.json

+ 3 - 2
Readme.md

@@ -1,4 +1,4 @@
-# 📦 KairoEngine.Utilities v0.2.0
+# 📦 KairoEngine.Utilities v0.2.1
 
 Kairoengine utilities library.
 
@@ -13,6 +13,7 @@ Kairoengine utilities library.
 
 ### 📄Changelog
 
+##### v0.2.1
+- Added SuperLerp function
 ##### v0.2.0
-
 - Moved Statistics namespace to its own package

+ 42 - 2
Runtime/Utilities.cs

@@ -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;
+        }
     }
 }
 

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
     "name": "at.kairoscope.kairoengine.utilities",
     "displayName": "KairoEngine Utilities",
-    "version": "0.2.0",
+    "version": "0.2.1",
     "unity": "2020.3",
     "description": "Kairoengine utilities library. Contains the MeshUtils, StringUtils, Vector2Int extensions and the Statistics System.",
     "dependencies": {