com.wallstop-studios.unity-helpers 1.0.0-rc4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +63 -0
- package/CHANGELOG.md +0 -0
- package/CHANGELOG.md.meta +7 -0
- package/Editor/AnimationCreator.cs +218 -0
- package/Editor/AnimationCreator.cs.meta +11 -0
- package/Editor/AnimationEventEditor.cs +742 -0
- package/Editor/AnimationEventEditor.cs.meta +11 -0
- package/Editor/PrefabCheckWizard.cs +140 -0
- package/Editor/PrefabCheckWizard.cs.meta +11 -0
- package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef +16 -0
- package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef.meta +7 -0
- package/Editor.meta +8 -0
- package/LICENSE +21 -0
- package/LICENSE.md +7 -0
- package/LICENSE.md.meta +7 -0
- package/LICENSE.meta +7 -0
- package/README.md +2 -0
- package/README.md.meta +7 -0
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs +102 -0
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs +43 -0
- package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs +85 -0
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/KSerializableAttribute.cs +23 -0
- package/Runtime/Core/Attributes/KSerializableAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs +33 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ParentComponent.cs +85 -0
- package/Runtime/Core/Attributes/ParentComponent.cs.meta +11 -0
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs +8 -0
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/RelationalComponentExtensions.cs +14 -0
- package/Runtime/Core/Attributes/RelationalComponentExtensions.cs.meta +11 -0
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +89 -0
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs +66 -0
- package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes.meta +8 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs +91 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs +180 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs +274 -0
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs +79 -0
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters.meta +8 -0
- package/Runtime/Core/DataStructure/Circle.cs +50 -0
- package/Runtime/Core/DataStructure/Circle.cs.meta +11 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +130 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +11 -0
- package/Runtime/Core/DataStructure/ISpatialTree.cs +58 -0
- package/Runtime/Core/DataStructure/ISpatialTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/KDTree.cs +186 -0
- package/Runtime/Core/DataStructure/KDTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/QuadTree.cs +184 -0
- package/Runtime/Core/DataStructure/QuadTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/RTree.cs +247 -0
- package/Runtime/Core/DataStructure/RTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/StringWrapper.cs +90 -0
- package/Runtime/Core/DataStructure/StringWrapper.cs.meta +11 -0
- package/Runtime/Core/DataStructure/TimedCache.cs +50 -0
- package/Runtime/Core/DataStructure/TimedCache.cs.meta +11 -0
- package/Runtime/Core/DataStructure.meta +8 -0
- package/Runtime/Core/Extension/AnimatorExtensions.cs +25 -0
- package/Runtime/Core/Extension/AnimatorExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/CircleExtensions.cs +25 -0
- package/Runtime/Core/Extension/CircleExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/ColorExtensions.cs +72 -0
- package/Runtime/Core/Extension/ColorExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/DictionaryExtensions.cs +173 -0
- package/Runtime/Core/Extension/DictionaryExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/DirectionExtensions.cs +210 -0
- package/Runtime/Core/Extension/DirectionExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/HashSetExtensions.cs +12 -0
- package/Runtime/Core/Extension/HashSetExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/IEnumerableExtensions.cs +109 -0
- package/Runtime/Core/Extension/IEnumerableExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/IListExtensions.cs +49 -0
- package/Runtime/Core/Extension/IListExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/LoggingExtensions.cs +196 -0
- package/Runtime/Core/Extension/LoggingExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/RandomExtensions.cs +110 -0
- package/Runtime/Core/Extension/RandomExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/StringExtensions.cs +76 -0
- package/Runtime/Core/Extension/StringExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/UnityExtensions.cs +1409 -0
- package/Runtime/Core/Extension/UnityExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension.meta +8 -0
- package/Runtime/Core/Helper/AssignUtilities.cs +14 -0
- package/Runtime/Core/Helper/AssignUtilities.cs.meta +11 -0
- package/Runtime/Core/Helper/Enumerables.cs +17 -0
- package/Runtime/Core/Helper/Enumerables.cs.meta +11 -0
- package/Runtime/Core/Helper/Geometry.cs +26 -0
- package/Runtime/Core/Helper/Geometry.cs.meta +11 -0
- package/Runtime/Core/Helper/Helpers.cs +1092 -0
- package/Runtime/Core/Helper/Helpers.cs.meta +11 -0
- package/Runtime/Core/Helper/IterationHelpers.cs +32 -0
- package/Runtime/Core/Helper/IterationHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/LifetimeHelpers.cs +12 -0
- package/Runtime/Core/Helper/LifetimeHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/Objects.cs +447 -0
- package/Runtime/Core/Helper/Objects.cs.meta +11 -0
- package/Runtime/Core/Helper/SpriteHelpers.cs +53 -0
- package/Runtime/Core/Helper/SpriteHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/StringInList.cs +31 -0
- package/Runtime/Core/Helper/StringInList.cs.meta +11 -0
- package/Runtime/Core/Helper/WallMath.cs +75 -0
- package/Runtime/Core/Helper/WallMath.cs.meta +11 -0
- package/Runtime/Core/Helper.meta +8 -0
- package/Runtime/Core/Math/Line.cs +51 -0
- package/Runtime/Core/Math/Line.cs.meta +11 -0
- package/Runtime/Core/Math/Parabola.cs +44 -0
- package/Runtime/Core/Math/Parabola.cs.meta +11 -0
- package/Runtime/Core/Math/PointPolygonCheck.cs +25 -0
- package/Runtime/Core/Math/PointPolygonCheck.cs.meta +11 -0
- package/Runtime/Core/Math/Range.cs +56 -0
- package/Runtime/Core/Math/Range.cs.meta +11 -0
- package/Runtime/Core/Math/XXHash.cs +308 -0
- package/Runtime/Core/Math/XXHash.cs.meta +11 -0
- package/Runtime/Core/Math.meta +8 -0
- package/Runtime/Core/Model/Direction.cs +26 -0
- package/Runtime/Core/Model/Direction.cs.meta +11 -0
- package/Runtime/Core/Model.meta +8 -0
- package/Runtime/Core/OneOf/FastOneOf.cs +145 -0
- package/Runtime/Core/OneOf/FastOneOf.cs.meta +11 -0
- package/Runtime/Core/OneOf/None.cs +6 -0
- package/Runtime/Core/OneOf/None.cs.meta +11 -0
- package/Runtime/Core/OneOf.meta +8 -0
- package/Runtime/Core/Random/AbstractRandom.cs +537 -0
- package/Runtime/Core/Random/AbstractRandom.cs.meta +11 -0
- package/Runtime/Core/Random/IRandom.cs +141 -0
- package/Runtime/Core/Random/IRandom.cs.meta +11 -0
- package/Runtime/Core/Random/NativePcgRandom.cs +97 -0
- package/Runtime/Core/Random/NativePcgRandom.cs.meta +11 -0
- package/Runtime/Core/Random/PcgRandom.cs +142 -0
- package/Runtime/Core/Random/PcgRandom.cs.meta +11 -0
- package/Runtime/Core/Random/RandomState.cs +92 -0
- package/Runtime/Core/Random/RandomState.cs.meta +11 -0
- package/Runtime/Core/Random/RandomUtilities.cs +26 -0
- package/Runtime/Core/Random/RandomUtilities.cs.meta +11 -0
- package/Runtime/Core/Random/SquirrelRandom.cs +82 -0
- package/Runtime/Core/Random/SquirrelRandom.cs.meta +11 -0
- package/Runtime/Core/Random/SystemRandom.cs +110 -0
- package/Runtime/Core/Random/SystemRandom.cs.meta +11 -0
- package/Runtime/Core/Random/ThreadLocalRandom.cs +11 -0
- package/Runtime/Core/Random/ThreadLocalRandom.cs.meta +11 -0
- package/Runtime/Core/Random/UnityRandom.cs +24 -0
- package/Runtime/Core/Random/UnityRandom.cs.meta +11 -0
- package/Runtime/Core/Random/XorShiftRandom.cs +45 -0
- package/Runtime/Core/Random/XorShiftRandom.cs.meta +11 -0
- package/Runtime/Core/Random.meta +8 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs +32 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs.meta +11 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs +32 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs.meta +11 -0
- package/Runtime/Core/Serialization/JsonConverters.meta +8 -0
- package/Runtime/Core/Serialization/Serializer.cs +125 -0
- package/Runtime/Core/Serialization/Serializer.cs.meta +11 -0
- package/Runtime/Core/Serialization.meta +8 -0
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +102 -0
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs.meta +11 -0
- package/Runtime/Core/Threading.meta +8 -0
- package/Runtime/Core.meta +8 -0
- package/Runtime/Protobuf-Net/System.Buffers.dll +0 -0
- package/Runtime/Protobuf-Net/System.Buffers.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Collections.Immutable.dll +0 -0
- package/Runtime/Protobuf-Net/System.Collections.Immutable.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll +0 -0
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll.meta +33 -0
- package/Runtime/Protobuf-Net/protobuf-net.Core.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.Core.dll.meta +33 -0
- package/Runtime/Protobuf-Net/protobuf-net.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.dll.meta +33 -0
- package/Runtime/Protobuf-Net.meta +8 -0
- package/Runtime/Utils/AnimationEventEqualityComparer.cs +149 -0
- package/Runtime/Utils/AnimationEventEqualityComparer.cs.meta +11 -0
- package/Runtime/Utils/AnimatorEnumStateMachine.cs +80 -0
- package/Runtime/Utils/AnimatorEnumStateMachine.cs.meta +11 -0
- package/Runtime/Utils/Buffers.cs +32 -0
- package/Runtime/Utils/Buffers.cs.meta +11 -0
- package/Runtime/Utils/CircleLineRenderer.cs +122 -0
- package/Runtime/Utils/CircleLineRenderer.cs.meta +11 -0
- package/Runtime/Utils/Oscillator.cs +25 -0
- package/Runtime/Utils/Oscillator.cs.meta +11 -0
- package/Runtime/Utils/SetTextureImportData.cs +67 -0
- package/Runtime/Utils/SetTextureImportData.cs.meta +11 -0
- package/Runtime/Utils.meta +8 -0
- package/Runtime/WallstopStudios.UnityHelpers.asmdef +14 -0
- package/Runtime/WallstopStudios.UnityHelpers.asmdef.meta +7 -0
- package/Runtime.meta +8 -0
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef +17 -0
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef.meta +7 -0
- package/Tests/Editor.meta +8 -0
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +106 -0
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures.meta +8 -0
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +14 -0
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +14 -0
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +76 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +141 -0
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs.meta +11 -0
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/Performance.meta +8 -0
- package/Tests/Runtime/Random/PcgRandomTests.cs +9 -0
- package/Tests/Runtime/Random/PcgRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/RandomTestBase.cs +117 -0
- package/Tests/Runtime/Random/RandomTestBase.cs.meta +11 -0
- package/Tests/Runtime/Random/SquirrelRandomTests.cs +9 -0
- package/Tests/Runtime/Random/SquirrelRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/SystemRandomTests.cs +10 -0
- package/Tests/Runtime/Random/SystemRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/UnityRandomTests.cs +9 -0
- package/Tests/Runtime/Random/UnityRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/XorShiftRandomTests.cs +9 -0
- package/Tests/Runtime/Random/XorShiftRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random.meta +8 -0
- package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef +22 -0
- package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef.meta +7 -0
- package/Tests/Runtime.meta +8 -0
- package/Tests.meta +8 -0
- package/Third Party Notices.md +1 -0
- package/Third Party Notices.md.meta +7 -0
- package/package.json +35 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.DataStructure
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Concurrent;
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
Used to cache strings, meant to be used in place of strings as keys for when a Dictionary
|
|
8
|
+
has a known set of values
|
|
9
|
+
*/
|
|
10
|
+
public sealed class StringWrapper : IEquatable<StringWrapper>, IComparable<StringWrapper>
|
|
11
|
+
{
|
|
12
|
+
private static readonly ConcurrentDictionary<string, StringWrapper> Cache = new();
|
|
13
|
+
|
|
14
|
+
public readonly string value;
|
|
15
|
+
|
|
16
|
+
private readonly int _hashCode;
|
|
17
|
+
|
|
18
|
+
private StringWrapper(string value)
|
|
19
|
+
{
|
|
20
|
+
this.value = value;
|
|
21
|
+
_hashCode = value?.GetHashCode() ?? 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static StringWrapper Get(string value)
|
|
25
|
+
{
|
|
26
|
+
return Cache.GetOrAdd(value, key => new StringWrapper(key));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static void Remove(string value)
|
|
30
|
+
{
|
|
31
|
+
_ = Cache.TryRemove(value, out _);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public bool Equals(StringWrapper other)
|
|
35
|
+
{
|
|
36
|
+
if (ReferenceEquals(this, other))
|
|
37
|
+
{
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (ReferenceEquals(other, null))
|
|
42
|
+
{
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (_hashCode != other._hashCode)
|
|
47
|
+
{
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return string.Equals(value, other.value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public int CompareTo(StringWrapper other)
|
|
55
|
+
{
|
|
56
|
+
if (ReferenceEquals(this, other))
|
|
57
|
+
{
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (ReferenceEquals(other, null))
|
|
62
|
+
{
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
int comparison = _hashCode.CompareTo(other._hashCode);
|
|
67
|
+
if (comparison != 0)
|
|
68
|
+
{
|
|
69
|
+
return comparison;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return string.Compare(value, other.value, StringComparison.Ordinal);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public override int GetHashCode()
|
|
76
|
+
{
|
|
77
|
+
return _hashCode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public override bool Equals(object other)
|
|
81
|
+
{
|
|
82
|
+
return Equals(other as StringWrapper);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public override string ToString()
|
|
86
|
+
{
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.DataStructure
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using Helper;
|
|
5
|
+
using Random;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
public sealed class TimedCache<T>
|
|
9
|
+
{
|
|
10
|
+
public T Value
|
|
11
|
+
{
|
|
12
|
+
get
|
|
13
|
+
{
|
|
14
|
+
if (!_lastRead.HasValue || Helpers.HasEnoughTimePassed(_lastRead.Value, _cacheTtl))
|
|
15
|
+
{
|
|
16
|
+
Reset();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return _value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private readonly Func<T> _valueProducer;
|
|
24
|
+
private readonly float _cacheTtl;
|
|
25
|
+
|
|
26
|
+
private float? _lastRead;
|
|
27
|
+
private T _value;
|
|
28
|
+
|
|
29
|
+
public TimedCache(Func<T> valueProducer, float cacheTtl, bool useJitter = false)
|
|
30
|
+
{
|
|
31
|
+
_valueProducer = valueProducer ?? throw new ArgumentNullException(nameof(valueProducer));
|
|
32
|
+
if (cacheTtl < 0)
|
|
33
|
+
{
|
|
34
|
+
throw new ArgumentException(nameof(cacheTtl));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_cacheTtl = cacheTtl;
|
|
38
|
+
if (useJitter && 0 <_cacheTtl)
|
|
39
|
+
{
|
|
40
|
+
_cacheTtl += PcgRandom.Instance.NextFloat(_cacheTtl);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public void Reset()
|
|
45
|
+
{
|
|
46
|
+
_value = _valueProducer();
|
|
47
|
+
_lastRead = Time.time;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Extension
|
|
2
|
+
{
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
|
|
5
|
+
public static class AnimatorExtensions
|
|
6
|
+
{
|
|
7
|
+
public static void ResetTriggers(this Animator animator)
|
|
8
|
+
{
|
|
9
|
+
if (!animator || !animator.isActiveAndEnabled)
|
|
10
|
+
{
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
foreach (AnimatorControllerParameter animatorParameter in animator.parameters)
|
|
15
|
+
{
|
|
16
|
+
if (animatorParameter.type != AnimatorControllerParameterType.Trigger)
|
|
17
|
+
{
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
animator.ResetTrigger(animatorParameter.name);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Extension
|
|
2
|
+
{
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using DataStructure;
|
|
5
|
+
using DataStructure.Adapters;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
public static class CircleExtensions
|
|
9
|
+
{
|
|
10
|
+
public static IEnumerable<FastVector3Int> EnumerateArea(this Circle circle, int z = 0)
|
|
11
|
+
{
|
|
12
|
+
for (int x = (int) -circle.radius; x < circle.radius; ++x)
|
|
13
|
+
{
|
|
14
|
+
for (int y = (int) -circle.radius; y < circle.radius; ++y)
|
|
15
|
+
{
|
|
16
|
+
Vector2 point = new(x, y);
|
|
17
|
+
if (circle.Contains(point))
|
|
18
|
+
{
|
|
19
|
+
yield return new FastVector3Int(x, y, z);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Extension
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using Random;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
|
|
7
|
+
// https://sharpsnippets.wordpress.com/2014/03/11/c-extension-complementary-color/
|
|
8
|
+
public static class ColorExtensions
|
|
9
|
+
{
|
|
10
|
+
public static Color GetComplement(this Color source, IRandom random = null, float variance = 0f)
|
|
11
|
+
{
|
|
12
|
+
Color inputColor = source;
|
|
13
|
+
//if RGB values are close to each other by a diff less than 10%, then if RGB values are lighter side, decrease the blue by 50% (eventually it will increase in conversion below), if RBB values are on darker side, decrease yellow by about 50% (it will increase in conversion)
|
|
14
|
+
float avgColorValue = (source.r + source.g + source.b) / 3;
|
|
15
|
+
float rDiff = Math.Abs(source.r - avgColorValue);
|
|
16
|
+
float gDiff = Math.Abs(source.g - avgColorValue);
|
|
17
|
+
float bDiff = Math.Abs(source.b - avgColorValue);
|
|
18
|
+
const float greyDelta = 20 / 255f;
|
|
19
|
+
if (rDiff < greyDelta && gDiff < greyDelta && bDiff < greyDelta) //The color is a shade of gray
|
|
20
|
+
{
|
|
21
|
+
if (avgColorValue < 123 / 255f) //color is dark
|
|
22
|
+
{
|
|
23
|
+
inputColor.b = 220 / 255f;
|
|
24
|
+
inputColor.g = 230 / 255f;
|
|
25
|
+
inputColor.r = 50 / 255f;
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
{
|
|
29
|
+
inputColor.r = 255 / 255f;
|
|
30
|
+
inputColor.g = 255 / 255f;
|
|
31
|
+
inputColor.b = 50 / 255f;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (random != null)
|
|
36
|
+
{
|
|
37
|
+
if (variance != 0)
|
|
38
|
+
{
|
|
39
|
+
variance = Math.Abs(variance);
|
|
40
|
+
|
|
41
|
+
float minR = Clamp(inputColor.r - variance);
|
|
42
|
+
float maxR = Clamp(inputColor.r + variance);
|
|
43
|
+
inputColor.r = random.NextFloat(minR, maxR);
|
|
44
|
+
|
|
45
|
+
float minG = Clamp(inputColor.g - variance);
|
|
46
|
+
float maxG = Clamp(inputColor.g + variance);
|
|
47
|
+
inputColor.g = random.NextFloat(minG, maxG);
|
|
48
|
+
|
|
49
|
+
float minB = Clamp(inputColor.b - variance);
|
|
50
|
+
float maxB = Clamp(inputColor.b + variance);
|
|
51
|
+
inputColor.b = random.NextFloat(minB, maxB);
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
inputColor.r *= random.NextFloat(1 / inputColor.r);
|
|
56
|
+
inputColor.g *= random.NextFloat(1 / inputColor.g);
|
|
57
|
+
inputColor.b *= random.NextFloat(1 / inputColor.b);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Color.RGBToHSV(inputColor, out float h, out float s, out float v);
|
|
62
|
+
h = h < 0.5f ? h + 0.5f : h - 0.5f;
|
|
63
|
+
Color result = Color.HSVToRGB(h, s, v);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private static float Clamp(float value)
|
|
68
|
+
{
|
|
69
|
+
return Math.Clamp(value, 0, 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Extension
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Linq;
|
|
6
|
+
|
|
7
|
+
public static class DictionaryExtensions
|
|
8
|
+
{
|
|
9
|
+
public static V GetOrAdd<K, V>(this IDictionary<K, V> dictionary, K key, Func<V> valueProducer)
|
|
10
|
+
{
|
|
11
|
+
if (dictionary.TryGetValue(key, out V result))
|
|
12
|
+
{
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return dictionary[key] = valueProducer();
|
|
17
|
+
}
|
|
18
|
+
public static V GetOrAdd<K, V>(this IDictionary<K, V> dictionary, K key, Func<K, V> valueProducer)
|
|
19
|
+
{
|
|
20
|
+
if (dictionary.TryGetValue(key, out V result))
|
|
21
|
+
{
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return dictionary[key] = valueProducer(key);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static V GetOrElse<K, V>(this IDictionary<K, V> dictionary, K key, Func<V> valueProducer)
|
|
29
|
+
{
|
|
30
|
+
if (dictionary.TryGetValue(key, out V value))
|
|
31
|
+
{
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
return valueProducer.Invoke();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static V GetOrElse<K, V>(this IDictionary<K, V> dictionary, K key, Func<K, V> valueProducer)
|
|
38
|
+
{
|
|
39
|
+
if (dictionary.TryGetValue(key, out V value))
|
|
40
|
+
{
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return valueProducer.Invoke(key);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static V GetOrAdd<K, V>(this IDictionary<K, V> dictionary, K key) where V : new()
|
|
48
|
+
{
|
|
49
|
+
if (dictionary.TryGetValue(key, out V result))
|
|
50
|
+
{
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return dictionary[key] = new V();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static V GetOrElse<K, V>(this IDictionary<K, V> dictionary, K key, V value)
|
|
58
|
+
{
|
|
59
|
+
return GetOrElse(dictionary, key, () => value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public static bool Remove<K, V>(this IDictionary<K, V> dictionary, K key, out V value)
|
|
63
|
+
{
|
|
64
|
+
if (dictionary.TryGetValue(key, out value))
|
|
65
|
+
{
|
|
66
|
+
return dictionary.Remove(key);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static V AddOrUpdate<K, V>(this IDictionary<K, V> dictionary, K key, Func<K, V> creator, Func<K, V, V> updater)
|
|
72
|
+
{
|
|
73
|
+
V latest = dictionary.TryGetValue(key, out V value) ? updater(key, value) : creator(key);
|
|
74
|
+
dictionary[key] = latest;
|
|
75
|
+
return latest;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public static Dictionary<K, V> Merge<K, V>(this IDictionary<K, V> lhs, IDictionary<K, V> rhs)
|
|
79
|
+
{
|
|
80
|
+
Dictionary<K, V> result = new Dictionary<K, V>(lhs.Count);
|
|
81
|
+
foreach (KeyValuePair<K, V> kvp in lhs)
|
|
82
|
+
{
|
|
83
|
+
if (rhs.ContainsKey(kvp.Key))
|
|
84
|
+
{
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
result[kvp.Key] = kvp.Value;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
foreach (KeyValuePair<K, V> kvp in rhs)
|
|
92
|
+
{
|
|
93
|
+
result[kvp.Key] = kvp.Value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// <summary>
|
|
100
|
+
/// </summary>
|
|
101
|
+
/// <typeparam name="K">Key type.</typeparam>
|
|
102
|
+
/// <typeparam name="V">Value type.</typeparam>
|
|
103
|
+
/// <param name="lhs">Basis dictionary.</param>
|
|
104
|
+
/// <param name="rhs">Changed dictionary.</param>
|
|
105
|
+
/// <returns>All elements of rhs that either don't exist in or are different from lhs</returns>
|
|
106
|
+
public static Dictionary<K, V> Difference<K, V>(this IDictionary<K, V> lhs, IDictionary<K, V> rhs)
|
|
107
|
+
{
|
|
108
|
+
Dictionary<K, V> result = new Dictionary<K, V>(rhs.Count);
|
|
109
|
+
foreach (KeyValuePair<K, V> kvp in rhs)
|
|
110
|
+
{
|
|
111
|
+
K key = kvp.Key;
|
|
112
|
+
V existing;
|
|
113
|
+
if (lhs.TryGetValue(key, out existing))
|
|
114
|
+
{
|
|
115
|
+
if (Equals(existing, kvp.Value))
|
|
116
|
+
{
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
result[key] = kvp.Value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public static Dictionary<V, K> Reverse<K, V>(this IDictionary<K, V> dictionary)
|
|
128
|
+
{
|
|
129
|
+
Dictionary<V, K> output = new Dictionary<V, K>(dictionary.Count);
|
|
130
|
+
foreach (KeyValuePair<K, V> entry in dictionary)
|
|
131
|
+
{
|
|
132
|
+
output[entry.Value] = entry.Key;
|
|
133
|
+
}
|
|
134
|
+
return output;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public static Dictionary<K, V> ToDictionary<K, V>(this IDictionary<K, V> dictionary)
|
|
138
|
+
{
|
|
139
|
+
return new Dictionary<K, V>(dictionary);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public static Dictionary<K, V> ToDictionary<K, V>(this IEnumerable<KeyValuePair<K, V>> prettyMuchADictionary)
|
|
143
|
+
{
|
|
144
|
+
return prettyMuchADictionary.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public static bool ContentEquals<K, V>(this IDictionary<K, V> dictionary, IDictionary<K, V> other)
|
|
148
|
+
{
|
|
149
|
+
if (ReferenceEquals(dictionary, other))
|
|
150
|
+
{
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (ReferenceEquals(dictionary, null) || ReferenceEquals(other, null))
|
|
155
|
+
{
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (dictionary.Count != other.Count)
|
|
160
|
+
{
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return !dictionary.Except(other).Any();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public static void Deconstruct<K, V>(this KeyValuePair<K, V> kvp, out K key, out V value)
|
|
168
|
+
{
|
|
169
|
+
key = kvp.Key;
|
|
170
|
+
value = kvp.Value;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|