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,45 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Random
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.Serialization;
|
|
5
|
+
|
|
6
|
+
[Serializable]
|
|
7
|
+
public sealed class XorShiftRandom : AbstractRandom
|
|
8
|
+
{
|
|
9
|
+
public static IRandom Instance => ThreadLocalRandom<XorShiftRandom>.Instance;
|
|
10
|
+
public override RandomState InternalState => new(_state, 0, _cachedGaussian);
|
|
11
|
+
|
|
12
|
+
[DataMember(Name = "State")]
|
|
13
|
+
private uint _state;
|
|
14
|
+
|
|
15
|
+
public XorShiftRandom() : this(Guid.NewGuid().GetHashCode())
|
|
16
|
+
{
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public XorShiftRandom(int state)
|
|
20
|
+
{
|
|
21
|
+
_state = unchecked((uint)state);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public XorShiftRandom(RandomState state)
|
|
25
|
+
{
|
|
26
|
+
_state = unchecked((uint)state.State1);
|
|
27
|
+
_cachedGaussian = state.Gaussian;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override uint NextUint()
|
|
31
|
+
{
|
|
32
|
+
uint state = _state;
|
|
33
|
+
state ^= state << 13;
|
|
34
|
+
state ^= state >> 17;
|
|
35
|
+
state ^= state << 5;
|
|
36
|
+
_state = state;
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public override IRandom Copy()
|
|
41
|
+
{
|
|
42
|
+
return new XorShiftRandom(InternalState);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Serialization.JsonConverters
|
|
2
|
+
{
|
|
3
|
+
using Extension;
|
|
4
|
+
using Newtonsoft.Json;
|
|
5
|
+
using Newtonsoft.Json.Linq;
|
|
6
|
+
using System;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
|
|
9
|
+
public sealed class Vector2Converter : JsonConverter
|
|
10
|
+
{
|
|
11
|
+
public static readonly Vector2Converter Instance = new Vector2Converter();
|
|
12
|
+
|
|
13
|
+
private Vector2Converter() { }
|
|
14
|
+
|
|
15
|
+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
|
16
|
+
{
|
|
17
|
+
JToken.FromObject(((Vector2)value).ToJsonString()).WriteTo(writer);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
|
21
|
+
JsonSerializer serializer)
|
|
22
|
+
{
|
|
23
|
+
object instance = serializer.Deserialize(reader);
|
|
24
|
+
return JsonConvert.DeserializeObject<Vector2>(instance.ToString());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public override bool CanConvert(Type objectType)
|
|
28
|
+
{
|
|
29
|
+
return objectType == typeof(Vector2);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Serialization.JsonConverters
|
|
2
|
+
{
|
|
3
|
+
using Extension;
|
|
4
|
+
using Newtonsoft.Json;
|
|
5
|
+
using Newtonsoft.Json.Linq;
|
|
6
|
+
using System;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
|
|
9
|
+
public sealed class Vector3Converter : JsonConverter
|
|
10
|
+
{
|
|
11
|
+
public static readonly Vector3Converter Instance = new Vector3Converter();
|
|
12
|
+
|
|
13
|
+
private Vector3Converter() { }
|
|
14
|
+
|
|
15
|
+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
|
16
|
+
{
|
|
17
|
+
JToken.FromObject(((Vector3)value).ToJsonString()).WriteTo(writer);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
|
21
|
+
JsonSerializer serializer)
|
|
22
|
+
{
|
|
23
|
+
object instance = serializer.Deserialize(reader);
|
|
24
|
+
return JsonConvert.DeserializeObject<Vector3>(instance.ToString());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public override bool CanConvert(Type objectType)
|
|
28
|
+
{
|
|
29
|
+
return objectType == typeof(Vector3);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Serialization
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.ComponentModel;
|
|
5
|
+
using Extension;
|
|
6
|
+
using JsonConverters;
|
|
7
|
+
using Newtonsoft.Json;
|
|
8
|
+
using Newtonsoft.Json.Converters;
|
|
9
|
+
using System.IO;
|
|
10
|
+
using System.Runtime.Serialization.Formatters.Binary;
|
|
11
|
+
using System.Text;
|
|
12
|
+
using UnityEngine;
|
|
13
|
+
|
|
14
|
+
internal static class SerializerEncoding
|
|
15
|
+
{
|
|
16
|
+
public static readonly Encoding Encoding = Encoding.Default;
|
|
17
|
+
|
|
18
|
+
public static readonly JsonConverter[] Converters =
|
|
19
|
+
{new StringEnumConverter(), Vector3Converter.Instance, Vector2Converter.Instance};
|
|
20
|
+
|
|
21
|
+
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
|
22
|
+
{
|
|
23
|
+
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
24
|
+
Converters = Converters
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public enum SerializationType
|
|
30
|
+
{
|
|
31
|
+
SystemBinary,
|
|
32
|
+
Protobuf,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static class Serializer
|
|
36
|
+
{
|
|
37
|
+
public static T Deserialize<T>(byte[] serialized, SerializationType serializationType)
|
|
38
|
+
{
|
|
39
|
+
switch (serializationType)
|
|
40
|
+
{
|
|
41
|
+
case SerializationType.SystemBinary:
|
|
42
|
+
return BinaryDeserialize<T>(serialized);
|
|
43
|
+
case SerializationType.Protobuf:
|
|
44
|
+
return ProtoDeserialize<T>(serialized);
|
|
45
|
+
default:
|
|
46
|
+
throw new InvalidEnumArgumentException(nameof(serializationType), (int)serializationType, typeof(SerializationType));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static byte[] Serialize<T>(T instance, SerializationType serializationType)
|
|
51
|
+
{
|
|
52
|
+
switch (serializationType)
|
|
53
|
+
{
|
|
54
|
+
case SerializationType.SystemBinary:
|
|
55
|
+
return BinarySerialize(instance);
|
|
56
|
+
case SerializationType.Protobuf:
|
|
57
|
+
return ProtoSerialize(instance);
|
|
58
|
+
default:
|
|
59
|
+
throw new InvalidEnumArgumentException(nameof(serializationType), (int)serializationType, typeof(SerializationType));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public static T BinaryDeserialize<T>(byte[] data)
|
|
64
|
+
{
|
|
65
|
+
using MemoryStream memoryStream = new(data);
|
|
66
|
+
BinaryFormatter binaryFormatter = new();
|
|
67
|
+
memoryStream.Position = 0;
|
|
68
|
+
return (T)binaryFormatter.Deserialize(memoryStream);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static byte[] BinarySerialize<T>(T input)
|
|
72
|
+
{
|
|
73
|
+
using MemoryStream memoryStream = new();
|
|
74
|
+
BinaryFormatter binaryFormatter = new();
|
|
75
|
+
binaryFormatter.Serialize(memoryStream, input);
|
|
76
|
+
return memoryStream.ToArray();
|
|
77
|
+
}
|
|
78
|
+
public static T ProtoDeserialize<T>(byte[] data)
|
|
79
|
+
{
|
|
80
|
+
using MemoryStream memoryStream = new(data);
|
|
81
|
+
return ProtoBuf.Serializer.Deserialize<T>(memoryStream);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public static T ProtoDeserialize<T>(byte[] data, Type type)
|
|
85
|
+
{
|
|
86
|
+
using MemoryStream memoryStream = new(data);
|
|
87
|
+
return (T) ProtoBuf.Serializer.Deserialize(type, memoryStream);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public static byte[] ProtoSerialize<T>(T input)
|
|
91
|
+
{
|
|
92
|
+
using MemoryStream memoryStream = new();
|
|
93
|
+
ProtoBuf.Serializer.Serialize(memoryStream, input);
|
|
94
|
+
return memoryStream.ToArray();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public static T JsonDeserialize<T>(string data)
|
|
98
|
+
{
|
|
99
|
+
return JsonConvert.DeserializeObject<T>(data);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public static byte[] JsonSerialize(object input)
|
|
103
|
+
{
|
|
104
|
+
return JsonStringify(input).GetBytes();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public static string JsonStringify(object input, bool pretty = false)
|
|
108
|
+
{
|
|
109
|
+
return JsonConvert.SerializeObject(input, pretty ? Formatting.Indented : Formatting.None,
|
|
110
|
+
SerializerEncoding.Settings);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public static T ReadFromJsonFile<T>(string path)
|
|
114
|
+
{
|
|
115
|
+
string settingsAsText = File.ReadAllText(path, SerializerEncoding.Encoding);
|
|
116
|
+
return JsonDeserialize<T>(settingsAsText);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public static void WriteToJsonFile<T>(T input, string path)
|
|
120
|
+
{
|
|
121
|
+
string jsonAsText = JsonUtility.ToJson(input);
|
|
122
|
+
File.WriteAllText(path, jsonAsText);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Threading
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Concurrent;
|
|
5
|
+
using System.Threading;
|
|
6
|
+
|
|
7
|
+
public sealed class SingleThreadedThreadPool : IDisposable
|
|
8
|
+
{
|
|
9
|
+
private int _active;
|
|
10
|
+
private int _working;
|
|
11
|
+
private Thread _worker;
|
|
12
|
+
private readonly ConcurrentQueue<Action> _work;
|
|
13
|
+
private AutoResetEvent _waitHandle;
|
|
14
|
+
private bool _disposed;
|
|
15
|
+
|
|
16
|
+
public SingleThreadedThreadPool()
|
|
17
|
+
{
|
|
18
|
+
_active = 1;
|
|
19
|
+
_working = 1;
|
|
20
|
+
_work = new ConcurrentQueue<Action>();
|
|
21
|
+
_waitHandle = new AutoResetEvent(false);
|
|
22
|
+
_worker = new Thread(DoWork);
|
|
23
|
+
_worker.Start();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
~SingleThreadedThreadPool()
|
|
27
|
+
{
|
|
28
|
+
Dispose(false);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private void DoWork()
|
|
32
|
+
{
|
|
33
|
+
while (Interlocked.CompareExchange(ref _active, 0, 0) != 0)
|
|
34
|
+
{
|
|
35
|
+
_ = Interlocked.Exchange(ref _working, 0);
|
|
36
|
+
if (_work.TryDequeue(out Action workItem))
|
|
37
|
+
{
|
|
38
|
+
_ = Interlocked.Exchange(ref _working, 1);
|
|
39
|
+
try
|
|
40
|
+
{
|
|
41
|
+
workItem();
|
|
42
|
+
}
|
|
43
|
+
catch
|
|
44
|
+
{
|
|
45
|
+
// Ignore (TODO: Log to some output function? The downside here is that this is in another thread, which means standard Unity logging is a no-go)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
{
|
|
50
|
+
_ = _waitHandle.WaitOne(TimeSpan.FromSeconds(1));
|
|
51
|
+
}
|
|
52
|
+
_ = Interlocked.Exchange(ref _working, 0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public void Enqueue(Action work)
|
|
57
|
+
{
|
|
58
|
+
_work.Enqueue(work);
|
|
59
|
+
_ = _waitHandle.Set();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public int Count => _work.Count + Interlocked.CompareExchange(ref _working, 0, 0);
|
|
63
|
+
|
|
64
|
+
public void Dispose()
|
|
65
|
+
{
|
|
66
|
+
Dispose(true);
|
|
67
|
+
GC.SuppressFinalize(this);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public void Dispose(bool disposing)
|
|
71
|
+
{
|
|
72
|
+
if (_disposed)
|
|
73
|
+
{
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
int active;
|
|
78
|
+
do
|
|
79
|
+
{
|
|
80
|
+
active = Interlocked.CompareExchange(ref _active, 0, _active);
|
|
81
|
+
}
|
|
82
|
+
while (active != 0);
|
|
83
|
+
|
|
84
|
+
if (disposing)
|
|
85
|
+
{
|
|
86
|
+
try
|
|
87
|
+
{
|
|
88
|
+
_worker?.Join();
|
|
89
|
+
_waitHandle?.Dispose();
|
|
90
|
+
}
|
|
91
|
+
catch
|
|
92
|
+
{
|
|
93
|
+
// Swallow
|
|
94
|
+
}
|
|
95
|
+
_waitHandle = null;
|
|
96
|
+
_worker = null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_disposed = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 0b2150e4058ce7f44a227744f555355a
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 1
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 1
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 0
|
|
23
|
+
settings:
|
|
24
|
+
DefaultValueInitialized: true
|
|
25
|
+
- first:
|
|
26
|
+
Windows Store Apps: WindowsStoreApps
|
|
27
|
+
second:
|
|
28
|
+
enabled: 0
|
|
29
|
+
settings:
|
|
30
|
+
CPU: AnyCPU
|
|
31
|
+
userData:
|
|
32
|
+
assetBundleName:
|
|
33
|
+
assetBundleVariant:
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 3572a397b425f944597d773e9632c386
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 1
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 1
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 0
|
|
23
|
+
settings:
|
|
24
|
+
DefaultValueInitialized: true
|
|
25
|
+
- first:
|
|
26
|
+
Windows Store Apps: WindowsStoreApps
|
|
27
|
+
second:
|
|
28
|
+
enabled: 0
|
|
29
|
+
settings:
|
|
30
|
+
CPU: AnyCPU
|
|
31
|
+
userData:
|
|
32
|
+
assetBundleName:
|
|
33
|
+
assetBundleVariant:
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 52dc20fddc7d3fb428d73ce304b26f1d
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 1
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 1
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 0
|
|
23
|
+
settings:
|
|
24
|
+
DefaultValueInitialized: true
|
|
25
|
+
- first:
|
|
26
|
+
Windows Store Apps: WindowsStoreApps
|
|
27
|
+
second:
|
|
28
|
+
enabled: 0
|
|
29
|
+
settings:
|
|
30
|
+
CPU: AnyCPU
|
|
31
|
+
userData:
|
|
32
|
+
assetBundleName:
|
|
33
|
+
assetBundleVariant:
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 1d6533ed92c062a4cbdc15cc1eaa3f2f
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 1
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 1
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 0
|
|
23
|
+
settings:
|
|
24
|
+
DefaultValueInitialized: true
|
|
25
|
+
- first:
|
|
26
|
+
Windows Store Apps: WindowsStoreApps
|
|
27
|
+
second:
|
|
28
|
+
enabled: 0
|
|
29
|
+
settings:
|
|
30
|
+
CPU: AnyCPU
|
|
31
|
+
userData:
|
|
32
|
+
assetBundleName:
|
|
33
|
+
assetBundleVariant:
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: bb72feeabd7b72048a24cb9a2c760581
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 1
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 1
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 0
|
|
23
|
+
settings:
|
|
24
|
+
DefaultValueInitialized: true
|
|
25
|
+
- first:
|
|
26
|
+
Windows Store Apps: WindowsStoreApps
|
|
27
|
+
second:
|
|
28
|
+
enabled: 0
|
|
29
|
+
settings:
|
|
30
|
+
CPU: AnyCPU
|
|
31
|
+
userData:
|
|
32
|
+
assetBundleName:
|
|
33
|
+
assetBundleVariant:
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: b674bf75ea2325149aece8b92819b42c
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 1
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 1
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 0
|
|
23
|
+
settings:
|
|
24
|
+
DefaultValueInitialized: true
|
|
25
|
+
- first:
|
|
26
|
+
Windows Store Apps: WindowsStoreApps
|
|
27
|
+
second:
|
|
28
|
+
enabled: 0
|
|
29
|
+
settings:
|
|
30
|
+
CPU: AnyCPU
|
|
31
|
+
userData:
|
|
32
|
+
assetBundleName:
|
|
33
|
+
assetBundleVariant:
|