/// <summary> /// Helper function that draws a compact Rect. /// </summary> static public void DrawRectProperty(string name, SerializedObject serializedObject, string field, float labelWidth, float spacing) { if (serializedObject.FindProperty(field) != null) { GUILayout.BeginHorizontal(); { GUILayout.Label(name, GUILayout.Width(labelWidth)); UGUIEditorTools.SetLabelWidth(20f); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("X", serializedObject, field + ".x", GUILayout.MinWidth(50f)); UGUIEditorTools.DrawProperty("Y", serializedObject, field + ".y", GUILayout.MinWidth(50f)); GUILayout.EndVertical(); UGUIEditorTools.SetLabelWidth(50f); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("Width", serializedObject, field + ".width", GUILayout.MinWidth(80f)); UGUIEditorTools.DrawProperty("Height", serializedObject, field + ".height", GUILayout.MinWidth(80f)); GUILayout.EndVertical(); UGUIEditorTools.SetLabelWidth(80f); if (spacing != 0f) { GUILayout.Space(spacing); } } GUILayout.EndHorizontal(); } }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected virtual bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (UGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UGUIAtlas>(OnSelectAtlas); } SerializedProperty atlas = UGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UGUIAtlas atl = atlas.objectReferenceValue as UGUIAtlas; UGUISettings.atlas = atl; UGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); UGUISprite uguiSprite = target as UGUISprite; string spriteName = uguiSprite.sprite == null ? "" : uguiSprite.sprite.name; UGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UGUIAtlas, spriteName, SelectSprite, true); return(true); }
/// <summary> /// Helper function that draws a compact Vector4. /// </summary> static public void DrawBorderProperty(string name, SerializedObject serializedObject, string field) { if (serializedObject.FindProperty(field) != null) { GUILayout.BeginHorizontal(); { GUILayout.Label(name, GUILayout.Width(75f)); UGUIEditorTools.SetLabelWidth(50f); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("Left", serializedObject, field + ".x", GUILayout.MinWidth(80f)); UGUIEditorTools.DrawProperty("Bottom", serializedObject, field + ".y", GUILayout.MinWidth(80f)); GUILayout.EndVertical(); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("Right", serializedObject, field + ".z", GUILayout.MinWidth(80f)); UGUIEditorTools.DrawProperty("Top", serializedObject, field + ".w", GUILayout.MinWidth(80f)); GUILayout.EndVertical(); UGUIEditorTools.SetLabelWidth(80f); } GUILayout.EndHorizontal(); } }
public override void OnInspectorGUI() { serializedObject.Update(); GUILayout.Space(6f); UGUIEditorTools.SetLabelWidth(80f); GUILayout.BeginHorizontal(); // Key not found in the localization file -- draw it as a text field SerializedProperty sp = UGUIEditorTools.DrawProperty("Key", serializedObject, "key"); string myKey = sp.stringValue; //Debug.Log(myKey); bool isPresent = !string.IsNullOrEmpty(myKey) && Localization.localizationHasBeenSet; GUI.color = isPresent ? Color.green : Color.red; GUILayout.BeginVertical(GUILayout.Width(22f)); GUILayout.Space(2f); GUILayout.Label(isPresent ? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f)); GUILayout.EndVertical(); GUI.color = Color.white; GUILayout.EndHorizontal(); if (isPresent) { if (UGUIEditorTools.DrawHeader("Preview")) { UGUIEditorTools.BeginContents(); string[] keys; string[] values; string value; if (Localization.dictionary.TryGetValue(myKey, out value)) { keys = new string[] { myKey }; values = new string[] { value }; for (int i = 0; i < keys.Length; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label(keys[i], GUILayout.Width(70f)); if (GUILayout.Button(values[i], "AS TextArea", GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f))) { (target as UGUILocalize).value = values[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); } } else { GUILayout.Label("No preview available"); } UGUIEditorTools.EndContents(); } } else if (mKeys != null && !string.IsNullOrEmpty(myKey)) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); GUILayout.BeginVertical(); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f); int matches = 0; for (int i = 0; i < mKeys.Count; ++i) { if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey)) { if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge")) { sp.stringValue = mKeys[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } if (++matches == 8) { GUILayout.Label("...and more"); break; } } } GUI.backgroundColor = Color.white; GUILayout.EndVertical(); GUILayout.Space(22f); GUILayout.EndHorizontal(); } serializedObject.ApplyModifiedProperties(); }