2
0

ScrollPositionControllerEditor.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /// Credit setchi (https://github.com/setchi)
  2. /// Sourced from - https://github.com/setchi/FancyScrollView
  3. // For maintenance, every new [SerializeField] variable in ScrollPositionController must be declared here
  4. using UnityEditor;
  5. namespace UnityEngine.UI.Extensions
  6. {
  7. [CustomEditor(typeof(ScrollPositionController))]
  8. [CanEditMultipleObjects]
  9. public class ScrollPositionControllerEditor : Editor
  10. {
  11. SerializedProperty viewport;
  12. SerializedProperty directionOfRecognize;
  13. SerializedProperty movementType;
  14. SerializedProperty elasticity;
  15. SerializedProperty scrollSensitivity;
  16. SerializedProperty inertia;
  17. SerializedProperty decelerationRate;
  18. SerializedProperty snap;
  19. SerializedProperty snapEnable;
  20. SerializedProperty snapVelocityThreshold;
  21. SerializedProperty snapDuration;
  22. SerializedProperty dataCount;
  23. void OnEnable()
  24. {
  25. viewport = serializedObject.FindProperty("viewport");
  26. directionOfRecognize = serializedObject.FindProperty("directionOfRecognize");
  27. movementType = serializedObject.FindProperty("movementType");
  28. elasticity = serializedObject.FindProperty("elasticity");
  29. scrollSensitivity = serializedObject.FindProperty("scrollSensitivity");
  30. inertia = serializedObject.FindProperty("inertia");
  31. decelerationRate = serializedObject.FindProperty("decelerationRate");
  32. snap = serializedObject.FindProperty("snap");
  33. snapEnable = serializedObject.FindProperty("snap.Enable");
  34. snapVelocityThreshold = serializedObject.FindProperty("snap.VelocityThreshold");
  35. snapDuration = serializedObject.FindProperty("snap.Duration");
  36. dataCount = serializedObject.FindProperty("dataCount");
  37. }
  38. public override void OnInspectorGUI()
  39. {
  40. serializedObject.Update();
  41. EditorGUILayout.PropertyField(viewport);
  42. EditorGUILayout.PropertyField(directionOfRecognize);
  43. EditorGUILayout.PropertyField(movementType);
  44. EditorGUILayout.PropertyField(elasticity);
  45. EditorGUILayout.PropertyField(scrollSensitivity);
  46. EditorGUILayout.PropertyField(inertia);
  47. DrawInertiaRelatedValues();
  48. EditorGUILayout.PropertyField(dataCount);
  49. serializedObject.ApplyModifiedProperties();
  50. }
  51. void DrawInertiaRelatedValues()
  52. {
  53. if (inertia.boolValue)
  54. {
  55. EditorGUILayout.PropertyField(decelerationRate);
  56. EditorGUILayout.PropertyField(snap);
  57. using (new EditorGUI.IndentLevelScope())
  58. {
  59. DrawSnapRelatedValues();
  60. }
  61. }
  62. }
  63. void DrawSnapRelatedValues()
  64. {
  65. if (snap.isExpanded)
  66. {
  67. EditorGUILayout.PropertyField(snapEnable);
  68. if (snapEnable.boolValue)
  69. {
  70. EditorGUILayout.PropertyField(snapVelocityThreshold);
  71. EditorGUILayout.PropertyField(snapDuration);
  72. }
  73. }
  74. }
  75. }
  76. }