multiple xr toolkit package
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VRC_DataStorageEditor.cs 4.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #if UNITY_EDITOR
  2. using UnityEditor;
  3. using UnityEngine;
  4. using System.Linq;
  5. namespace VRCSDK2
  6. {
  7. [CustomPropertyDrawer(typeof(VRCSDK2.VRC_DataStorage.VrcDataElement))]
  8. public class CustomDataElementDrawer : PropertyDrawer
  9. {
  10. public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
  11. {
  12. if (property == null)
  13. return;
  14. SerializedProperty nameProperty = property.FindPropertyRelative("name");
  15. SerializedProperty mirrorProperty = property.FindPropertyRelative("mirror");
  16. SerializedProperty typeProperty = property.FindPropertyRelative("type");
  17. SerializedProperty valueProperty = null;
  18. switch (typeProperty.enumValueIndex)
  19. {
  20. case (int)VRC_DataStorage.VrcDataType.Bool:
  21. valueProperty = property.FindPropertyRelative("valueBool");
  22. break;
  23. case (int)VRC_DataStorage.VrcDataType.Float:
  24. valueProperty = property.FindPropertyRelative("valueFloat");
  25. break;
  26. case (int)VRC_DataStorage.VrcDataType.Int:
  27. valueProperty = property.FindPropertyRelative("valueInt");
  28. break;
  29. case (int)VRC_DataStorage.VrcDataType.String:
  30. valueProperty = property.FindPropertyRelative("valueString");
  31. break;
  32. case (int)VRC_DataStorage.VrcDataType.SerializeObject:
  33. valueProperty = property.FindPropertyRelative("serializeComponent");
  34. break;
  35. case (int)VRC_DataStorage.VrcDataType.None:
  36. case (int)VRC_DataStorage.VrcDataType.SerializeBytes:
  37. break;
  38. }
  39. EditorGUI.BeginProperty(rect, label, property);
  40. int baseWidth = (int)(rect.width / 4);
  41. Rect nameRect = new Rect(rect.x, rect.y, baseWidth, rect.height);
  42. Rect mirrorRect = new Rect(rect.x + baseWidth, rect.y, baseWidth, rect.height);
  43. Rect typeRect = new Rect(rect.x + baseWidth * 2, rect.y, baseWidth, rect.height);
  44. Rect valueRect = new Rect(rect.x + baseWidth * 3, rect.y, baseWidth, rect.height);
  45. Rect typeValueRect = new Rect(rect.x + baseWidth * 2, rect.y, baseWidth * 2, rect.height);
  46. EditorGUI.PropertyField(nameRect, nameProperty, GUIContent.none);
  47. EditorGUI.PropertyField(mirrorRect, mirrorProperty, GUIContent.none);
  48. switch (mirrorProperty.enumValueIndex)
  49. {
  50. case (int)VRC_DataStorage.VrcDataMirror.None:
  51. if (valueProperty == null)
  52. VRC_EditorTools.FilteredEnumPopup<VRC_DataStorage.VrcDataType>(typeValueRect, typeProperty, t => true);
  53. else
  54. {
  55. VRC_EditorTools.FilteredEnumPopup<VRC_DataStorage.VrcDataType>(typeRect, typeProperty, t => true);
  56. EditorGUI.PropertyField(valueRect, valueProperty, GUIContent.none);
  57. }
  58. break;
  59. case (int)VRC_DataStorage.VrcDataMirror.SerializeComponent:
  60. typeProperty.enumValueIndex = (int)VRC_DataStorage.VrcDataType.SerializeObject;
  61. EditorGUI.PropertyField(typeValueRect, valueProperty, GUIContent.none);
  62. break;
  63. default:
  64. VRC_EditorTools.FilteredEnumPopup<VRC_DataStorage.VrcDataType>(typeValueRect, typeProperty, t => true);
  65. break;
  66. }
  67. EditorGUI.EndProperty();
  68. }
  69. }
  70. [CustomEditor(typeof(VRCSDK2.VRC_DataStorage)), CanEditMultipleObjects]
  71. public class VRC_DataStorageEditor : Editor
  72. {
  73. public override void OnInspectorGUI()
  74. {
  75. VRCSDK2.VRC_ObjectSync os = ((VRCSDK2.VRC_DataStorage)target).GetComponent<VRCSDK2.VRC_ObjectSync>();
  76. if (os != null && os.SynchronizePhysics)
  77. EditorGUILayout.HelpBox("Consider either removing the VRC_ObjectSync or disabling SynchronizePhysics.", MessageType.Warning);
  78. DrawDefaultInspector();
  79. }
  80. }
  81. }
  82. #endif