Skip to content

Commit 381dc4f

Browse files
jeffreyrainy0xFA11
andauthored
chore: Tighten up the APIs of NetworkAnimator and NetworkTransform to leave public only what's needed (#1897)
* chore: Thighten up the APIs of NetworkAnimator and NetworkTransform to leave public only what's needed * Update com.unity.netcode.gameobjects/Components/NetworkAnimator.cs * minor syntax fix Co-authored-by: Fatih Mar <[email protected]>
1 parent 97d9cbf commit 381dc4f

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

com.unity.netcode.gameobjects/Components/NetworkAnimator.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public class NetworkAnimator : NetworkBehaviour
1515
internal struct AnimationMessage : INetworkSerializable
1616
{
1717
// state hash per layer. if non-zero, then Play() this animation, skipping transitions
18-
public int StateHash;
19-
public float NormalizedTime;
20-
public int Layer;
21-
public float Weight;
22-
public byte[] Parameters;
18+
internal int StateHash;
19+
internal float NormalizedTime;
20+
internal int Layer;
21+
internal float Weight;
22+
internal byte[] Parameters;
2323

2424
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
2525
{
@@ -33,8 +33,8 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
3333

3434
internal struct AnimationTriggerMessage : INetworkSerializable
3535
{
36-
public int Hash;
37-
public bool Reset;
36+
internal int Hash;
37+
internal bool Reset;
3838

3939
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
4040
{
@@ -57,29 +57,29 @@ public Animator Animator
5757
private bool m_SendMessagesAllowed = false;
5858

5959
// Animators only support up to 32 params
60-
public static int K_MaxAnimationParams = 32;
60+
private const int k_MaxAnimationParams = 32;
6161

6262
private int[] m_TransitionHash;
6363
private int[] m_AnimationHash;
6464
private float[] m_LayerWeights;
6565

6666
private unsafe struct AnimatorParamCache
6767
{
68-
public int Hash;
69-
public int Type;
70-
public fixed byte Value[4]; // this is a max size of 4 bytes
68+
internal int Hash;
69+
internal int Type;
70+
internal fixed byte Value[4]; // this is a max size of 4 bytes
7171
}
7272

7373
// 128 bytes per Animator
74-
private FastBufferWriter m_ParameterWriter = new FastBufferWriter(K_MaxAnimationParams * sizeof(float), Allocator.Persistent);
74+
private FastBufferWriter m_ParameterWriter = new FastBufferWriter(k_MaxAnimationParams * sizeof(float), Allocator.Persistent);
7575
private NativeArray<AnimatorParamCache> m_CachedAnimatorParameters;
7676

7777
// We cache these values because UnsafeUtility.EnumToInt uses direct IL that allows a non-boxing conversion
7878
private struct AnimationParamEnumWrapper
7979
{
80-
public static readonly int AnimatorControllerParameterInt;
81-
public static readonly int AnimatorControllerParameterFloat;
82-
public static readonly int AnimatorControllerParameterBool;
80+
internal static readonly int AnimatorControllerParameterInt;
81+
internal static readonly int AnimatorControllerParameterFloat;
82+
internal static readonly int AnimatorControllerParameterBool;
8383

8484
static AnimationParamEnumWrapper()
8585
{

com.unity.netcode.gameobjects/Components/NetworkTransform.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal struct NetworkTransformState : INetworkSerializable
3939
// 11-15: <unused>
4040
private ushort m_Bitset;
4141

42-
public bool InLocalSpace
42+
internal bool InLocalSpace
4343
{
4444
get => (m_Bitset & (1 << k_InLocalSpaceBit)) != 0;
4545
set
@@ -50,7 +50,7 @@ public bool InLocalSpace
5050
}
5151

5252
// Position
53-
public bool HasPositionX
53+
internal bool HasPositionX
5454
{
5555
get => (m_Bitset & (1 << k_PositionXBit)) != 0;
5656
set
@@ -60,7 +60,7 @@ public bool HasPositionX
6060
}
6161
}
6262

63-
public bool HasPositionY
63+
internal bool HasPositionY
6464
{
6565
get => (m_Bitset & (1 << k_PositionYBit)) != 0;
6666
set
@@ -70,7 +70,7 @@ public bool HasPositionY
7070
}
7171
}
7272

73-
public bool HasPositionZ
73+
internal bool HasPositionZ
7474
{
7575
get => (m_Bitset & (1 << k_PositionZBit)) != 0;
7676
set
@@ -81,7 +81,7 @@ public bool HasPositionZ
8181
}
8282

8383
// RotAngles
84-
public bool HasRotAngleX
84+
internal bool HasRotAngleX
8585
{
8686
get => (m_Bitset & (1 << k_RotAngleXBit)) != 0;
8787
set
@@ -91,7 +91,7 @@ public bool HasRotAngleX
9191
}
9292
}
9393

94-
public bool HasRotAngleY
94+
internal bool HasRotAngleY
9595
{
9696
get => (m_Bitset & (1 << k_RotAngleYBit)) != 0;
9797
set
@@ -101,7 +101,7 @@ public bool HasRotAngleY
101101
}
102102
}
103103

104-
public bool HasRotAngleZ
104+
internal bool HasRotAngleZ
105105
{
106106
get => (m_Bitset & (1 << k_RotAngleZBit)) != 0;
107107
set
@@ -112,7 +112,7 @@ public bool HasRotAngleZ
112112
}
113113

114114
// Scale
115-
public bool HasScaleX
115+
internal bool HasScaleX
116116
{
117117
get => (m_Bitset & (1 << k_ScaleXBit)) != 0;
118118
set
@@ -122,7 +122,7 @@ public bool HasScaleX
122122
}
123123
}
124124

125-
public bool HasScaleY
125+
internal bool HasScaleY
126126
{
127127
get => (m_Bitset & (1 << k_ScaleYBit)) != 0;
128128
set
@@ -132,7 +132,7 @@ public bool HasScaleY
132132
}
133133
}
134134

