public void Init() { if (m_Initialized) { return; } m_Initialized = true; sync = target as NetworkTransformChild; m_Target = serializedObject.FindProperty("m_Target"); if (sync.GetComponent <NetworkTransform>() == null) { Debug.LogError("NetworkTransformChild must be on the root object with the NetworkTransform, not on the child node"); m_Target.objectReferenceValue = null; } m_MovementThreshold = serializedObject.FindProperty("m_MovementThreshold"); m_InterpolateRotation = serializedObject.FindProperty("m_InterpolateRotation"); m_InterpolateMovement = serializedObject.FindProperty("m_InterpolateMovement"); m_RotationSyncCompression = serializedObject.FindProperty("m_RotationSyncCompression"); m_SyncIntervalProperty = serializedObject.FindProperty("syncInterval"); m_TargetLabel = new GUIContent("Target", "The child transform to be synchronized."); EditorGUI.indentLevel += 1; m_MovementThresholdLabel = new GUIContent("Movement Threshold", "The distance that this object can move without sending a movement synchronization update."); m_InterpolateRotationLabel = new GUIContent("Interpolate Rotation Factor", "The larger this number is, the faster the object will interpolate to the target facing direction."); m_InterpolateMovementLabel = new GUIContent("Interpolate Movement Factor", "The larger this number is, the faster the object will interpolate to the target position."); m_RotationSyncCompressionLabel = new GUIContent("Compress Rotation", "How much to compress rotation sync updates.\n\nChoose None for no compression.\n\nChoose Low for a low amount of compression that preserves accuracy.\n\nChoose High for a high amount of compression that sacrifices accuracy."); m_RotationAxisLabel = new GUIContent("Rotation Axis", "Which axis to use for rotation."); EditorGUI.indentLevel -= 1; }
internal static void HandleChildTransform(NetworkMessage netMsg) { LocalChildTransformMessage message = netMsg.ReadMessage <LocalChildTransformMessage>(); GameObject foundObj = NetworkServer.FindLocalObject(message.netId); if (foundObj == null) { Debug.LogError("Received NetworkTransformChild data for GameObject that doesn't exist"); return; } var children = foundObj.GetComponents <NetworkTransformChild>(); if (children == null || children.Length == 0) { Debug.LogError("HandleChildTransform no children"); return; } if (message.childIndex >= children.Length) { Debug.LogError("HandleChildTransform childIndex invalid"); return; } NetworkTransformChild foundSync = children[message.childIndex]; if (foundSync == null) { Debug.LogError("HandleChildTransform null target"); return; } if (!foundSync.localPlayerAuthority) { Debug.LogError("HandleChildTransform no localPlayerAuthority"); return; } if (!netMsg.conn.clientOwnedObjects.Contains(message.netId)) { Debug.LogWarning("NetworkTransformChild netId:" + message.netId + " is not for a valid player"); return; } foundSync.UnserializeModeTransform(new NetworkReader(message.payload), false); foundSync.m_LastClientSyncTime = Time.time; if (!foundSync.isClient) { // dedicated server wont interpolate, so snap. foundSync.m_Target.localPosition = foundSync.m_TargetSyncPosition; foundSync.m_Target.localRotation = foundSync.m_TargetSyncRotation3D; } }