Tanoda
CUIImageEditor.cs
Go to the documentation of this file.
1
3
4using UnityEditor;
5
7{
8 [CustomEditor(typeof(CUIImage))]
10 {
11 public override void OnInspectorGUI()
12 {
13 base.OnInspectorGUI();
14
15 CUIImage script = (CUIImage)this.target;
16
17 EditorGUILayout.Space();
18
19 EditorGUI.BeginChangeCheck();
20
21 EditorGUI.BeginDisabledGroup(!(script.UIImage.type == Image.Type.Sliced || script.UIImage.type == Image.Type.Tiled));
22 Vector2 newCornerRatio = EditorGUILayout.Vector2Field("Corner Ratio", script.cornerPosRatio);
23 if (EditorGUI.EndChangeCheck())
24 {
25 Undo.RecordObject(script, "Change Corner Ratio");
26 EditorUtility.SetDirty(script);
27 script.cornerPosRatio = newCornerRatio;
28 }
29
30 if (GUILayout.Button("Use native corner ratio"))
31 {
32 Undo.RecordObject(script, "Change Corner Ratio");
33 EditorUtility.SetDirty(script);
34 script.cornerPosRatio = script.OriCornerPosRatio;
35 }
36
37 if (script.UIImage.type == Image.Type.Sliced || script.UIImage.type == Image.Type.Filled)
38 {
39 EditorGUILayout.HelpBox("With CUIImage, you can also adjust the size of the corners for filled or sliced Image. The grey sphere in the editor scene could also be moved to change the corner's size.", MessageType.Info);
40 }
41 else
42 {
43 EditorGUILayout.HelpBox("With CUIImage, you can also adjust the size of the corners for filled or sliced Image. You need to set Image to filled or sliced to use this feature.", MessageType.Info);
44 }
45
46 EditorGUI.EndDisabledGroup();
47 }
48
49 protected override void OnSceneGUI()
50 {
51 base.OnSceneGUI();
52
53 CUIImage script = (CUIImage)this.target;
54
55 if (script.UIImage.type == Image.Type.Sliced || script.UIImage.type == Image.Type.Tiled)
56 {
57 Vector3 cornerPos = Vector3.zero;//
58
59 if (script.IsCurved)
60 {
61 cornerPos = script.GetBCurveSandwichSpacePoint(script.cornerPosRatio.x, script.cornerPosRatio.y);
62 }
63 else
64 {
65 cornerPos.x = script.cornerPosRatio.x * script.RectTrans.rect.width - script.RectTrans.pivot.x * script.RectTrans.rect.width;
66 cornerPos.y = script.cornerPosRatio.y * script.RectTrans.rect.height - script.RectTrans.pivot.y * script.RectTrans.rect.height;
67 }
68
69 Handles.color = Color.gray;
70 EditorGUI.BeginChangeCheck();
71 Vector3 newCornerPos = Handles.FreeMoveHandle(script.transform.TransformPoint(cornerPos), script.transform.rotation, HandleUtility.GetHandleSize(script.transform.TransformPoint(cornerPos)) / 7, Vector3.one, Handles.SphereHandleCap);
72 Handles.Label(newCornerPos, string.Format("Corner Mover"));
73
74 newCornerPos = script.transform.InverseTransformPoint(newCornerPos);
75
76 if (EditorGUI.EndChangeCheck())
77 {
78 Undo.RecordObject(script, "Move Corner");
79 EditorUtility.SetDirty(script);
80
81 script.cornerPosRatio = new Vector2(newCornerPos.x, newCornerPos.y);
82 script.cornerPosRatio.x = (script.cornerPosRatio.x + script.RectTrans.pivot.x * script.RectTrans.rect.width) / script.RectTrans.rect.width;
83 script.cornerPosRatio.y = (script.cornerPosRatio.y + script.RectTrans.pivot.y * script.RectTrans.rect.height) / script.RectTrans.rect.height;
84 }
85 }
86 }
87 }
88}
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32
Vector3 GetBCurveSandwichSpacePoint(float _xTime, float _yTime)
Definition: CUIGraphic.cs:603
Credit Erdener Gonenc - @PixelEnvision.