135-
public bool HasScaleZ
135+
internal bool HasScaleZ
136136
{
137137
get => (m_Bitset & (1 << k_ScaleZBit)) != 0;
138138
set
@@ -142,7 +142,7 @@ public bool HasScaleZ
142142
}
143143
}
144144

145-
public bool IsTeleportingNextFrame
145+
internal bool IsTeleportingNextFrame
146146
{
147147
get => (m_Bitset & (1 << k_TeleportingBit)) != 0;
148148
set
@@ -152,12 +152,12 @@ public bool IsTeleportingNextFrame
152152
}
153153
}
154154

155-
public float PositionX, PositionY, PositionZ;
156-
public float RotAngleX, RotAngleY, RotAngleZ;
157-
public float ScaleX, ScaleY, ScaleZ;
158-
public double SentTime;
155+
internal float PositionX, PositionY, PositionZ;
156+
internal float RotAngleX, RotAngleY, RotAngleZ;
157+
internal float ScaleX, ScaleY, ScaleZ;
158+
internal double SentTime;
159159

160-
public Vector3 Position
160+
internal Vector3 Position
161161
{
162162
get { return new Vector3(PositionX, PositionY, PositionZ); }
163163
set
@@ -168,7 +168,7 @@ public Vector3 Position
168168
}
169169
}
170170

171-
public Vector3 Rotation
171+
internal Vector3 Rotation
172172
{
173173
get { return new Vector3(RotAngleX, RotAngleY, RotAngleZ); }
174174
set
@@ -179,7 +179,7 @@ public Vector3 Rotation
179179
}
180180
}
181181

182-
public Vector3 Scale
182+
internal Vector3 Scale
183183
{
184184
get { return new Vector3(ScaleX, ScaleY, ScaleZ); }
185185
set
@@ -795,8 +795,6 @@ private void Initialize()
795795
}
796796
}
797797

798-
#region state set
799-
800798
/// <summary>
801799
/// Directly sets a state on the authoritative transform.
802800
/// This will override any changes made previously to the transform
@@ -856,7 +854,6 @@ private void SetStateServerRpc(Vector3 pos, Quaternion rot, Vector3 scale, bool
856854
m_Transform.localScale = scale;
857855
m_LocalAuthoritativeNetworkState.IsTeleportingNextFrame = shouldTeleport;
858856
}
859-
#endregion
860857

861858
// todo this is currently in update, to be able to catch any transform changes. A FixedUpdate mode could be added to be less intense, but it'd be
862859
// conditional to users only making transform update changes in FixedUpdate.

0 commit comments

Comments
 (0)