|
6 | 6 | using System;
|
7 | 7 | using System.IO;
|
8 | 8 | using System.Text;
|
| 9 | +using MLAPI.Components; |
9 | 10 | using MLAPI.Internal;
|
| 11 | +using MLAPI.Logging; |
10 | 12 | using UnityEngine;
|
11 | 13 |
|
12 | 14 | namespace MLAPI.Serialization
|
@@ -129,6 +131,49 @@ public object ReadObjectPacked(Type type)
|
129 | 131 | return ReadCharPacked();
|
130 | 132 | if (type.IsEnum)
|
131 | 133 | return ReadInt32Packed();
|
| 134 | + if (type == typeof(GameObject)) |
| 135 | + { |
| 136 | + uint networkId = ReadUInt32Packed(); |
| 137 | + if (SpawnManager.SpawnedObjects.ContainsKey(networkId)) |
| 138 | + { |
| 139 | + return SpawnManager.SpawnedObjects[networkId].gameObject; |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + if (LogHelper.CurrentLogLevel <= LogLevel.Normal) |
| 144 | + LogHelper.LogWarning("BitReader canot find the GameObject sent in the SpawnedObjects list, it may have been destroyed. NetworkId: " + networkId.ToString()); |
| 145 | + return null; |
| 146 | + } |
| 147 | + } |
| 148 | + if (type == typeof(NetworkedObject)) |
| 149 | + { |
| 150 | + uint networkId = ReadUInt32Packed(); |
| 151 | + if (SpawnManager.SpawnedObjects.ContainsKey(networkId)) |
| 152 | + { |
| 153 | + return SpawnManager.SpawnedObjects[networkId]; |
| 154 | + } |
| 155 | + else |
| 156 | + { |
| 157 | + if (LogHelper.CurrentLogLevel <= LogLevel.Normal) |
| 158 | + LogHelper.LogWarning("BitReader canot find the NetworkedObject sent in the SpawnedObjects list, it may have been destroyed. NetworkId: " + networkId.ToString()); |
| 159 | + return null; |
| 160 | + } |
| 161 | + } |
| 162 | + if (type == typeof(NetworkedBehaviour)) |
| 163 | + { |
| 164 | + uint networkId = ReadUInt32Packed(); |
| 165 | + ushort behaviourId = ReadUInt16Packed(); |
| 166 | + if (SpawnManager.SpawnedObjects.ContainsKey(networkId)) |
| 167 | + { |
| 168 | + return SpawnManager.SpawnedObjects[networkId].GetBehaviourAtOrderIndex(behaviourId); |
| 169 | + } |
| 170 | + else |
| 171 | + { |
| 172 | + if (LogHelper.CurrentLogLevel <= LogLevel.Normal) |
| 173 | + LogHelper.LogWarning("BitReader canot find the NetworkedBehaviour sent in the SpawnedObjects list, it may have been destroyed. NetworkId: " + networkId.ToString()); |
| 174 | + return null; |
| 175 | + } |
| 176 | + } |
132 | 177 | if (typeof(IBitWritable).IsAssignableFrom(type))
|
133 | 178 | {
|
134 | 179 | object instance = Activator.CreateInstance(type);
|
|
0 commit comments