public bool Update() { if (JNet.IsServer) { return(NetDirty); } if (objID == 0) { if (obj != null) { obj = null; UponObjectUpdate?.Invoke(null); } } else { if (obj == null || obj.NetID != objID) { var found = JNet.GetObject(objID); if (found != null) { obj = found; UponObjectUpdate?.Invoke(obj); } } } return(false); }
private void LateUpdate() { if (!updateParent) { return; } updateParent = false; if (ParentNetID != 0 && ParentNodeID != 0) { // Try to find the object. NetObject obj = JNet.GetObject(ParentNetID); if (obj == null) { JNet.Error($"Failed to find net object of id {ParentNetID} to sync the transform of this object."); return; } var node = obj.GetParentNode(ParentNodeID); if (node == null) { JNet.Error($"Failed to find net object of id {ParentNetID} parent node ({ParentNodeID}) to sync the transform of this object."); return; } this.transform.SetParent(node.GetTransform(), true); } else { this.transform.SetParent(null, true); } }
private static void AddAllParsers() { AddParser( (m) => m.ReadBoolean(), (m, o) => m.Write((bool)o)); AddParser( (m) => m.ReadColor(), (m, o) => m.Write((Color)o)); AddParser( (m) => m.ReadString(), (m, o) => m.Write((string)o)); AddParser( (m) => m.ReadByte(), (m, o) => m.Write((byte)o)); AddParser( (m) => m.ReadSByte(), (m, o) => m.Write((sbyte)o)); AddParser( (m) => m.ReadInt16(), (m, o) => m.Write((short)o)); AddParser( (m) => m.ReadUInt16(), (m, o) => m.Write((ushort)o)); AddParser( (m) => m.ReadInt32(), (m, o) => m.Write((int)o)); AddParser( (m) => m.ReadUInt32(), (m, o) => m.Write((uint)o)); AddParser( (m) => m.ReadInt64(), (m, o) => m.Write((long)o)); AddParser( (m) => m.ReadUInt64(), (m, o) => m.Write((ulong)o)); AddParser( (m) => m.ReadFloat(), (m, o) => m.Write((float)o)); AddParser( (m) => m.ReadDouble(), (m, o) => m.Write((double)o)); AddParser( (m) => m.ReadDecimal(), (m, o) => m.Write((decimal)o)); AddParser( (m) => m.ReadVector2(), (m, o) => m.Write((Vector2)o)); AddParser( (m) => m.ReadVector3(), (m, o) => m.Write((Vector3)o)); AddParser( (m) => m.ReadVector4(), (m, o) => m.Write((Vector4)o)); AddParser( (m) => JNet.GetObject(m.ReadUInt16()), (m, o) => m.Write((ushort)o)); }
private void ProcessSetOwner(NetIncomingMessage msg) { ushort netID = msg.ReadUInt16(); long ownerID = msg.ReadInt64(); var obj = JNet.GetObject(netID); if (obj != null) { obj.OwnerID = ownerID; } }
private void ProcessSpawnAll(NetIncomingMessage msg) { int objectCount = msg.ReadInt32(); int expectedSceneObjects = JNet.EnableSceneObjectNetworking ? JNet.TrackedObjectCount : 0; JNet.Log($"Recieved {objectCount} objects from the server."); for (int i = 0; i < objectCount; i++) { ushort prefabID = msg.ReadUInt16(); ushort netID = msg.ReadUInt16(); // Get the prefab for that ID... NetObject prefab = JNet.GetPrefab(prefabID); if (prefab == null && netID > expectedSceneObjects) { JNet.Error("Failed to find prefab for ID " + prefabID + ", object not spawned on client. Desync incoming!"); return; } if (netID == 0) { JNet.Error("Client got spawn message with instance net ID of zero, server error or corruption? Object not spawned, prefab id was " + prefabID + " (" + prefab + ")."); return; } // Instantiate the game object, if not scene object. NetObject no; if (prefab != null) { no = GameObject.Instantiate(prefab); } else { no = JNet.GetObject(netID); } // We need to register the object to the system, if not scene object. if (prefab != null) { JNet.Tracker.Register(no, netID); } // Read all the behaviours. no.Deserialize(msg, true); } UponWorldRecieved?.Invoke(); }
public void Deserialize(NetIncomingMessage msg, bool first) { ushort id = msg.ReadUInt16(); if (objID != id) { this.objID = id; var found = JNet.GetObject(id); if (found != obj || first) { obj = found; UponObjectUpdate?.Invoke(obj); } } }
public static NetObject ReadNetObject(this NetIncomingMessage msg) { return(JNet.GetObject(msg.ReadUInt16())); }