diff --git a/.gitmodules b/.gitmodules
index e14f4f2..e69de29 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +0,0 @@
-[submodule "geometry3Sharp"]
- path = geometry3Sharp
- url = https://github.com/gradientspace/geometry3Sharp
diff --git a/Camera/FitToCameraView.cs b/Camera/FitToCameraView.cs
index de375a2..9dc20b0 100644
--- a/Camera/FitToCameraView.cs
+++ b/Camera/FitToCameraView.cs
@@ -5,7 +5,7 @@ namespace UnityHelpers
///
/// Use this to get an object to fit properly in a camera's view.
///
- [ExecuteAlways]
+ [ExecuteInEditMode]
public class FitToCameraView : MonoBehaviour
{
[Range(0, 10000)]
diff --git a/Camera/Modes/FirstPersonCameraController.cs b/Camera/Modes/FirstPersonCameraController.cs
index 43622ee..3d51ad2 100644
--- a/Camera/Modes/FirstPersonCameraController.cs
+++ b/Camera/Modes/FirstPersonCameraController.cs
@@ -34,11 +34,14 @@ protected override void ApplyInput()
else
transform.position = Vector3.zero;
- if (strafe >= shiftMinimum || lookHorizontal >= shiftMinimum)
- shiftRight?.Invoke();
- else if (strafe <= -shiftMinimum || lookHorizontal <= -shiftMinimum)
- shiftLeft?.Invoke();
-
+ if (strafe >= shiftMinimum || lookHorizontal >= shiftMinimum) {
+ if (shiftRight != null)
+ shiftRight.Invoke ();
+ } else if (strafe <= -shiftMinimum || lookHorizontal <= -shiftMinimum)
+ {
+ if (shiftLeft != null)
+ shiftLeft.Invoke ();
+ }
}
}
}
\ No newline at end of file
diff --git a/Camera/Modes/OrbitCameraController.cs b/Camera/Modes/OrbitCameraController.cs
index 574db4c..5721e09 100644
--- a/Camera/Modes/OrbitCameraController.cs
+++ b/Camera/Modes/OrbitCameraController.cs
@@ -62,10 +62,15 @@ protected override void ApplyInput()
distance = Mathf.Clamp(distance, minDistance, maxDistance);
transform.position -= transform.forward * distance;
- if (strafe >= shiftMinimum)
- shiftRight?.Invoke();
- else if (strafe <= -shiftMinimum)
- shiftLeft?.Invoke();
+ if (strafe >= shiftMinimum) {
+ if (shiftRight != null)
+ shiftRight.Invoke ();
+ }
+ else if (strafe <= -shiftMinimum)
+ {
+ if (shiftLeft != null)
+ shiftLeft.Invoke ();
+ }
}
}
}
\ No newline at end of file
diff --git a/CommonRoutines.cs b/CommonRoutines.cs
index f67a357..0391c73 100644
--- a/CommonRoutines.cs
+++ b/CommonRoutines.cs
@@ -42,7 +42,8 @@ public static IEnumerator DoUntil(Action action, Func pred, float t
if (pred != null)
predicateOutput = pred();
}
- postAction?.Invoke();
+ if (postAction != null)
+ postAction.Invoke();
}
///
/// Waits to do action using either a timer or condition.
@@ -63,7 +64,8 @@ public static IEnumerator WaitToDoAction(Action action, float timeout = 5,
predicateOutput = pred();
}
- action?.Invoke(predicateOutput || pred == null);
+ if (action != null)
+ action.Invoke(predicateOutput || pred == null);
}
[Obsolete("Use instead TimedAction with the onStart action")]
///
@@ -78,10 +80,12 @@ public static IEnumerator TimedAction(Action action, float time, Action o
float startTime = Time.time;
while (Time.time - startTime <= time)
{
- action?.Invoke((Time.time - startTime) / time);
+ if (action != null)
+ action.Invoke((Time.time - startTime) / time);
yield return null;
}
- onComplete?.Invoke();
+ if (onComplete != null)
+ onComplete.Invoke();
}
///
/// Does an action over a set period of time giving the percent complete as parameter.
@@ -93,15 +97,18 @@ public static IEnumerator TimedAction(Action action, float time, Action o
/// Coroutine enumerator
public static IEnumerator TimedAction(Action action, float time, Action onStart, Action onComplete)
{
- onStart?.Invoke();
+ if (onStart != null)
+ onStart.Invoke();
time = Mathf.Clamp(time, 0, float.MaxValue);
float startTime = Time.time;
while (Time.time - startTime <= time)
{
- action?.Invoke((Time.time - startTime) / time);
+ if (action != null)
+ action.Invoke((Time.time - startTime) / time);
yield return null;
}
- onComplete?.Invoke();
+ if (onComplete != null)
+ onComplete.Invoke();
}
}
}
\ No newline at end of file
diff --git a/DDS/DDSLoader.cs b/DDS/DDSLoader.cs
index a72e739..1e9f3bc 100644
--- a/DDS/DDSLoader.cs
+++ b/DDS/DDSLoader.cs
@@ -58,7 +58,7 @@ public static Texture2D LoadDDSFile(Stream data)
bool isCompressed = (header.ddspf.dwFlags & PIXELFORMAT_DWFlags.DDPF_FOURCC) != 0;
if (isCompressed && header.ddspf.dwFourCC == DDS_DX10)
{
- Debug.Log(nameof(DDSLoader) + ": Reading extra header");
+ Debug.Log("DDSLoader: Reading extra header");
header_10.dxgiFormat = (DXGI_FORMAT)DataParser.ReadInt(data);
header_10.resourceDimension = (D3D10_RESOURCE_DIMENSION)DataParser.ReadInt(data);
header_10.miscFlag = DataParser.ReadUInt(data);
@@ -70,7 +70,7 @@ public static Texture2D LoadDDSFile(Stream data)
Texture2DHelpers.FlipVertical(imageColors, (ushort)header.dwWidth, (ushort)header.dwHeight);
}
else
- Debug.LogError(nameof(DDSLoader) + ": Invalid DDS magic, expected " + DDS_ + " got " + magic);
+ Debug.LogError("DDSLoader: Invalid DDS magic, expected " + DDS_ + " got " + magic);
if (imageColors != null)
{
diff --git a/Debug/DebugPanel.cs b/Debug/DebugPanel.cs
index 4c12d5c..c2e47f8 100644
--- a/Debug/DebugPanel.cs
+++ b/Debug/DebugPanel.cs
@@ -11,10 +11,14 @@ public class DebugPanel : MonoBehaviour
{
public string emptyMessage = "Nothing to show";
- private static Dictionary debugValues = new Dictionary();
+ private static Dictionary debugValues = new Dictionary();
private static bool refreshed;
+ #if (TextMeshPro)
public TMPro.TextMeshProUGUI output;
+ #else
+ public UnityEngine.UI.Text output;
+ #endif
private System.Text.StringBuilder builtOutput = new System.Text.StringBuilder();
[Space(10), Tooltip("If set to true, will only output from filtered values")]
@@ -33,7 +37,7 @@ private void Update()
List toBeRemoved = new List();
foreach (var debugValue in debugValues)
{
- if (Time.time - debugValue.Value.Item2 > debugValue.Value.Item1)
+ if (Time.time - debugValue.Value.startTime > debugValue.Value.duration)
toBeRemoved.Add(debugValue.Key);
}
foreach (var key in toBeRemoved)
@@ -52,10 +56,10 @@ private void LateUpdate()
public string GetOutput()
{
- builtOutput.Clear();
+ builtOutput.Remove(0, builtOutput.Length);
foreach (var debugValue in debugValues)
if (!filterValues || IsFiltered(debugValue.Key))
- builtOutput.AppendLine(debugValue.Key + ": " + debugValue.Value.Item3);
+ builtOutput.AppendLine(debugValue.Key + ": " + debugValue.Value.outputValue);
return builtOutput.ToString();
}
@@ -73,7 +77,14 @@ public static void Log(string name, object value)
}
public static void Log(string name, object value, float showtime)
{
- debugValues[name] = (showtime, Time.time, value);
+ debugValues[name] = new DebugItem() { duration = showtime, startTime = Time.time, outputValue = value };
}
+
+ public struct DebugItem
+ {
+ public float duration;
+ public float startTime;
+ public object outputValue;
+ }
}
}
\ No newline at end of file
diff --git a/Debug/Prefabs/DebuggingPool.prefab b/Debug/Prefabs/DebuggingPool.prefab
index 4845cfe..ac5de6d 100644
Binary files a/Debug/Prefabs/DebuggingPool.prefab and b/Debug/Prefabs/DebuggingPool.prefab differ
diff --git a/Debug/UnityConsoleOutput.cs b/Debug/UnityConsoleOutput.cs
new file mode 100644
index 0000000..a587645
--- /dev/null
+++ b/Debug/UnityConsoleOutput.cs
@@ -0,0 +1,57 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace UnityHelpers
+{
+ public class UnityConsoleOutput : MonoBehaviour
+ {
+ public static string log { get; private set; }
+ List myLogList = new List();
+ public int maxOutputLines = 50;
+
+ public int frames = 10;
+ private int framesPassed = 0;
+ #if (TextMeshPro)
+ public TMPro.TextMeshProUGUI outputLabel;
+ #else
+ public UnityEngine.UI.Text outputLabel;
+ #endif
+
+ void OnEnable ()
+ {
+ Application.logMessageReceived += HandleLog;
+ }
+
+ void OnDisable ()
+ {
+ Application.logMessageReceived -= HandleLog;
+ }
+
+ void HandleLog(string logString, string stackTrace, LogType type)
+ {
+ log = logString;
+ string newString = "\n [" + type + "] : " + log;
+ myLogList.Add(newString);
+ if (type == LogType.Exception)
+ {
+ newString = "\n" + stackTrace;
+ myLogList.Add(newString);
+ }
+ log = string.Empty;
+ for (int i = Mathf.Max(0, myLogList.Count - maxOutputLines - 1); i < myLogList.Count; i++)
+ {
+ log += myLogList[i];
+ }
+ }
+
+ void Update()
+ {
+ if (framesPassed >= frames)
+ {
+ framesPassed = 0;
+ outputLabel.text = log;
+ }
+ framesPassed++;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Debug/UnityConsoleOutput.cs.meta b/Debug/UnityConsoleOutput.cs.meta
new file mode 100644
index 0000000..2f771d3
--- /dev/null
+++ b/Debug/UnityConsoleOutput.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e5cb7b1c3afbd184ba4e686414c5d383
+timeCreated: 1598495386
+licenseType: Pro
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/EditorExtensions/Attributes/EditorEnumFlags.cs b/EditorExtensions/Attributes/EditorEnumFlags.cs
index 337262e..8deba97 100644
--- a/EditorExtensions/Attributes/EditorEnumFlags.cs
+++ b/EditorExtensions/Attributes/EditorEnumFlags.cs
@@ -1,4 +1,4 @@
-using UnityEditor;
+//using UnityEditor;
using UnityEngine;
namespace UnityHelpers
diff --git a/HealthController.cs b/HealthController.cs
index 358b5ef..69ffef8 100644
--- a/HealthController.cs
+++ b/HealthController.cs
@@ -56,18 +56,22 @@ private void Add(float percent)
percent = Mathf.Clamp01(Mathf.Abs(percent));
value = Mathf.Clamp01(value + percent);
- onValueChanged?.Invoke(value);
- onHealed?.Invoke(percent);
+ if (onValueChanged != null)
+ onValueChanged.Invoke(value);
+ if (onHealed != null)
+ onHealed.Invoke(percent);
}
private void Remove(float percent)
{
percent = Mathf.Clamp01(Mathf.Abs(percent));
value = Mathf.Clamp01(value - percent);
- onValueChanged?.Invoke(value);
- onHurt?.Invoke(-percent);
- if (value <= 0)
- onDead?.Invoke(-percent);
+ if (onValueChanged != null)
+ onValueChanged.Invoke(value);
+ if (onHurt != null)
+ onHurt.Invoke(-percent);
+ if (value <= 0 && onDead != null)
+ onDead.Invoke(-percent);
}
[System.Serializable]
diff --git a/Helpers/BoundsHelpers.cs b/Helpers/BoundsHelpers.cs
index d956d9c..041eba2 100644
--- a/Helpers/BoundsHelpers.cs
+++ b/Helpers/BoundsHelpers.cs
@@ -6,77 +6,6 @@ namespace UnityHelpers
{
public static class BoundsHelpers
{
- ///
- /// Gets all the renderers or colliders in the transform and gets their total bounds.
- ///
- /// The root transform of the object
- /// An option to return the bounds' center to be relative or absolute
- /// If set to true, will get the total bounds from colliders rather than renderers
- /// If set to true includes renderers or colliders that are on disabled gameobjects
- /// A bounds that encapsulates the entire model
- [System.Obsolete("Please use the new GetTotalBounds functions which properly get local/world space bounds")]
- public static Bounds GetTotalBounds(this Transform transform, bool worldSpace = true, bool fromColliders = false, bool includeDisabled = false)
- {
- return GetTotalBounds(transform, ~0, worldSpace, fromColliders, includeDisabled);
- }
- ///
- /// Gets all the renderers or colliders in the transform and gets their total bounds.
- ///
- /// The root transform of the object
- /// The layers to include in bounds calculation
- /// An option to return the bounds' center to be relative or absolute
- /// If set to true, will get the total bounds from colliders rather than renderers
- /// If set to true includes renderers or colliders that are on disabled gameobjects
- /// A bounds that encapsulates the entire model
- [System.Obsolete("Please use the new GetTotalBounds functions which properly get local/world space bounds")]
- public static Bounds GetTotalBounds(this Transform transform, LayerMask layer, bool worldSpace = true, bool fromColliders = false, bool includeDisabled = false)
- {
- Bounds totalBounds = new Bounds();
-
- List innerBounds = new List();
- if (fromColliders)
- {
- foreach (var collider in transform.GetComponentsInChildren(true))
- if (((1 << collider.gameObject.layer) & layer.value) != 0 && (includeDisabled || collider.gameObject.activeSelf))
- innerBounds.Add(collider.bounds);
- }
- else
- {
- foreach (var renderer in transform.GetComponentsInChildren(true))
- if (((1 << renderer.gameObject.layer) & layer.value) != 0 && (includeDisabled || renderer.gameObject.activeSelf))
- innerBounds.Add(renderer.bounds);
- }
-
- if (innerBounds.Count > 0)
- totalBounds = Combine(innerBounds.ToArray());
- else
- totalBounds = new Bounds(transform.position, Vector3.zero);
-
- if (!worldSpace)
- totalBounds.center = transform.InverseTransformPoint(totalBounds.center);
-
- return totalBounds;
- }
- ///
- /// Gets only the current transform's renderer's bounds.
- ///
- /// The transform of the object
- /// An option to return the bounds' center to be relative or absolute
- /// A bounds that encapsulates only the given transform's model
- [System.Obsolete("Please use the new GetBounds functions which properly gets local/world space bounds")]
- public static Bounds GetBounds(this Transform transform, bool worldSpace = true)
- {
- Bounds singleBounds = new Bounds();
-
- Renderer renderer = transform.GetComponent();
- if (renderer != null)
- singleBounds = renderer.bounds;
- if (!worldSpace)
- singleBounds.center = transform.InverseTransformPoint(singleBounds.center);
-
- return singleBounds;
- }
-
///
/// Gets the total bounds of an object including all it's children
///
@@ -100,11 +29,14 @@ public static Bounds GetTotalBounds(this Transform root, Space space, bool fromC
/// A bounds that encapsulates the entire model
public static Bounds GetTotalBounds(this Transform root, Space space, LayerMask layers, bool fromColliders = false, bool includeDisabled = false)
{
- Bounds totalBounds = default;
+ Bounds totalBounds = new Bounds();
IEnumerable boundedObjects;
if (fromColliders)
+ {
boundedObjects = root.GetComponentsInChildren(true).Select(collider => collider.gameObject);
+ boundedObjects = boundedObjects.Concat(root.GetComponentsInChildren(true).Select(collider => collider.gameObject));
+ }
else
boundedObjects = root.GetComponentsInChildren(true).Select(renderer => renderer.gameObject);
@@ -140,7 +72,7 @@ public static Bounds GetTotalBounds(this Transform root, Space space, LayerMask
/// A bounds that encapsulates only the given transform's model
public static Bounds GetBounds(this Transform transform, Space space, bool useCollider = false)
{
- Bounds singleBounds = default;
+ Bounds singleBounds = new Bounds();
if (useCollider)
{
@@ -152,6 +84,17 @@ public static Bounds GetBounds(this Transform transform, Space space, bool useCo
localBounds = transform.TransformBounds(localBounds);
singleBounds = localBounds;
}
+ else
+ {
+ var collider2D = transform.GetComponent();
+ if (collider2D != null)
+ {
+ var localBounds = collider2D.GetLocalBounds();
+ if (space == Space.World)
+ localBounds = transform.TransformBounds(localBounds);
+ singleBounds = localBounds;
+ }
+ }
}
else
{
@@ -229,7 +172,61 @@ public static Bounds GetLocalBounds(this Collider collider)
}
else
{
- Debug.LogError("BoundsHelpers: Given collider was of an unsupported type");
+ Debug.LogError("BoundsHelpers: Given Collider was of an unsupported type");
+ }
+
+ return new Bounds(center, size);
+ }
+ ///
+ /// Gets the local bounds of the collider by figuring out which type it is (supported types: BoxCollider, SphereCollider, CapsuleCollider, and MeshCollider)
+ /// Courtesy of eisenpony from https://forum.unity.com/threads/how-do-you-find-the-size-of-a-local-bounding-box.341007/
+ ///
+ /// The collider whose bounding box is being queried
+ /// The bounding box
+ public static Bounds GetLocalBounds(this Collider2D collider)
+ {
+ Vector2 center = Vector2.zero;
+ Vector2 size = Vector2.zero;
+
+ if (collider is BoxCollider2D)
+ {
+ var box2D = ((BoxCollider2D)collider);
+ center = box2D.offset;
+ size = box2D.size;
+ }
+ else if (collider is CircleCollider2D)
+ {
+ var circle2D = ((CircleCollider2D)collider);
+ center = circle2D.offset;
+ size = Vector2.one * circle2D.radius * 2;
+ }
+ else if (collider is CapsuleCollider2D)
+ {
+ var capsule2D = ((CapsuleCollider2D)collider);
+ center = capsule2D.offset;
+ size = capsule2D.size;
+ }
+ else if (collider is CompositeCollider2D)
+ {
+ var comp2D = ((CompositeCollider2D)collider);
+ center = comp2D.offset;
+ size = comp2D.bounds.size;
+ }
+ else if (collider is EdgeCollider2D)
+ {
+ var edge2D = ((EdgeCollider2D)collider);
+ center = edge2D.offset;
+ size = edge2D.bounds.size;
+ }
+ else if (collider is PolygonCollider2D)
+ {
+ var poly2D = ((PolygonCollider2D)collider);
+ center = poly2D.offset;
+ size = poly2D.bounds.size;
+ }
+ else
+ {
+ Debug.LogError("BoundsHelpers: Given Collider2D was of an unsupported type");
}
return new Bounds(center, size);
diff --git a/Helpers/EditorHelpers.cs b/Helpers/EditorHelpers.cs
index 617bf1b..07742f4 100644
--- a/Helpers/EditorHelpers.cs
+++ b/Helpers/EditorHelpers.cs
@@ -1,3 +1,4 @@
+#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using System.Reflection;
@@ -5,7 +6,6 @@
namespace UnityHelpers
{
- #if UNITY_EDITOR
public static class EditorHelpers
{
///
@@ -194,6 +194,7 @@ public static System.Type GetTargetType(this SerializedProperty prop)
field = GetFieldOfProperty(prop);
return field != null ? field.FieldType : typeof(UnityEngine.Object);
}
+ #if CSHARP_7_3_OR_NEWER
case SerializedPropertyType.FixedBufferSize:
return typeof(int);
case SerializedPropertyType.Vector2Int:
@@ -204,6 +205,7 @@ public static System.Type GetTargetType(this SerializedProperty prop)
return typeof(RectInt);
case SerializedPropertyType.BoundsInt:
return typeof(BoundsInt);
+ #endif
default:
{
field = GetFieldOfProperty(prop);
@@ -212,5 +214,5 @@ public static System.Type GetTargetType(this SerializedProperty prop)
}
}
}
- #endif
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
diff --git a/Helpers/MeshHelpers.cs b/Helpers/MeshHelpers.cs
index 1faa923..a3dd134 100644
--- a/Helpers/MeshHelpers.cs
+++ b/Helpers/MeshHelpers.cs
@@ -2,7 +2,7 @@
using MIConvexHull;
using System.Collections.Generic;
using System.Linq;
-using g3;
+//using g3;
namespace UnityHelpers
{
@@ -160,7 +160,7 @@ public static bool IsPointOnSurface(this Mesh mesh, Vector3 point)
/// The object to be checked. Must have a MeshFilter component attached.
/// The point in question.
/// Whether the point is inside the mesh.
- public static bool IsPointInside(this Transform currentObject, Vector3 point)
+ /*public static bool IsPointInside(this Transform currentObject, Vector3 point)
{
bool isInside = false;
MeshFilter meshFilter = currentObject.GetComponent();
@@ -185,7 +185,7 @@ public static bool IsPointInside(this Mesh mesh, Vector3 point)
var spatial = new DMeshAABBTree3(mesh3);
spatial.Build();
return spatial.IsInside(new Vector3d(point.x, point.y, point.z));
- }
+ }*/
///
/// Gets the center of a triangle given it's three points.
///
@@ -256,13 +256,13 @@ private static bool SameSide(Vector3 p1, Vector3 p2, Vector3 A, Vector3 B)
/// The normals of the mesh.
/// The percent of the original triangle count the final triangle count should be.
/// The decimated mesh.
- public static MeshData DecimateByTriangleCount(IEnumerable vertices, IEnumerable triangles, IEnumerable normals, float trianglePercent = 0.5f)
+ /*public static MeshData DecimateByTriangleCount(IEnumerable vertices, IEnumerable triangles, IEnumerable normals, float trianglePercent = 0.5f)
{
var mesh = GenerateDynamicMesh(vertices, triangles, normals);
var reducer = new Reducer(mesh);
reducer.ReduceToTriangleCount(Mathf.RoundToInt(Mathf.Clamp01(trianglePercent) * (triangles.Count() / 3)));
return new MeshData(reducer.Mesh);
- }
+ }*/
///
/// Reduces the vertex count of the given mesh.
///
@@ -271,7 +271,7 @@ public static MeshData DecimateByTriangleCount(IEnumerable vertices, IE
/// The normals of the mesh.
/// The percent of the original vertex count the final vertex count should be.
/// The decimated mesh.
- public static MeshData DecimateByVertexCount(IEnumerable vertices, IEnumerable triangles, IEnumerable normals, float vertexPercent = 0.5f)
+ /*public static MeshData DecimateByVertexCount(IEnumerable vertices, IEnumerable triangles, IEnumerable normals, float vertexPercent = 0.5f)
{
var mesh = GenerateDynamicMesh(vertices, triangles, normals);
var reducer = new Reducer(mesh);
@@ -281,7 +281,7 @@ public static MeshData DecimateByVertexCount(IEnumerable vertices, IEnu
private static DMesh3 GenerateDynamicMesh(IEnumerable vertices, IEnumerable triangles, IEnumerable normals)
{
return DMesh3Builder.Build(vertices.Select(vertex => new Vector3f(vertex.x, vertex.y, vertex.z)), triangles, normals.Select(vector => new Vector3f(vector.x, vector.y, vector.z)));
- }
+ }*/
///
/// Creates a convex hull given the original vertices of a mesh.
@@ -370,12 +370,12 @@ public MeshData(Mesh _mesh)
uv3 = mesh.uv3;
uv4 = mesh.uv4;
}
- public MeshData(DMesh3 _mesh)
+ /*public MeshData(DMesh3 _mesh)
{
_mesh = new DMesh3(_mesh, true);
vertices = _mesh.VertexIndices().Select(vID => { var vertex = _mesh.GetVertexf(vID); return new Vector3(vertex.x, vertex.y, vertex.z); }).ToArray();
triangles = _mesh.TriangleIndices().SelectMany(tID => _mesh.GetTriangle(tID).array).ToArray();
- }
+ }*/
public void Dispose()
{
if (mesh != null)
diff --git a/Helpers/RectTransformHelpers.cs b/Helpers/RectTransformHelpers.cs
index cabfa13..52b4c2c 100644
--- a/Helpers/RectTransformHelpers.cs
+++ b/Helpers/RectTransformHelpers.cs
@@ -10,11 +10,11 @@ public static Vector2 CalculatePivotPercentFromCenter(this RectTransform rectTra
}
public static Vector2 RemovePivotOffset(this Vector2 localPosition, RectTransform relativeTo)
{
- return localPosition + relativeTo.pivot * relativeTo.rect.size;
+ return localPosition + relativeTo.pivot.Multiply(relativeTo.rect.size);
}
public static void ShiftPivot(this RectTransform rectTransform, Vector2 newPivot)
{
- Vector2 positionOffset = (newPivot - rectTransform.pivot) * rectTransform.rect.size;
+ Vector2 positionOffset = (newPivot - rectTransform.pivot).Multiply(rectTransform.rect.size);
rectTransform.localPosition += (Vector3)positionOffset;
rectTransform.pivot = newPivot;
}
diff --git a/Helpers/VectorHelpers.cs b/Helpers/VectorHelpers.cs
index db48922..23e9728 100644
--- a/Helpers/VectorHelpers.cs
+++ b/Helpers/VectorHelpers.cs
@@ -72,8 +72,42 @@ public static float PercentDirection(this Vector3 vector, Vector3 otherVector)
public static float SignedAngle(this Vector3 point, Vector3 otherPoint, Vector3 fromDirection, Vector3 axis)
{
Vector3 obstacleOffset = otherPoint - point;
- return Vector3.SignedAngle(fromDirection, obstacleOffset.normalized, axis);
+ //return Vector3.SignedAngle(fromDirection, obstacleOffset.normalized, axis);
+ return fromDirection.SignedAngle(obstacleOffset.normalized, axis);
}
+ ///
+ /// Gets the signed angle between fromDirection and toDirection on the given axis.
+ ///
+ /// The direction to measure from.
+ /// The direction to measure to.
+ /// The axis to measure on.
+ /// The signed angle.
+ public static float SignedAngle(this Vector3 fromDirection, Vector3 toDirection, Vector3 axis)
+ {
+ var diffRot = Quaternion.Euler(Vector3.forward) * Quaternion.Inverse(Quaternion.Euler(axis));
+ Vector3 firstDir = Vector3.ProjectOnPlane(fromDirection, axis).normalized;
+ Vector3 secondDir = Vector3.ProjectOnPlane(toDirection, axis).normalized;
+ firstDir = diffRot * firstDir;
+ secondDir = diffRot * secondDir;
+ return firstDir.xz().SignedAngle(secondDir.xz());
+ }
+ ///
+ /// Gets the signed angle between fromDirection and toDirection.
+ ///
+ /// The direction to measure from.
+ /// The direction to measure to.
+ /// The signed angle.
+ public static float SignedAngle(this Vector2 fromDirection, Vector2 toDirection)
+ {
+ fromDirection = fromDirection.normalized;
+ toDirection = toDirection.normalized;
+ float firstAngle = Mathf.Atan2(fromDirection.y, fromDirection.x) * Mathf.Rad2Deg;
+ float secondAngle = Mathf.Atan2(toDirection.y, toDirection.x) * Mathf.Rad2Deg;
+ float angle = firstAngle - secondAngle;
+ if (angle < 0)
+ angle += 360;
+ return angle;
+ }
///
/// Gets just the x and y values of the vector
diff --git a/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.2D.cs b/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.2D.cs
index 326b781..f3347e7 100644
--- a/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.2D.cs
+++ b/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.2D.cs
@@ -175,8 +175,9 @@ internal static List Create(IList points, double tole
// in this case just add
if (cvxVNum == 2)
{
+ List newUsedIndices;
convexHullCCW = FindIntermediatePointsForLongSkinny(points, numPoints, indicesUsed[0], indicesUsed[1],
- out var newUsedIndices);
+ out newUsedIndices);
if (!newUsedIndices.Any())
// looks like only two indices total! so all points are co-linear.
return new List { points[indicesUsed[0]], points[indicesUsed[1]] };
@@ -499,7 +500,7 @@ private static List FindIntermediatePointsForLongSkinny(IList<
// if it errors - it is because there are two points at the same distance along. So, we then
// check if the new point or the existing one on the list should stay. Simply keep the one that is
// furthest from the edge vector.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ //[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool AddToListAlong(TVertex[] sortedPoints, double[] sortedKeys, ref int size,
TVertex newPoint, double newPointX, double newPointY, double basePointX, double basePointY,
double edgeVectorX, double edgeVectorY, double tolerance) where TVertex : IVertex2D
@@ -570,7 +571,7 @@ private static bool AddToListAlong(TVertex[] sortedPoints, double[] sor
// This binary search is modified/simplified from Array.BinarySearch
// (https://referencesource.microsoft.com/mscorlib/a.html#b92d187c91d4c9a9)
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ //[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int BinarySearch(double[] array, int length, double value)
{
var lo = 0;
diff --git a/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.Initialize.cs b/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.Initialize.cs
index 55ad6ea..168d0a9 100644
--- a/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.Initialize.cs
+++ b/MIConvexHull.NET Standard/ConvexHull/ConvexHullAlgorithm.Initialize.cs
@@ -352,13 +352,15 @@ private List FindInitialPoints()
else if ((NumOfDimensions + 1) < numBBPoints)
{ //if there are more bounding box points than needed, call the following function to find a
// random one that has a large volume.
- bestVertexIndices = FindLargestRandomSimplex(boundingBoxPoints, boundingBoxPoints, out var volume);
+ double volume;
+ bestVertexIndices = FindLargestRandomSimplex(boundingBoxPoints, boundingBoxPoints, out volume);
degenerate = volume <= negligibleVolume;
}
if (degenerate)
{ // if it turns out to still be degenerate, then increase the check to include all vertices.
// this is potentially expensive, but we don't have a choice.
- bestVertexIndices = FindLargestRandomSimplex(boundingBoxPoints, Enumerable.Range(0, NumberOfVertices), out var volume);
+ double volume;
+ bestVertexIndices = FindLargestRandomSimplex(boundingBoxPoints, Enumerable.Range(0, NumberOfVertices), out volume);
degenerate = volume <= negligibleVolume;
}
if (degenerate) throw new ConvexHullGenerationException(ConvexHullCreationResultOutcome.DegenerateData,
diff --git a/ObjectPool/ObjectPool.cs b/ObjectPool/ObjectPool.cs
index 9625f78..4ff34c2 100644
--- a/ObjectPool/ObjectPool.cs
+++ b/ObjectPool/ObjectPool.cs
@@ -80,9 +80,10 @@ public G Get(Action action = null) where G : Component
G componentOnObject = null;
Get((poolObject) =>
{
- componentOnObject = poolObject?.GetComponent();
- if (componentOnObject != null)
- action?.Invoke(componentOnObject);
+ if (poolObject != null)
+ componentOnObject = poolObject.GetComponent();
+ if (componentOnObject != null && action != null)
+ action.Invoke(componentOnObject);
});
return componentOnObject;
}
@@ -114,7 +115,8 @@ public T Get(Action action = null)
availableObject = objectPool[availableIndex];
- action?.Invoke(availableObject);
+ if (action != null)
+ action.Invoke(availableObject);
availableObject.gameObject.SetActive(true);
}
diff --git a/ObjectPool/PoolSpawner.cs b/ObjectPool/PoolSpawner.cs
index aaf6f10..6f488e4 100644
--- a/ObjectPool/PoolSpawner.cs
+++ b/ObjectPool/PoolSpawner.cs
@@ -45,12 +45,13 @@ public void Spawn()
if (setScale)
spawned.localScale = Vector3.one * Random.Range(minScale, maxScale);
});
- if (spawnedItem != null)
- onSpawn?.Invoke(spawnedItem, poolName);
+ if (spawnedItem != null && onSpawn != null)
+ onSpawn.Invoke(spawnedItem, poolName);
}
public void ReturnAll()
{
- Pool?.ReturnAll();
+ if (Pool != null)
+ Pool.ReturnAll();
}
private Vector3 GetRandomSpawnPoint()
{
diff --git a/Physics/CollisionListener.cs b/Physics/CollisionListener.cs
index 30a0c1d..b1db901 100644
--- a/Physics/CollisionListener.cs
+++ b/Physics/CollisionListener.cs
@@ -20,48 +20,52 @@ public class CollisionListener : MonoBehaviour
private void OnCollisionStay(Collision collision)
{
- onCollisionStay?.Invoke(new TreeCollider.CollisionInfo
- {
- collidedWith = collision.gameObject,
- collision = collision,
- collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
- isTrigger = false,
- otherCollider = collision.collider,
- sender = gameObject
- });
+ if (onCollisionStay != null)
+ onCollisionStay.Invoke(new TreeCollider.CollisionInfo
+ {
+ collidedWith = collision.gameObject,
+ collision = collision,
+ collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
+ isTrigger = false,
+ otherCollider = collision.collider,
+ sender = gameObject
+ });
}
private void OnTriggerStay(Collider other)
{
- onTriggerStay?.Invoke(new TreeCollider.CollisionInfo
- {
- collidedWith = other.gameObject,
- collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
- isTrigger = true,
- otherCollider = other,
- sender = gameObject
- });
+ if (onTriggerStay != null)
+ onTriggerStay.Invoke(new TreeCollider.CollisionInfo
+ {
+ collidedWith = other.gameObject,
+ collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
+ isTrigger = true,
+ otherCollider = other,
+ sender = gameObject
+ });
}
private void OnTriggerEnter(Collider other)
{
- onTriggerEnter?.Invoke(new TreeCollider.CollisionInfo
- {
- collidedWith = other.gameObject,
- collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
- isTrigger = true,
- otherCollider = other,
- sender = gameObject
- });
+ if (onTriggerEnter != null)
+ onTriggerEnter.Invoke(new TreeCollider.CollisionInfo
+ {
+ collidedWith = other.gameObject,
+ collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
+ isTrigger = true,
+ otherCollider = other,
+ sender = gameObject
+ });
}
private void OnTriggerExit(Collider other)
{
- onTriggerExit?.Invoke(new TreeCollider.CollisionInfo
- {
- collidedWith = other.gameObject,
- collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
- isTrigger = true,
- otherCollider = other,
- sender = gameObject
- });
+ if (onTriggerExit != null)
+ onTriggerExit.Invoke(new TreeCollider.CollisionInfo
+ {
+ collidedWith = other.gameObject,
+ collisionState = TreeCollider.CollisionInfo.CollisionState.stay,
+ isTrigger = true,
+ otherCollider = other,
+ sender = gameObject
+ });
}
}
}
\ No newline at end of file
diff --git a/Physics/CompoundCollision.cs b/Physics/CompoundCollision.cs
index e7c531f..17fdbb1 100644
--- a/Physics/CompoundCollision.cs
+++ b/Physics/CompoundCollision.cs
@@ -30,7 +30,8 @@ private void OnCollisionExit(Collision col)
Debug.Assert(hits[col.gameObject] >= 0);
if (hits[col.gameObject] <= 0)
{
- onCollisionExit?.Invoke(col);
+ if (onCollisionExit != null)
+ onCollisionExit.Invoke(col);
hits.Remove(col.gameObject);
}
}
diff --git a/Physics/Grabber.cs b/Physics/Grabber.cs
index 037d317..4c1de3e 100644
--- a/Physics/Grabber.cs
+++ b/Physics/Grabber.cs
@@ -72,7 +72,7 @@ void Update()
public void AddGrabSpot(string name, Transform grabbedParentedTo)
{
- AddGrabSpot(name, grabbedParentedTo, default);
+ AddGrabSpot(name, grabbedParentedTo, new RaycastInfo());
}
public void AddGrabSpot(string name, Transform grabbedParentedTo, ICastable dimensions)
{
@@ -114,14 +114,16 @@ public void RefreshInRange(System.Action enteredRange, System.Action<
if (grabbableItem != null)
{
inRange.Add(grabbableItem);
- enteredRange?.Invoke(itemInCast.transform);
+ if (enteredRange != null)
+ enteredRange.Invoke(itemInCast.transform);
}
}
}
foreach (var lostItem in oldInRange.Except(inRange))
{
- leftRange?.Invoke(lostItem);
+ if (leftRange != null)
+ leftRange.Invoke(lostItem);
}
}
@@ -151,8 +153,9 @@ public void DrawDebugCast()
}
public void ReturnDebugCast()
{
- if (debugLine != null)
- PoolManager.GetPool("DebugSpheres")?.Return(debugLine.transform);
+ var spheresPool = PoolManager.GetPool("DebugSpheres");
+ if (debugLine != null && spheresPool != null)
+ spheresPool.Return(debugLine.transform);
}
public int CountInRange()
diff --git a/Physics/PhysicsPauser.cs b/Physics/PhysicsPauser.cs
index d5a2b57..fee1f65 100644
--- a/Physics/PhysicsPauser.cs
+++ b/Physics/PhysicsPauser.cs
@@ -8,7 +8,7 @@ namespace UnityHelpers
///
public static class PhysicsPauser
{
- private static Dictionary history = new Dictionary();
+ private static Dictionary history = new Dictionary();
public static void Pause(bool onOff)
{
@@ -18,7 +18,7 @@ public static void Pause(bool onOff)
{
if (!physicsObject.isKinematic) //if something was originally kinematic don't touch it
{
- history[physicsObject] = (physicsObject.velocity, physicsObject.angularVelocity);
+ history[physicsObject] = new PhysicsSnapshot() { velocity = physicsObject.velocity, angularVelocity = physicsObject.angularVelocity };
physicsObject.isKinematic = true;
}
}
@@ -28,11 +28,17 @@ public static void Pause(bool onOff)
foreach (var historyObject in history)
{
historyObject.Key.isKinematic = false;
- historyObject.Key.velocity = historyObject.Value.Item1;
- historyObject.Key.angularVelocity = historyObject.Value.Item2;
+ historyObject.Key.velocity = historyObject.Value.velocity;
+ historyObject.Key.angularVelocity = historyObject.Value.angularVelocity;
}
history.Clear();
}
}
+
+ public struct PhysicsSnapshot
+ {
+ public Vector3 velocity;
+ public Vector3 angularVelocity;
+ }
}
}
diff --git a/Physics/SetCenterOfMass.cs b/Physics/SetCenterOfMass.cs
index a43147c..1d94bbf 100644
--- a/Physics/SetCenterOfMass.cs
+++ b/Physics/SetCenterOfMass.cs
@@ -2,7 +2,7 @@
namespace UnityHelpers
{
- [ExecuteAlways]
+ [ExecuteInEditMode]
public class SetCenterOfMass : MonoBehaviour
{
private Rigidbody body { get { if (_body == null) { _body = GetComponent(); if (_body != null) InitCOM(); } return _body; } }
diff --git a/Physics/TreeCollider.cs b/Physics/TreeCollider.cs
index 64f39f5..277ff4a 100644
--- a/Physics/TreeCollider.cs
+++ b/Physics/TreeCollider.cs
@@ -7,7 +7,7 @@ namespace UnityHelpers
/// This script is meant to be used on objects that have many colliders in their children
/// that you'd like to listen to from a parent. Only attach this script to the parent.
///
- [ExecuteAlways]
+ [ExecuteInEditMode]
public class TreeCollider : MonoBehaviour
{
private List childTrees = new List();
@@ -85,7 +85,8 @@ private void OnCollided(CollisionInfo colInfo)
if (debugMessages)
Debug.Log(GetDebugCollisionMessage(colInfo));
- onCollided?.Invoke(colInfo);
+ if (onCollided != null)
+ onCollided.Invoke(colInfo);
}
#region 3D Trigger Events
private void OnTriggerEnter(Collider other)
@@ -94,7 +95,8 @@ private void OnTriggerEnter(Collider other)
}
private void OnTriggerEnter(CollisionInfo colInfo)
{
- onTriggerEnter?.Invoke(colInfo);
+ if (onTriggerEnter != null)
+ onTriggerEnter.Invoke(colInfo);
OnCollided(colInfo);
}
private void OnTriggerStay(Collider other)
@@ -103,7 +105,8 @@ private void OnTriggerStay(Collider other)
}
private void OnTriggerStay(CollisionInfo colInfo)
{
- onTriggerStay?.Invoke(colInfo);
+ if (onTriggerStay != null)
+ onTriggerStay.Invoke(colInfo);
OnCollided(colInfo);
}
private void OnTriggerExit(Collider other)
@@ -112,7 +115,8 @@ private void OnTriggerExit(Collider other)
}
private void OnTriggerExit(CollisionInfo colInfo)
{
- onTriggerExit?.Invoke(colInfo);
+ if (onTriggerExit != null)
+ onTriggerExit.Invoke(colInfo);
OnCollided(colInfo);
}
#endregion
@@ -123,7 +127,8 @@ private void OnCollisionEnter(Collision collision)
}
private void OnCollisionEnter(CollisionInfo colInfo)
{
- onCollisionEnter?.Invoke(colInfo);
+ if (onCollisionEnter != null)
+ onCollisionEnter.Invoke(colInfo);
OnCollided(colInfo);
}
private void OnCollisionStay(Collision collision)
@@ -132,7 +137,8 @@ private void OnCollisionStay(Collision collision)
}
private void OnCollisionStay(CollisionInfo colInfo)
{
- onCollisionStay?.Invoke(colInfo);
+ if (onCollisionStay != null)
+ onCollisionStay.Invoke(colInfo);
OnCollided(colInfo);
}
private void OnCollisionExit(Collision collision)
@@ -141,7 +147,8 @@ private void OnCollisionExit(Collision collision)
}
private void OnCollisionExit(CollisionInfo colInfo)
{
- onCollisionExit?.Invoke(colInfo);
+ if (onCollisionExit != null)
+ onCollisionExit.Invoke(colInfo);
OnCollided(colInfo);
}
#endregion
@@ -166,7 +173,7 @@ private void InitChildren()
Collider[] childrenColliders = GetComponentsInChildren(true);
foreach (var collider in childrenColliders)
{
- if (collider.transform.parent?.GetComponentInParent().transform == transform)
+ if (collider.transform.parent != null && collider.transform.parent.GetComponentInParent().transform == transform)
{
var childTreeCollider = collider.gameObject.GetComponent();
if (childTreeCollider == null)
diff --git a/Physics/Vehicles/Ball/BallPhysics.cs b/Physics/Vehicles/Ball/BallPhysics.cs
index a38eb53..c636e67 100644
--- a/Physics/Vehicles/Ball/BallPhysics.cs
+++ b/Physics/Vehicles/Ball/BallPhysics.cs
@@ -54,7 +54,7 @@ private void AccelerateBall()
Vector3 worldDirection = new Vector3(circularInput.x, 0, circularInput.y);
//Get the angle offset of the input direction from world forward
- float upAngle = Vector3.SignedAngle(Vector3.forward, worldDirection, Vector3.up);
+ float upAngle = Vector3.forward.SignedAngle(worldDirection, Vector3.up);
//Apply the same angle offset but to the given ball forward and make sure the input magnitude is the same
Vector3 adjustedWorldDirection = Quaternion.AngleAxis(upAngle, up) * forward * worldDirection.magnitude;
diff --git a/geometry3Sharp.meta b/Physics/Vehicles/Ball/Models/Materials.meta
similarity index 58%
rename from geometry3Sharp.meta
rename to Physics/Vehicles/Ball/Models/Materials.meta
index 0ae38f5..4238902 100644
--- a/geometry3Sharp.meta
+++ b/Physics/Vehicles/Ball/Models/Materials.meta
@@ -1,8 +1,9 @@
fileFormatVersion: 2
-guid: e809a4525c25f124fb0b63917cc7efbb
+guid: acfd39ede18a32a4a93b383525a057f5
folderAsset: yes
+timeCreated: 1592859477
+licenseType: Pro
DefaultImporter:
- externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
diff --git a/Physics/Vehicles/Ball/Models/Materials/Material.mat b/Physics/Vehicles/Ball/Models/Materials/Material.mat
new file mode 100644
index 0000000..33506f9
Binary files /dev/null and b/Physics/Vehicles/Ball/Models/Materials/Material.mat differ
diff --git a/Physics/Vehicles/Ball/Models/Materials/Material.mat.meta b/Physics/Vehicles/Ball/Models/Materials/Material.mat.meta
new file mode 100644
index 0000000..f2cc994
--- /dev/null
+++ b/Physics/Vehicles/Ball/Models/Materials/Material.mat.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 2860900b979ed4646b39f4b38adbe119
+timeCreated: 1592859477
+licenseType: Pro
+NativeFormatImporter:
+ mainObjectFileID: 2100000
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Physics/Vehicles/Car/CarPhysics.cs b/Physics/Vehicles/Car/CarPhysics.cs
index 3becdcd..7dabf6c 100644
--- a/Physics/Vehicles/Car/CarPhysics.cs
+++ b/Physics/Vehicles/Car/CarPhysics.cs
@@ -128,12 +128,14 @@ private void OnCollisionEnter(Collision collision)
//Debug.Log(collision.gameObject.name + " impulse: " + collision.impulse + " percent damage: " + percentDamage);
}
- onHit?.Invoke(this, collision);
+ if (onHit != null)
+ onHit.Invoke(this, collision);
}
private void OnTriggerEnter(Collider other)
{
//Debug.Log("Triggered " + other.name);
- onTrigger?.Invoke(this, other);
+ if (onTrigger != null)
+ onTrigger.Invoke(this, other);
}
private void OnHealthValueChanged(float value)
@@ -246,7 +248,7 @@ private void CastRays(RaycastHitInfo[] rayResults, float distanceObstacleCheck,
private static RaycastHitInfo GetClosestHitInfo(RaycastHitInfo[] directionRayResults)
{
- RaycastHitInfo bestRay = default;
+ RaycastHitInfo bestRay = new RaycastHitInfo();
if (directionRayResults != null)
{
float closestRay = float.MaxValue;
diff --git a/RailSystemController.cs b/RailSystemController.cs
index 7d8524b..68603e5 100644
--- a/RailSystemController.cs
+++ b/RailSystemController.cs
@@ -21,7 +21,7 @@ public class RailSystemController : MonoBehaviour
void Update()
{
- if (target != null && checkpoints?.Length > 0)
+ if (target != null && checkpoints != null && checkpoints.Length > 0)
{
if (loop && value >= 1)
value = 0;
diff --git a/Shaders/ScreenEffects/FakeObjects.cs b/Shaders/ScreenEffects/FakeObjects.cs
index 9a0efbe..53780bb 100644
--- a/Shaders/ScreenEffects/FakeObjects.cs
+++ b/Shaders/ScreenEffects/FakeObjects.cs
@@ -49,7 +49,8 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (buffer == null || buffer.count != allSquares.Length)
{
- buffer?.Dispose();
+ if (buffer != null)
+ buffer.Dispose();
buffer = new ComputeBuffer(allSquares.Length, sizeof(float) * 3);
}
buffer.SetData(allSquares);
diff --git a/TaskManager/TaskManagerController.cs b/TaskManager/TaskManagerController.cs
index 922f83c..58a3e00 100644
--- a/TaskManager/TaskManagerController.cs
+++ b/TaskManager/TaskManagerController.cs
@@ -1,4 +1,5 @@
-using UnityEngine;
+#if CSHARP_7_3_OR_NEWER
+using UnityEngine;
using System;
using System.Linq;
@@ -225,4 +226,5 @@ public static bool HasTask(TaskWrapper task)
return task != null && (IsQueued(task) || IsRunning(task));
}
}
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
diff --git a/TaskManager/TaskWrapper.cs b/TaskManager/TaskWrapper.cs
index c84a07f..008d369 100644
--- a/TaskManager/TaskWrapper.cs
+++ b/TaskManager/TaskWrapper.cs
@@ -1,4 +1,5 @@
-using System;
+#if CSHARP_7_3_OR_NEWER
+using System;
using System.Threading;
using System.Threading.Tasks;
@@ -78,4 +79,5 @@ public async Task Start(Action onBegin = null, Action
}
}
}
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
diff --git a/UI/BorderController.cs b/UI/BorderController.cs
index cf84720..8638298 100644
--- a/UI/BorderController.cs
+++ b/UI/BorderController.cs
@@ -73,7 +73,8 @@ private void CheckSizeChanged()
{
if (!Mathf.Approximately(rectTransform.rect.width, _prevSize.x) || !Mathf.Approximately(rectTransform.rect.height, _prevSize.y))
{
- onSizeChanged?.Invoke();
+ if (onSizeChanged != null)
+ onSizeChanged.Invoke();
ResetBorders();
_prevSize = rectTransform.rect.size;
@@ -86,7 +87,8 @@ public void SetShownEdges(BorderEdge value)
if (shownEdges != _prevShownEdges)
{
- onEdgesShownChanged?.Invoke();
+ if (onEdgesShownChanged != null)
+ onEdgesShownChanged.Invoke();
ResetBorders();
@@ -102,7 +104,8 @@ public void SetBorderSize(float value)
if (borderSize != _prevBorderSize)
{
- onBorderSizeChanged?.Invoke();
+ if (onBorderSizeChanged != null)
+ onBorderSizeChanged.Invoke();
ResetBorders();
_prevBorderSize = borderSize;
@@ -114,7 +117,8 @@ public void SetDependant(bool value)
if (dependant != _prevDependant)
{
- onDependantChanged?.Invoke();
+ if (onDependantChanged != null)
+ onDependantChanged.Invoke();
if (dependant)
SetBorderSize(borderSize / Mathf.Min(rectTransform.rect.width, rectTransform.rect.height));
@@ -133,7 +137,8 @@ public void SetBorderColor(Color value)
if (borderColor.r != _prevBorderColor.r || borderColor.g != _prevBorderColor.g || borderColor.b != _prevBorderColor.b || borderColor.a != _prevBorderColor.a)
{
- onBorderColorChanged?.Invoke();
+ if (onBorderColorChanged != null)
+ onBorderColorChanged.Invoke();
_prevBorderColor = borderColor;
}
diff --git a/UI/DraggableItem.cs b/UI/DraggableItem.cs
index 8932890..f890d6a 100644
--- a/UI/DraggableItem.cs
+++ b/UI/DraggableItem.cs
@@ -72,12 +72,14 @@ private void Drag(Vector2 delta)
SelfRectTransform.localPosition = ClampToContainer(nextPos.x, nextPos.y);
isDragging = true;
- onDrag?.Invoke();
+ if (onDrag != null)
+ onDrag.Invoke();
}
private void EndDrag()
{
isDragging = false;
- onEndDrag?.Invoke();
+ if (onEndDrag != null)
+ onEndDrag.Invoke();
}
private Vector2 ClampToContainer(float x, float y)
diff --git a/UI/FPSCounter.cs b/UI/FPSCounter.cs
index b000c69..f06b600 100644
--- a/UI/FPSCounter.cs
+++ b/UI/FPSCounter.cs
@@ -4,7 +4,11 @@ namespace UnityHelpers
{
public class FPSCounter : MonoBehaviour
{
+ #if (TextMeshPro)
public TMPro.TextMeshProUGUI fpsText;
+ #else
+ public UnityEngine.UI.Text fpsText;
+ #endif
public int displayEveryNthFrame = 4;
private int lastDisplayed = 0;
private float sum = 0;
@@ -15,7 +19,9 @@ void Update()
sum += 1 / Time.deltaTime;
if (++lastDisplayed % displayEveryNthFrame == 0)
{
- fpsText.text = Mathf.FloorToInt(sum / displayEveryNthFrame).ToString();
+ string output = Mathf.FloorToInt(sum / displayEveryNthFrame).ToString();
+ if (fpsText != null)
+ fpsText.text = output;
sum = 0;
lastDisplayed = 0;
}
diff --git a/UI/FPSCounter.cs.meta b/UI/FPSCounter.cs.meta
index 5dc0551..4ca31bf 100644
--- a/UI/FPSCounter.cs.meta
+++ b/UI/FPSCounter.cs.meta
@@ -1,7 +1,6 @@
fileFormatVersion: 2
-guid: 3c5cd6661eb240048982643a5e122fe0
+guid: b81d514e76df249468f8bdd863ba12d0
MonoImporter:
- externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
diff --git a/UI/OnScreenKeyboard/KeyController.cs b/UI/OnScreenKeyboard/KeyController.cs
index 98ce2e4..7248bb8 100644
--- a/UI/OnScreenKeyboard/KeyController.cs
+++ b/UI/OnScreenKeyboard/KeyController.cs
@@ -1,6 +1,8 @@
using UnityEngine;
using UnityEngine.UI;
+#if (TextMeshPro)
using TMPro;
+#endif
namespace UnityHelpers
{
@@ -10,7 +12,11 @@ public class KeyController : MonoBehaviour
public string lowercaseValue;
public string uppercaseValue;
+ #if (TextMeshPro)
public TextMeshProUGUI label;
+ #else
+ public Text label;
+ #endif
public event KeyClickedHandler onKeyClicked;
public delegate void KeyClickedHandler(string value);
@@ -26,7 +32,8 @@ void Update()
private void Clicked()
{
- onKeyClicked?.Invoke(lowercaseValue);
+ if (onKeyClicked != null)
+ onKeyClicked.Invoke(lowercaseValue);
}
}
}
\ No newline at end of file
diff --git a/UI/OnScreenKeyboard/KeyboardController.cs b/UI/OnScreenKeyboard/KeyboardController.cs
index eea8083..c84431f 100644
--- a/UI/OnScreenKeyboard/KeyboardController.cs
+++ b/UI/OnScreenKeyboard/KeyboardController.cs
@@ -2,7 +2,9 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
+#if (TextMeshPro)
using TMPro;
+#endif
using System.Collections;
namespace UnityHelpers
@@ -12,8 +14,11 @@ public class KeyboardController : MonoBehaviour
private StringBuilder builtOutput = new StringBuilder();
private GameObject currentlySelected;
+ #if (TextMeshPro)
+ private TMP_InputField inputField;
+ #else
private InputField inputField;
- private TMP_InputField tmpInputField;
+ #endif
private int caretPosition, selectionAnchorPosition, selectionFocusPosition;
private KeyController[] keyboardKeys;
@@ -39,12 +44,6 @@ private void CheckCaret()
selectionAnchorPosition = inputField.selectionAnchorPosition;
selectionFocusPosition = inputField.selectionFocusPosition;
}
- else if (tmpInputField != null && eventSystemSelection == tmpInputField.gameObject)
- {
- caretPosition = tmpInputField.caretPosition;
- selectionAnchorPosition = tmpInputField.selectionAnchorPosition;
- selectionFocusPosition = tmpInputField.selectionFocusPosition;
- }
//Debug.Log("Caret Pos: " + caretPosition + " SAP: " + selectionAnchorPosition + " SFP: " + selectionFocusPosition);
}
@@ -53,39 +52,38 @@ private void RefreshInputFields()
var eventSystemSelection = EventSystem.current.currentSelectedGameObject;
if (eventSystemSelection != currentlySelected)
{
- var button = eventSystemSelection?.GetComponent(); //Should change this to be keyboard key component when created
+ KeyController button = null;
+ if (eventSystemSelection != null)
+ button = eventSystemSelection.GetComponent(); //Should change this to be keyboard key component when created
if (button == null)
{
currentlySelected = eventSystemSelection;
- inputField?.onValueChanged.RemoveListener(InputFieldValueChanged);
- tmpInputField?.onValueChanged.RemoveListener(InputFieldValueChanged);
+ if (inputField != null)
+ inputField.onValueChanged.RemoveListener(InputFieldValueChanged);
inputField = null;
- tmpInputField = null;
if (eventSystemSelection != null)
{
+ #if (TextMeshPro)
+ inputField = eventSystemSelection.GetComponent();
+ #else
inputField = eventSystemSelection.GetComponent();
- if (inputField == null)
- tmpInputField = eventSystemSelection.GetComponent();
+ #endif
if (inputField != null)
SetText(inputField.text);
- else if (tmpInputField != null)
- SetText(tmpInputField.text);
- inputField?.onValueChanged.AddListener(InputFieldValueChanged);
- tmpInputField?.onValueChanged.AddListener(InputFieldValueChanged);
+ if (inputField != null)
+ inputField.onValueChanged.AddListener(InputFieldValueChanged);
}
}
}
if (inputField != null)
inputField.text = builtOutput.ToString();
- else if (tmpInputField != null)
- tmpInputField.text = builtOutput.ToString();
}
private void InputFieldValueChanged(string value)
{
@@ -93,7 +91,8 @@ private void InputFieldValueChanged(string value)
}
public void SetText(string value)
{
- builtOutput.Clear();
+ builtOutput.Remove (0, builtOutput.Length);
+ //builtOutput.Clear();
builtOutput.Append(value);
}
@@ -119,13 +118,6 @@ private IEnumerator ReturnCaretPosition(int index)
inputField.selectionFocusPosition = index;
inputField.ForceLabelUpdate();
}
- else if (tmpInputField != null)
- {
- tmpInputField.caretPosition = index;
- tmpInputField.selectionAnchorPosition = index;
- tmpInputField.selectionFocusPosition = index;
- tmpInputField.ForceLabelUpdate();
- }
}
}
}
\ No newline at end of file
diff --git a/UI/SliderValueAdjuster.cs b/UI/SliderValueAdjuster.cs
index 2fc2cab..6daa0d1 100644
--- a/UI/SliderValueAdjuster.cs
+++ b/UI/SliderValueAdjuster.cs
@@ -3,7 +3,7 @@
namespace UnityHelpers
{
- [ExecuteAlways]
+ [ExecuteInEditMode]
public class SliderValueAdjuster : MonoBehaviour
{
private Slider slider;
diff --git a/UI/SliderValueToText.cs b/UI/SliderValueToText.cs
index 242832b..645cc4c 100644
--- a/UI/SliderValueToText.cs
+++ b/UI/SliderValueToText.cs
@@ -3,13 +3,17 @@
namespace UnityHelpers
{
- [ExecuteAlways]
+ [ExecuteInEditMode]
public class SliderValueToText : MonoBehaviour
{
private Slider slider;
private bool sliderErrored, labelErrored;
+ #if (TextMeshPro)
public TMPro.TextMeshProUGUI targetLabel;
+ #else
+ public Text targetLabel;
+ #endif
[Space(10)]
diff --git a/UI/TouchGesturesHandler.cs b/UI/TouchGesturesHandler.cs
index 256d89b..7da1001 100644
--- a/UI/TouchGesturesHandler.cs
+++ b/UI/TouchGesturesHandler.cs
@@ -79,8 +79,8 @@ void Update()
EndPinch();
EndDrag();
- if (highestTouchCount == 1 && Time.time - startTouchTime <= tapDuration && (EventSystem.current.currentSelectedGameObject == null || EventSystem.current.currentSelectedGameObject.GetComponent() == null))
- onUp?.Invoke(prevTouches[0], Vector2.zero);
+ if (onUp != null && highestTouchCount == 1 && Time.time - startTouchTime <= tapDuration && (EventSystem.current.currentSelectedGameObject == null || EventSystem.current.currentSelectedGameObject.GetComponent() == null))
+ onUp.Invoke(prevTouches[0], Vector2.zero);
startTouchTime = -1;
highestTouchCount = 0;
@@ -95,19 +95,22 @@ private void Down(Vector2 position)
{
Vector2 delta = position - prevTouches[0];
prevTouches[0] = position;
- onDown?.Invoke(position, delta);
+ if (onDown != null)
+ onDown.Invoke(position, delta);
}
private void Drag(Vector2 position)
{
isDragging = true;
Vector2 delta = position - prevTouches[0];
prevTouches[0] = position;
- onDrag?.Invoke(position, delta);
+ if (onDrag != null)
+ onDrag.Invoke(position, delta);
}
private void EndDrag()
{
isDragging = false;
- onEndDrag?.Invoke(prevTouches[0], Vector2.zero);
+ if (onEndDrag != null)
+ onEndDrag.Invoke(prevTouches[0], Vector2.zero);
}
private void StartPinch(Vector2 pos1, Vector2 pos2)
@@ -116,13 +119,14 @@ private void StartPinch(Vector2 pos1, Vector2 pos2)
prevTouches[0] = pos1;
prevTouches[1] = pos2;
- onPinchStart?.Invoke(pos1, pos2, 0, 0);
+ if (onPinchStart != null)
+ onPinchStart.Invoke(pos1, pos2, 0, 0);
}
private void Pinching(Vector2 pos1, Vector2 pos2)
{
Vector2 dir1 = (pos2 - pos1).normalized;
Vector2 dir2 = (prevTouches[1] - prevTouches[0]).normalized;
- float rot = Vector2.SignedAngle(dir2, dir1);
+ float rot = dir2.SignedAngle(dir1);
float oldDistance = Vector2.Distance(prevTouches[0], prevTouches[1]);
float newDistance = Vector2.Distance(pos1, pos2);
@@ -130,12 +134,14 @@ private void Pinching(Vector2 pos1, Vector2 pos2)
prevTouches[1] = pos2;
float delta = newDistance - oldDistance;
- onPinch?.Invoke(pos1, pos2, delta, rot);
+ if (onPinch != null)
+ onPinch.Invoke(pos1, pos2, delta, rot);
}
private void EndPinch()
{
isPinching = false;
- onPinchEnd?.Invoke(prevTouches[0], prevTouches[1], 0, 0);
+ if (onPinchEnd != null)
+ onPinchEnd.Invoke(prevTouches[0], prevTouches[1], 0, 0);
}
private Vector2 GetTouchAsLocal(int touchIndex)
diff --git a/ValuesManager/ValueWrapper.cs b/ValuesManager/ValueWrapper.cs
index acc1796..281f270 100644
--- a/ValuesManager/ValueWrapper.cs
+++ b/ValuesManager/ValueWrapper.cs
@@ -88,7 +88,7 @@ public float GetAxis()
public void RemoveAxis()
{
storedTypes &= ~CommonType.axis;
- axis = default;
+ axis = 0;
}
public void SetToggle(bool value)
@@ -106,7 +106,7 @@ public bool GetToggle()
public void RemoveToggle()
{
storedTypes &= ~CommonType.toggle;
- toggle = default;
+ toggle = false;
}
public void SetDirection(Vector3 value)
@@ -124,7 +124,7 @@ public Vector3 GetDirection()
public void RemoveDirection()
{
storedTypes &= ~CommonType.direction;
- direction = default;
+ direction = Vector3.zero;
}
public void SetPoint(Vector3 value)
@@ -142,7 +142,7 @@ public Vector3 GetPoint()
public void RemovePoint()
{
storedTypes &= ~CommonType.point;
- point = default;
+ point = Vector3.zero;
}
public void SetOrientation(Quaternion value)
@@ -160,7 +160,7 @@ public Quaternion GetOrientation()
public void RemoveOrientation()
{
storedTypes &= ~CommonType.orientation;
- orientation = default;
+ orientation = Quaternion.identity;
}
}
}
\ No newline at end of file
diff --git a/geometry3Sharp b/geometry3Sharp
deleted file mode 160000
index 7982934..0000000
--- a/geometry3Sharp
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 79829341d6c225375128c32cd4720dd48f970c6e