11 [CustomEditor(typeof(Scroller))]
12 [CanEditMultipleObjects]
15 SerializedProperty viewport;
16 SerializedProperty scrollDirection;
17 SerializedProperty movementType;
18 SerializedProperty elasticity;
19 SerializedProperty scrollSensitivity;
20 SerializedProperty inertia;
21 SerializedProperty decelerationRate;
22 SerializedProperty snap;
23 SerializedProperty snapEnable;
24 SerializedProperty snapVelocityThreshold;
25 SerializedProperty snapDuration;
26 SerializedProperty snapEasing;
27 SerializedProperty draggable;
28 SerializedProperty scrollbar;
30 AnimBool showElasticity;
31 AnimBool showInertiaRelatedValues;
32 AnimBool showSnapEnableRelatedValues;
36 viewport = serializedObject.FindProperty(
"viewport");
37 scrollDirection = serializedObject.FindProperty(
"scrollDirection");
38 movementType = serializedObject.FindProperty(
"movementType");
39 elasticity = serializedObject.FindProperty(
"elasticity");
40 scrollSensitivity = serializedObject.FindProperty(
"scrollSensitivity");
41 inertia = serializedObject.FindProperty(
"inertia");
42 decelerationRate = serializedObject.FindProperty(
"decelerationRate");
43 snap = serializedObject.FindProperty(
"snap");
44 snapEnable = serializedObject.FindProperty(
"snap.Enable");
45 snapVelocityThreshold = serializedObject.FindProperty(
"snap.VelocityThreshold");
46 snapDuration = serializedObject.FindProperty(
"snap.Duration");
47 snapEasing = serializedObject.FindProperty(
"snap.Easing");
48 draggable = serializedObject.FindProperty(
"draggable");
49 scrollbar = serializedObject.FindProperty(
"scrollbar");
51 showElasticity =
new AnimBool(Repaint);
52 showInertiaRelatedValues =
new AnimBool(Repaint);
53 showSnapEnableRelatedValues =
new AnimBool(Repaint);
59 showElasticity.valueChanged.RemoveListener(Repaint);
60 showInertiaRelatedValues.valueChanged.RemoveListener(Repaint);
61 showSnapEnableRelatedValues.valueChanged.RemoveListener(Repaint);
64 void SetAnimBools(
bool instant)
66 SetAnimBool(showElasticity, !movementType.hasMultipleDifferentValues && movementType.enumValueIndex == (
int)
MovementType.Elastic, instant);
67 SetAnimBool(showInertiaRelatedValues, !inertia.hasMultipleDifferentValues && inertia.boolValue, instant);
68 SetAnimBool(showSnapEnableRelatedValues, !snapEnable.hasMultipleDifferentValues && snapEnable.boolValue, instant);
71 void SetAnimBool(AnimBool a,
bool value,
bool instant)
87 serializedObject.Update();
88 EditorGUILayout.PropertyField(viewport);
89 EditorGUILayout.PropertyField(scrollDirection);
90 EditorGUILayout.PropertyField(movementType);
91 DrawMovementTypeRelatedValue();
92 EditorGUILayout.PropertyField(scrollSensitivity);
93 EditorGUILayout.PropertyField(inertia);
94 DrawInertiaRelatedValues();
95 EditorGUILayout.PropertyField(draggable);
96 EditorGUILayout.PropertyField(scrollbar);
97 serializedObject.ApplyModifiedProperties();
100 void DrawMovementTypeRelatedValue()
102 using (var group =
new EditorGUILayout.FadeGroupScope(showElasticity.faded))
109 using (
new EditorGUI.IndentLevelScope())
111 EditorGUILayout.PropertyField(elasticity);
116 void DrawInertiaRelatedValues()
118 using (var group =
new EditorGUILayout.FadeGroupScope(showInertiaRelatedValues.faded))
125 using (
new EditorGUI.IndentLevelScope())
127 EditorGUILayout.PropertyField(decelerationRate);
128 EditorGUILayout.PropertyField(snap);
130 using (
new EditorGUI.IndentLevelScope())
132 DrawSnapRelatedValues();
138 void DrawSnapRelatedValues()
142 EditorGUILayout.PropertyField(snapEnable);
144 using (var group =
new EditorGUILayout.FadeGroupScope(showSnapEnableRelatedValues.faded))
151 EditorGUILayout.PropertyField(snapVelocityThreshold);
152 EditorGUILayout.PropertyField(snapDuration);
153 EditorGUILayout.PropertyField(snapEasing);
Credit Erdener Gonenc - @PixelEnvision.