|
| 1 | +using Unity.Netcode.Prototyping; |
| 2 | +using UnityEditor; |
| 3 | +using UnityEngine; |
| 4 | + |
| 5 | +namespace Unity.Netcode.Editor |
| 6 | +{ |
| 7 | + [CustomEditor(typeof(NetworkTransform))] |
| 8 | + public class NetworkTransformEditor : UnityEditor.Editor |
| 9 | + { |
| 10 | + private SerializedProperty m_SyncPositionXProperty; |
| 11 | + private SerializedProperty m_SyncPositionYProperty; |
| 12 | + private SerializedProperty m_SyncPositionZProperty; |
| 13 | + private SerializedProperty m_SyncRotationXProperty; |
| 14 | + private SerializedProperty m_SyncRotationYProperty; |
| 15 | + private SerializedProperty m_SyncRotationZProperty; |
| 16 | + private SerializedProperty m_SyncScaleXProperty; |
| 17 | + private SerializedProperty m_SyncScaleYProperty; |
| 18 | + private SerializedProperty m_SyncScaleZProperty; |
| 19 | + private SerializedProperty m_PositionThresholdProperty; |
| 20 | + private SerializedProperty m_RotAngleThresholdProperty; |
| 21 | + private SerializedProperty m_ScaleThresholdProperty; |
| 22 | + private SerializedProperty m_InLocalSpaceProperty; |
| 23 | + private SerializedProperty m_InterpolateProperty; |
| 24 | + |
| 25 | + private static int s_ToggleOffset = 45; |
| 26 | + private static float s_MaxRowWidth = EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth + 5; |
| 27 | + private static GUIContent s_PositionLabel = EditorGUIUtility.TrTextContent("Position"); |
| 28 | + private static GUIContent s_RotationLabel = EditorGUIUtility.TrTextContent("Rotation"); |
| 29 | + private static GUIContent s_ScaleLabel = EditorGUIUtility.TrTextContent("Scale"); |
| 30 | + |
| 31 | + public void OnEnable() |
| 32 | + { |
| 33 | + m_SyncPositionXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionX)); |
| 34 | + m_SyncPositionYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionY)); |
| 35 | + m_SyncPositionZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionZ)); |
| 36 | + m_SyncRotationXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleX)); |
| 37 | + m_SyncRotationYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleY)); |
| 38 | + m_SyncRotationZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncRotAngleZ)); |
| 39 | + m_SyncScaleXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleX)); |
| 40 | + m_SyncScaleYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleY)); |
| 41 | + m_SyncScaleZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncScaleZ)); |
| 42 | + m_PositionThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.PositionThreshold)); |
| 43 | + m_RotAngleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.RotAngleThreshold)); |
| 44 | + m_ScaleThresholdProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleThreshold)); |
| 45 | + m_InLocalSpaceProperty = serializedObject.FindProperty(nameof(NetworkTransform.InLocalSpace)); |
| 46 | + m_InterpolateProperty = serializedObject.FindProperty(nameof(NetworkTransform.Interpolate)); |
| 47 | + } |
| 48 | + |
| 49 | + public override void OnInspectorGUI() |
| 50 | + { |
| 51 | + EditorGUILayout.LabelField("Syncing", EditorStyles.boldLabel); |
| 52 | + { |
| 53 | + GUILayout.BeginHorizontal(); |
| 54 | + |
| 55 | + var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); |
| 56 | + var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); |
| 57 | + |
| 58 | + rect = EditorGUI.PrefixLabel(rect, ctid, s_PositionLabel); |
| 59 | + rect.width = s_ToggleOffset; |
| 60 | + |
| 61 | + m_SyncPositionXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncPositionXProperty.boolValue); |
| 62 | + rect.x += s_ToggleOffset; |
| 63 | + m_SyncPositionYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncPositionYProperty.boolValue); |
| 64 | + rect.x += s_ToggleOffset; |
| 65 | + m_SyncPositionZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncPositionZProperty.boolValue); |
| 66 | + |
| 67 | + GUILayout.EndHorizontal(); |
| 68 | + } |
| 69 | + { |
| 70 | + GUILayout.BeginHorizontal(); |
| 71 | + |
| 72 | + var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); |
| 73 | + var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); |
| 74 | + |
| 75 | + rect = EditorGUI.PrefixLabel(rect, ctid, s_RotationLabel); |
| 76 | + rect.width = s_ToggleOffset; |
| 77 | + |
| 78 | + m_SyncRotationXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncRotationXProperty.boolValue); |
| 79 | + rect.x += s_ToggleOffset; |
| 80 | + m_SyncRotationYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncRotationYProperty.boolValue); |
| 81 | + rect.x += s_ToggleOffset; |
| 82 | + m_SyncRotationZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncRotationZProperty.boolValue); |
| 83 | + |
| 84 | + GUILayout.EndHorizontal(); |
| 85 | + } |
| 86 | + { |
| 87 | + GUILayout.BeginHorizontal(); |
| 88 | + |
| 89 | + var rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, s_MaxRowWidth, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, EditorStyles.numberField); |
| 90 | + var ctid = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); |
| 91 | + |
| 92 | + rect = EditorGUI.PrefixLabel(rect, ctid, s_ScaleLabel); |
| 93 | + rect.width = s_ToggleOffset; |
| 94 | + |
| 95 | + m_SyncScaleXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncScaleXProperty.boolValue); |
| 96 | + rect.x += s_ToggleOffset; |
| 97 | + m_SyncScaleYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncScaleYProperty.boolValue); |
| 98 | + rect.x += s_ToggleOffset; |
| 99 | + m_SyncScaleZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncScaleZProperty.boolValue); |
| 100 | + |
| 101 | + GUILayout.EndHorizontal(); |
| 102 | + } |
| 103 | + |
| 104 | + EditorGUILayout.Space(); |
| 105 | + EditorGUILayout.LabelField("Thresholds", EditorStyles.boldLabel); |
| 106 | + EditorGUILayout.PropertyField(m_PositionThresholdProperty); |
| 107 | + EditorGUILayout.PropertyField(m_RotAngleThresholdProperty); |
| 108 | + EditorGUILayout.PropertyField(m_ScaleThresholdProperty); |
| 109 | + |
| 110 | + EditorGUILayout.Space(); |
| 111 | + EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel); |
| 112 | + EditorGUILayout.PropertyField(m_InLocalSpaceProperty); |
| 113 | + EditorGUILayout.PropertyField(m_InterpolateProperty); |
| 114 | + |
| 115 | + serializedObject.ApplyModifiedProperties(); |
| 116 | + } |
| 117 | + } |
| 118 | +} |
0 commit comments