diff --git a/com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs new file mode 100644 index 0000000000..519b2a6f38 --- /dev/null +++ b/com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs @@ -0,0 +1,118 @@ +using Unity.Netcode.Prototyping; +using UnityEditor; +using UnityEngine; + +namespace Unity.Netcode.Editor +{ + [CustomEditor(typeof(NetworkTransform))] + public class NetworkTransformEditor : UnityEditor.Editor + { + private SerializedProperty m_SyncPositionXProperty; + private SerializedProperty m_SyncPositionYProperty; + private SerializedProperty m_SyncPositionZProperty; + private SerializedProperty m_SyncRotationXProperty; + private SerializedProperty m_SyncRotationYProperty; + private SerializedProperty m_SyncRotationZProperty; + private SerializedProperty m_SyncScaleXProperty; + private SerializedProperty m_SyncScaleYProperty; + private SerializedProperty m_SyncScaleZProperty; + private SerializedProperty m_PositionThresholdProperty; + private SerializedProperty m_RotAngleThresholdProperty; + private SerializedProperty m_ScaleThresholdProperty; + private SerializedProperty m_InLocalSpaceProperty; + private SerializedProperty m_InterpolateProperty; + + private static int s_ToggleOffset = 45; + private static float s_MaxRowWidth = EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth + 5; + private static GUIContent s_PositionLabel = EditorGUIUtility.TrTextContent("Position"); + private static GUIContent s_RotationLabel = EditorGUIUtility.TrTextContent("Rotation"); + private static GUIContent s_ScaleLabel = EditorGUIUtility.TrTextContent("Scale"); + + public void OnEnable() + { + m_SyncPositionXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionX)); + m_SyncPositionYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionY)); + m_SyncPositionZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionZ)); + m_SyncRotationXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleX)); + m_SyncRotationYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleY)); + m_SyncRotationZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleZ)); + m_SyncScaleXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleX)); + m_SyncScaleYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleY)); + m_SyncScaleZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleZ)); + m_PositionThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.PositionThreshold)); + m_RotAngleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.RotAngleThreshold)); + m_ScaleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleThreshold)); + m_InLocalSpaceProperty = serializedObject.FindProperty(nameof(NetworkTransform.InLocalSpace)); + m_InterpolateProperty = serializedObject.FindProperty(nameof(NetworkTransform.Interpolate)); + } + + public override void OnInspectorGUI() + { + EditorGUILayout.LabelField("Syncing", EditorStyles.boldLabel); + { + GUILayout.BeginHorizontal(); + + var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); + var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); + + rect = EditorGUI.PrefixLabel(rect, ctid, s_PositionLabel); + rect.width = s_ToggleOffset; + + m_SyncPositionXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncPositionXProperty.boolValue); + rect.x += s_ToggleOffset; + m_SyncPositionYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncPositionYProperty.boolValue); + rect.x += s_ToggleOffset; + m_SyncPositionZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncPositionZProperty.boolValue); + + GUILayout.EndHorizontal(); + } + { + GUILayout.BeginHorizontal(); + + var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); + var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); + + rect = EditorGUI.PrefixLabel(rect, ctid, s_RotationLabel); + rect.width = s_ToggleOffset; + + m_SyncRotationXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncRotationXProperty.boolValue); + rect.x += s_ToggleOffset; + m_SyncRotationYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncRotationYProperty.boolValue); + rect.x += s_ToggleOffset; + m_SyncRotationZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncRotationZProperty.boolValue); + + GUILayout.EndHorizontal(); + } + { + GUILayout.BeginHorizontal(); + + var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); + var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); + + rect = EditorGUI.PrefixLabel(rect, ctid, s_ScaleLabel); + rect.width = s_ToggleOffset; + + m_SyncScaleXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncScaleXProperty.boolValue); + rect.x += s_ToggleOffset; + m_SyncScaleYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncScaleYProperty.boolValue); + rect.x += s_ToggleOffset; + m_SyncScaleZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncScaleZProperty.boolValue); + + GUILayout.EndHorizontal(); + } + + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Thresholds", EditorStyles.boldLabel); + EditorGUILayout.PropertyField(m_PositionThresholdProperty); + EditorGUILayout.PropertyField(m_RotAngleThresholdProperty); + EditorGUILayout.PropertyField(m_ScaleThresholdProperty); + + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel); + EditorGUILayout.PropertyField(m_InLocalSpaceProperty); + EditorGUILayout.PropertyField(m_InterpolateProperty); + + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs.meta b/com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs.meta new file mode 100644 index 0000000000..544457ff4a --- /dev/null +++ b/com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 17891488cb32d4243b0710884463d70f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Prototyping/NetworkTransform.cs b/com.unity.netcode.gameobjects/Prototyping/NetworkTransform.cs index dfeefad15f..ccfb9db003 100644 --- a/com.unity.netcode.gameobjects/Prototyping/NetworkTransform.cs +++ b/com.unity.netcode.gameobjects/Prototyping/NetworkTransform.cs @@ -128,6 +128,12 @@ public void NetworkSerialize(NetworkSerializer serializer) } } + public bool SyncPositionX = true, SyncPositionY = true, SyncPositionZ = true; + public bool SyncRotAngleX = true, SyncRotAngleY = true, SyncRotAngleZ = true; + public bool SyncScaleX = true, SyncScaleY = true, SyncScaleZ = true; + + public float PositionThreshold, RotAngleThreshold, ScaleThreshold; + /// /// Sets whether this transform should sync in local space or in world space. /// This is important to set since reparenting this transform could have issues, @@ -137,11 +143,8 @@ public void NetworkSerialize(NetworkSerializer serializer) [Tooltip("Sets whether this transform should sync in local space or in world space")] public bool InLocalSpace = false; - public bool SyncPositionX = true, SyncPositionY = true, SyncPositionZ = true; - public bool SyncRotAngleX = true, SyncRotAngleY = true, SyncRotAngleZ = true; - public bool SyncScaleX = true, SyncScaleY = true, SyncScaleZ = true; - - public float PositionThreshold, RotAngleThreshold, ScaleThreshold; + // todo: revisit after MTT-876 + public bool Interpolate = true; /// /// The base amount of sends per seconds to use when range is disabled