Skip to content

Commit cfd37a4

Browse files
committed
Found the real bug, was a different implementation Write(byte[]) in Mirror from Unet's
1 parent 642647d commit cfd37a4

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed
Binary file not shown.

Assets/emotitron/Utilities/MirrorTools/MirrorCheck.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ private void Awake()
3434
{
3535
/// Remove the UNET NetIdentity if it exists on this object.
3636
var ni = GetComponent<UnityEngine.Networking.NetworkIdentity>();
37-
3837
if (ni)
3938
{
39+
AddMirrorNetManager();
4040
DestroyImmediate(ni);
4141
return;
4242
}
@@ -73,7 +73,6 @@ static void SceneOpenedCallback(Scene scene, UnityEditor.SceneManagement.OpenSce
7373
if (!scene.name.Contains("Example") && !scene.name.Contains("Sample"))
7474
return;
7575

76-
Debug.Log("<b>Opening Scene</b> " + scene.name); // // path);
7776
//if (_mode == UnityEditor.SceneManagement.OpenSceneMode.)
7877
// get root objects in scene
7978
List<GameObject> rootObjects = new List<GameObject>();
@@ -83,7 +82,7 @@ static void SceneOpenedCallback(Scene scene, UnityEditor.SceneManagement.OpenSce
8382
/// Need to make sure all NetIds have been converted before converting NM
8483
if (!mirrorNetIdAlreadyAddedToResources)
8584
{
86-
Debug.Log("MirrorNetId being added to all resources");
85+
Debug.Log("Mirror NetId being added to all resources that have UNET NetId");
8786
AddMirrorNetIdToResources();
8887
mirrorNetIdAlreadyAddedToResources = true;
8988
}
@@ -96,7 +95,6 @@ static void SceneOpenedCallback(Scene scene, UnityEditor.SceneManagement.OpenSce
9695
{
9796
if (mc)
9897
{
99-
Debug.Log("Found MC on " + go.name);
10098
mc.AddMirrorNetManager();
10199
}
102100
}
@@ -105,14 +103,12 @@ static void SceneOpenedCallback(Scene scene, UnityEditor.SceneManagement.OpenSce
105103

106104
public static void AddMirrorNetIdToResources()
107105
{
108-
Debug.Log("LoadAllREsources !!!!");
109106
// Option for stripping all prefabs in all resource folders of NI
110107
var objs = Resources.LoadAll<MirrorCheck>("");
111108

112109
// MirrorCheck on objects in resource folders should be prefabs. Replace NI on all of those.
113110
for (int i = 0; i < objs.Length; i++)
114111
{
115-
Debug.Log("<b>Replacing NI on </b>" + objs[i].gameObject.name);
116112
AddMirrorNetowrkIdentity(objs[i].gameObject);
117113
}
118114

@@ -130,6 +126,7 @@ public static void RemoveUNetNetIdFromResources()
130126
Debug.Log("<b>Replacing NI on </b>" + objs[i].gameObject.name);
131127
RemoveUNetNetowrkIdentity(objs[i].gameObject);
132128
}
129+
AssetDatabase.SaveAssets();
133130
}
134131

135132
/// <summary>
@@ -139,13 +136,11 @@ public static void RemoveUNetNetIdFromResources()
139136
public Mirror.NetworkManager AddMirrorNetManager()
140137
{
141138
var unetNM = GetComponent<UnityEngine.Networking.NetworkManager>();
142-
Debug.Log("unet nm? " + gameObject.name + " " + (unetNM != null));
143139

144140
if (unetNM == null)
145141
return null;
146142

147143
var mirrorNM = GetComponent<Mirror.NetworkManager>();
148-
Debug.Log("mirror nm? " + gameObject.name + " " + (mirrorNM != null));
149144

150145
if (mirrorNM)
151146
return mirrorNM;
@@ -245,14 +240,6 @@ public static void AddMirrorNetowrkIdentity(GameObject prefab)
245240
if (mirrorNI)
246241
return;
247242

248-
249-
///// TEST
250-
//mirrorNI = prefab.AddComponent<Mirror.NetworkIdentity>();
251-
//mirrorNI.localPlayerAuthority = unetNI.localPlayerAuthority;
252-
//mirrorNI.serverOnly = unetNI.serverOnly;
253-
//return;
254-
255-
256243
if (PrefabUtility.IsPartOfPrefabAsset(prefab))
257244
{
258245
var path = AssetDatabase.GetAssetPath(prefab);
@@ -266,8 +253,6 @@ public static void AddMirrorNetowrkIdentity(GameObject prefab)
266253
try
267254
{
268255
mirrorNI = prefabRoot.AddComponent<Mirror.NetworkIdentity>();
269-
Debug.Log("Trying " + prefab.name + " " + (mirrorNI != null));
270-
271256
mirrorNI.localPlayerAuthority = unetNI.localPlayerAuthority;
272257
mirrorNI.serverOnly = unetNI.serverOnly;
273258
PrefabUtility.SaveAsPrefabAssetAndConnect(prefabRoot, path, InteractionMode.UserAction);
@@ -293,7 +278,6 @@ public static void RemoveUNetNetowrkIdentity(GameObject prefab)
293278
DestroyImmediate(unetNI, true);
294279

295280
EditorUtility.SetDirty(prefab);
296-
AssetDatabase.SaveAssets();
297281
}
298282

299283
public static void CopyPlayerPrefab(UnityEngine.Networking.NetworkManager src, Mirror.NetworkManager targ)

Assets/emotitron/Utilities/Networking/NetAdapters/NetMsgCallbacks.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ public BytesMessageNonalloc() { }
4040

4141
public override void Serialize(NetworkWriter writer)
4242
{
43+
#if MIRROR
4344
writer.Write(buffer, 0, length);
45+
#else
46+
writer.Write(buffer, writer.Position, length);
47+
#endif
4448
}
4549

4650
public override void Deserialize(NetworkReader reader)
4751
{
4852
length = (ushort)(reader.Length - reader.Position);
49-
reader.ReadBytes(length);
5053
for (int i = 0; i < length; i++)
5154
incomingbuffer[i] = reader.ReadByte();
5255
}
@@ -299,7 +302,7 @@ private static void UnregisterMessageId(int msgId, bool asServer)
299302
#if MIRROR
300303
NetworkClient.UnregisterHandler((short)msgId);
301304
#else
302-
if (NetworkManager.singleton.client != null)
305+
if (NetworkManager.singleton.client != null)
303306
NetworkManager.singleton.client.UnregisterHandler((short)msgId);
304307
#endif
305308
}

Assets/emotitron/Utilities/Networking/NetAdapters/NetMsgSends.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public static void Send(this byte[] buffer, short msgId, ReceiveGroup rcvGrp)
116116
/// </summary>
117117
public static void Send(BytesMessageNonalloc msg, short msgId, ReceiveGroup rcvGrp, int channel = Channels.DefaultUnreliable)
118118
{
119-
120119
/// Server send to all. Owner client send to server.
121120
if (rcvGrp == ReceiveGroup.All)
122121
{

0 commit comments

Comments
 (0)