-
-
Notifications
You must be signed in to change notification settings - Fork 590
Expand file tree
/
Copy pathCollisionShapeLoader.cs
More file actions
75 lines (61 loc) · 2.42 KB
/
CollisionShapeLoader.cs
File metadata and controls
75 lines (61 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace Components;
using SharedBase.Archive;
/// <summary>
/// Specifies a collision shape resource to be loaded into a <see cref="PhysicsShapeHolder"/>
/// </summary>
public struct CollisionShapeLoader : IArchivableComponent
{
public const ushort SERIALIZATION_VERSION = 1;
public string CollisionResourcePath;
public bool SkipCollisionLoading;
/// <summary>
/// Density of the shape. Only applies if <see cref="ApplyDensity"/> is true.
/// </summary>
public float Density;
/// <summary>
/// If false, a default density (if known for the collision resource) is used
/// </summary>
public bool ApplyDensity;
/// <summary>
/// If this is set to true then when this shape is created it doesn't force a <see cref="Physics"/> to
/// recreate the body for the changed shape (if the body was already created). When false, it is ensured that
/// the body gets recreated when the shape changes.
/// </summary>
public bool SkipForceRecreateBodyIfCreated;
/// <summary>
/// Must be set to false if parameters are changed for the shape to be reloaded
/// </summary>
public bool ShapeLoaded;
public CollisionShapeLoader(string resourcePath, float density)
{
CollisionResourcePath = resourcePath;
Density = density;
ApplyDensity = true;
SkipForceRecreateBodyIfCreated = false;
ShapeLoaded = false;
}
public ushort CurrentArchiveVersion => SERIALIZATION_VERSION;
public ThriveArchiveObjectType ArchiveObjectType => ThriveArchiveObjectType.ComponentCollisionShapeLoader;
public void WriteToArchive(ISArchiveWriter writer)
{
writer.Write(CollisionResourcePath);
writer.Write(Density);
writer.Write(ApplyDensity);
writer.Write(SkipForceRecreateBodyIfCreated);
}
}
public static class CollisionShapeLoaderHelpers
{
public static CollisionShapeLoader ReadFromArchive(ISArchiveReader reader, ushort version)
{
if (version is > CollisionShapeLoader.SERIALIZATION_VERSION or <= 0)
throw new InvalidArchiveVersionException(version, CollisionShapeLoader.SERIALIZATION_VERSION);
return new CollisionShapeLoader
{
CollisionResourcePath = reader.ReadString()!,
Density = reader.ReadFloat(),
ApplyDensity = reader.ReadBool(),
SkipForceRecreateBodyIfCreated = reader.ReadBool(),
};
}
}