void NetUtilSyncTransform(object t_object) { if (NetUtilManager.OwnsObject(gameObject.name)) { return; } NetUtilSyncTransform netTransform = (NetUtilSyncTransform)t_object; if (netTransform.time < newTime) { return; } oldTime = newTime; oldPosition = newPosition; oldRotation = newRotation; oldScale = newScale; samplePosition = transform.position; sampleRotation = transform.rotation; sampleScale = transform.localScale; newTime = netTransform.time; newPosition = netTransform.position.toVector3(); newRotation = netTransform.rotation.toQuaternion(); newScale = netTransform.localScale.toVector3(); currentTime = oldTime; }
/// <summary> /// handles incoming sync transform messages /// </summary> private void HandleSyncTransform(int connectionId, byte[] buffer, int size) { try { NetUtilSyncTransform message = ConstructType <NetUtilSyncTransform>(buffer, 1, size - 1); SyncTransform(message, connectionId); } catch (Exception e) { Debug.Log(buffer.Length); Debug.Log(size); } }
/// <summary> /// syncs a game objects transform over the network /// </summary> /// <param name="t_name">the name of the object to synchronize</param> /// <param name="t_transform">the transform to synchronize with</param> /// <param name="t_connectionOrigin">the origin of the create object message, defaults to -1 for local</param> public void SyncTransform(NetUtilSyncTransform t_message, int t_connectionOrigin = -1) { if (t_connectionOrigin == -1 && !m_gameObjects.ContainsKey(t_message.name)) { throw new ArgumentException("\"" + t_message.name + "\" is not an existing netutil game object"); } if (!m_gameObjects.ContainsKey(t_message.name)) { return; } SendPrioritySync(NetUtilMessageType.SYNC_TRANSFORM, t_message, t_connectionOrigin); if (t_connectionOrigin != -1) { m_gameObjects[t_message.name].BroadcastMessage("NetUtilSyncTransform", t_message); } }