10using System.Runtime.CompilerServices;
28 [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 get => ULongToNetworkBehaviour(base.Value);
30 [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 set => base.Value = NetworkBehaviourToULong(value);
36 public new event Action<T, T> Callback;
39 [MethodImpl(MethodImplOptions.AggressiveInlining)]
40 protected override void InvokeCallback(ulong oldValue, ulong newValue) =>
41 Callback?.Invoke(ULongToNetworkBehaviour(oldValue), ULongToNetworkBehaviour(newValue));
49 : base(NetworkBehaviourToULong(value)) {}
52 [MethodImpl(MethodImplOptions.AggressiveInlining)]
57 [MethodImpl(MethodImplOptions.AggressiveInlining)]
65 [MethodImpl(MethodImplOptions.AggressiveInlining)]
69 [MethodImpl(MethodImplOptions.AggressiveInlining)]
73 [MethodImpl(MethodImplOptions.AggressiveInlining)]
77 [MethodImpl(MethodImplOptions.AggressiveInlining)]
81 [MethodImpl(MethodImplOptions.AggressiveInlining)]
85 [MethodImpl(MethodImplOptions.AggressiveInlining)]
89 [MethodImpl(MethodImplOptions.AggressiveInlining)]
93 [MethodImpl(MethodImplOptions.AggressiveInlining)]
97 [MethodImpl(MethodImplOptions.AggressiveInlining)]
101 [MethodImpl(MethodImplOptions.AggressiveInlining)]
105 [MethodImpl(MethodImplOptions.AggressiveInlining)]
107 [MethodImpl(MethodImplOptions.AggressiveInlining)]
108 public override int GetHashCode() => Value.GetHashCode();
112 [MethodImpl(MethodImplOptions.AggressiveInlining)]
113 internal static ulong Pack(uint netId,
byte componentIndex) =>
114 (ulong)netId << 32 | componentIndex;
116 [MethodImpl(MethodImplOptions.AggressiveInlining)]
117 internal static void Unpack(ulong value, out uint netId, out
byte componentIndex)
119 netId = (uint)(value >> 32);
120 componentIndex = (byte)(value & 0xFF);
124 static T ULongToNetworkBehaviour(ulong value)
127 Unpack(value, out uint netId, out
byte componentIndex);
133 return identity !=
null ? (T)identity.NetworkBehaviours[componentIndex] :
null;
136 static ulong NetworkBehaviourToULong(T value)
139 return value !=
null ? Pack(value.netId, (
byte)value.ComponentIndex) : 0;
143 [MethodImpl(MethodImplOptions.AggressiveInlining)]
146 Unpack(base.Value, out uint netId, out
byte componentIndex);
147 writer.WriteUInt(netId);
148 writer.WriteByte(componentIndex);
151 [MethodImpl(MethodImplOptions.AggressiveInlining)]
152 public override void OnSerializeDelta(
NetworkWriter writer) =>
153 OnSerializeAll(writer);
156 [MethodImpl(MethodImplOptions.AggressiveInlining)]
159 uint netId = reader.ReadUInt();
160 byte componentIndex = reader.ReadByte();
161 base.Value = Pack(netId, componentIndex);
164 [MethodImpl(MethodImplOptions.AggressiveInlining)]
165 public override void OnDeserializeDelta(
NetworkReader reader) =>
166 OnDeserializeAll(reader);
Base class for networked components.
NetworkIdentity identifies objects across the network.
Network Reader for most simple types like floats, ints, buffers, structs, etc. Use NetworkReaderPool....
Network Writer for most simple types like floats, ints, buffers, structs, etc. Use NetworkWriterPool....