10using System.Collections.Generic;
17 [CanEditMultipleObjects]
18 [CustomEditor(typeof(LeapSlicedGraphic), editorForChildClasses:
true)]
24 specifyCustomDrawer(
"_sourceDataIndex", drawSourceData);
26 specifyCustomDrawer(
"_resolution_verts_per_meter", drawResolution);
28 specifyCustomDecorator(
"_size", decorateSize);
29 specifyCustomPostDecorator(
"_size", postDecorateSize);
31 specifyCustomDrawer(
"_nineSliced", drawSize);
35 base.OnInspectorGUI();
37 serializedObject.ApplyModifiedProperties();
38 foreach (var target
in targets) {
39 if (!target.canNineSlice) {
40 target.nineSliced =
false;
43 serializedObject.Update();
46 private void drawSourceData(SerializedProperty property) {
47 serializedObject.ApplyModifiedProperties();
49 var mainGroup = targets.Query().
50 Select(t => t.attachedGroup).
51 FirstOrDefault(g => g !=
null);
54 if (mainGroup ==
null) {
59 if (targets.Query().Any(p => p.attachedGroup != mainGroup)) {
63 var features =
new List<LeapGraphicFeatureBase>();
64 foreach (var feature
in mainGroup.features) {
65 if (feature is LeapTextureFeature || feature is LeapSpriteFeature) {
66 features.Add(feature);
70 if (features.Count == 1) {
75 foreach (var target
in targets) {
77 if (target.sourceData ==
null) {
81 int dataIndex = features.IndexOf(target.sourceData.feature);
86 else if (index != dataIndex) {
92 string[] options = features.Query().Select(f => {
93 if (f is LeapTextureFeature) {
94 return (f as LeapTextureFeature).propertyName +
" (Texture)";
97 return (f as LeapSpriteFeature).propertyName +
" (Sprite)";
101 EditorGUI.BeginChangeCheck();
104 EditorGUI.showMixedValue =
true;
107 int newIndex = EditorGUILayout.Popup(
"Data Source", index, options);
109 EditorGUI.showMixedValue =
false;
111 if (EditorGUI.EndChangeCheck()) {
112 foreach (var target
in targets) {
113 List<LeapFeatureData> data = target.featureData.Query().Where(f => f is LeapTextureData || f is LeapSpriteData).ToList();
115 Undo.RecordObject(target,
"Setting source data");
116 target.sourceData = data[newIndex];
120 serializedObject.Update();
123 private void drawResolution(SerializedProperty property) {
124 LeapPanelOutlineGraphic.ResolutionType mainType = targets[0].resolutionType;
125 bool allSameType = targets.Query().All(p => p.resolutionType == mainType);
131 Rect rect = EditorGUILayout.GetControlRect();
133 GUIContent resolutionContent =
new GUIContent(
"Resolution");
134 if (mainType == LeapPanelOutlineGraphic.ResolutionType.Vertices) {
135 resolutionContent.tooltip =
"How many vertices this panel should have in the x and y direction. These values ignore the edges (0 is a valid resolution).";
138 resolutionContent.tooltip =
"How many vertices this panel should spawn relative to the width and height of the panel. The panel will always have enough vertices to form a quad.";
140 EditorGUI.LabelField(rect, resolutionContent);
142 rect.x += EditorGUIUtility.labelWidth - 2;
143 rect.width -= EditorGUIUtility.labelWidth;
144 rect.width *= 2.0f / 3.0f;
146 float originalWidth = EditorGUIUtility.labelWidth;
147 EditorGUIUtility.labelWidth = 14;
152 right.x += right.width + 1;
154 if (mainType == LeapPanelOutlineGraphic.ResolutionType.Vertices) {
155 SerializedProperty x = serializedObject.FindProperty(
"_resolution_vert_x");
156 SerializedProperty y = serializedObject.FindProperty(
"_resolution_vert_y");
158 x.intValue = EditorGUI.IntField(left,
"X", x.intValue);
159 y.intValue = EditorGUI.IntField(right,
"Y", y.intValue);
162 Vector2 value =
property.vector2Value;
164 value.x = EditorGUI.FloatField(left,
"X", value.x);
165 value.y = EditorGUI.FloatField(right,
"Y", value.y);
167 property.vector2Value = value;
170 EditorGUIUtility.labelWidth = originalWidth;
173 private void decorateSize(SerializedProperty property) {
174 EditorGUI.BeginDisabledGroup(targets.Query().Any((t) => t.GetComponent<RectTransform>() !=
null));
177 private void postDecorateSize(SerializedProperty property) {
178 EditorGUI.EndDisabledGroup();
181 private void drawSize(SerializedProperty property) {
182 using (
new GUILayout.HorizontalScope()) {
183 var canAllNineSlice = targets.Query().All(p => p.canNineSlice);
184 using (
new EditorGUI.DisabledGroupScope(!canAllNineSlice)) {
185 EditorGUILayout.PropertyField(property);
188 if (targets.Length == 1) {
189 var rectTransform = target.GetComponent<RectTransform>();
190 if (rectTransform ==
null) {
191 if (GUILayout.Button(
"Add Rect Transform", GUILayout.MaxWidth(150))) {
192 Vector2 initialSize = target.rect.size;
194 rectTransform = target.gameObject.AddComponent<RectTransform>();
195 rectTransform.sizeDelta = initialSize;
override void OnInspectorGUI()