1+ using UnityEngine ;
2+ using UnityEditor ;
3+ using UnityEngine . UI ;
4+ namespace Zalgo
5+ {
6+ public class ZCurvesGenerator : MonoBehaviour
7+ {
8+ [ Range ( 0.00001f , 1f ) ]
9+ public float deltaSlopeRight = 0.00001f ;
10+ [ Range ( 0.00001f , 1f ) ]
11+ public float deltaSlopeLeft = 0.00001f ;
12+ [ Range ( 0f , 1f ) ]
13+ public float leftSide = 0f ;
14+ [ Range ( 0f , 1f ) ]
15+ public float rightSide = 0.5f ;
16+ [ HideInInspector ]
17+ public AnimationCurve Curve ;
18+ public bool AutoUpdate = true ;
19+ public void Generate ( )
20+ {
21+ Curve = new AnimationCurve ( ) ;
22+ Curve . preWrapMode = WrapMode . ClampForever ;
23+ Curve . postWrapMode = WrapMode . ClampForever ;
24+ Curve . AddKey ( new Keyframe ( 0f , 0f ) ) ;
25+ Curve . AddKey ( new Keyframe ( leftSide - deltaSlopeLeft , 0f ) ) ;
26+ Curve . AddKey ( new Keyframe ( leftSide + deltaSlopeLeft , 1f ) ) ;
27+ Curve . AddKey ( new Keyframe ( rightSide - deltaSlopeRight , 1f ) ) ;
28+ Curve . AddKey ( new Keyframe ( rightSide + deltaSlopeRight , 0f ) ) ;
29+ Curve . AddKey ( new Keyframe ( 1f , 0f ) ) ;
30+ }
31+ public void Reset ( )
32+ {
33+ deltaSlopeRight = 0.00001f ;
34+ deltaSlopeLeft = 0.00001f ;
35+ leftSide = 0f ;
36+ rightSide = 0.5f ;
37+ Generate ( ) ;
38+ }
39+ }
40+ [ CustomEditor ( typeof ( ZCurvesGenerator ) ) ]
41+ public class ZCurvesEditor : Editor
42+ {
43+ public override void OnInspectorGUI ( )
44+ {
45+ ZCurvesGenerator CurvesGenerator = ( ZCurvesGenerator ) target ;
46+ if ( DrawDefaultInspector ( ) )
47+ {
48+ if ( CurvesGenerator . AutoUpdate )
49+ {
50+ CurvesGenerator . Generate ( ) ;
51+ }
52+ }
53+ GUILayout . BeginHorizontal ( ) ;
54+ GUILayout . EndHorizontal ( ) ;
55+ GUILayout . BeginHorizontal ( ) ;
56+ if ( GUILayout . Button ( "Generate" , GUILayout . Width ( 135f ) ) )
57+ {
58+ CurvesGenerator . Generate ( ) ;
59+ }
60+ if ( GUILayout . Button ( "Revert" , GUILayout . Width ( 135f ) ) )
61+ {
62+ CurvesGenerator . Reset ( ) ;
63+ }
64+ GUILayout . EndHorizontal ( ) ;
65+ CurvesGenerator . Curve =
66+ EditorGUILayout . CurveField ( "Height Curve" , CurvesGenerator . Curve ) ;
67+ //EditorGUILayout.CurveField(CurvesGenerator.Curve, new Rect(0f, 0f, 2f, 2f), GUILayout.Height(30f));
68+
69+ }
70+ }
71+ }
0 commit comments