Tanoda
ScrollPositionControllerEditor.cs
Go to the documentation of this file.
1
3
4// For maintenance, every new [SerializeField] variable in ScrollPositionController must be declared here
5
6using UnityEditor;
7
9{
10 [CustomEditor(typeof(ScrollPositionController))]
11 [CanEditMultipleObjects]
12 public class ScrollPositionControllerEditor : Editor
13 {
14 SerializedProperty viewport;
15 SerializedProperty directionOfRecognize;
16 SerializedProperty movementType;
17 SerializedProperty elasticity;
18 SerializedProperty scrollSensitivity;
19 SerializedProperty inertia;
20 SerializedProperty decelerationRate;
21 SerializedProperty snap;
22 SerializedProperty snapEnable;
23 SerializedProperty snapVelocityThreshold;
24 SerializedProperty snapDuration;
25 SerializedProperty dataCount;
26
27 void OnEnable()
28 {
29 viewport = serializedObject.FindProperty("viewport");
30 directionOfRecognize = serializedObject.FindProperty("directionOfRecognize");
31 movementType = serializedObject.FindProperty("movementType");
32 elasticity = serializedObject.FindProperty("elasticity");
33 scrollSensitivity = serializedObject.FindProperty("scrollSensitivity");
34 inertia = serializedObject.FindProperty("inertia");
35 decelerationRate = serializedObject.FindProperty("decelerationRate");
36 snap = serializedObject.FindProperty("snap");
37 snapEnable = serializedObject.FindProperty("snap.Enable");
38 snapVelocityThreshold = serializedObject.FindProperty("snap.VelocityThreshold");
39 snapDuration = serializedObject.FindProperty("snap.Duration");
40 dataCount = serializedObject.FindProperty("dataCount");
41 }
42
43 public override void OnInspectorGUI()
44 {
45 serializedObject.Update();
46 EditorGUILayout.PropertyField(viewport);
47 EditorGUILayout.PropertyField(directionOfRecognize);
48 EditorGUILayout.PropertyField(movementType);
49 EditorGUILayout.PropertyField(elasticity);
50 EditorGUILayout.PropertyField(scrollSensitivity);
51 EditorGUILayout.PropertyField(inertia);
52 DrawInertiaRelatedValues();
53 EditorGUILayout.PropertyField(dataCount);
54 serializedObject.ApplyModifiedProperties();
55 }
56
57 void DrawInertiaRelatedValues()
58 {
59 if (inertia.boolValue)
60 {
61 EditorGUILayout.PropertyField(decelerationRate);
62 EditorGUILayout.PropertyField(snap);
63
64 using (new EditorGUI.IndentLevelScope())
65 {
66 DrawSnapRelatedValues();
67 }
68 }
69 }
70
71 void DrawSnapRelatedValues()
72 {
73 if (snap.isExpanded)
74 {
75 EditorGUILayout.PropertyField(snapEnable);
76
77 if (snapEnable.boolValue)
78 {
79 EditorGUILayout.PropertyField(snapVelocityThreshold);
80 EditorGUILayout.PropertyField(snapDuration);
81 }
82 }
83 }
84 }
85}
Credit Erdener Gonenc - @PixelEnvision.