/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties() { mLabel = mWidget as UILabel; GUILayout.BeginHorizontal(); #if DYNAMIC_FONT mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f)); if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f))) #else mFontType = FontType.NGUI; if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f))) #endif { if (mFontType == FontType.NGUI) { ComponentSelector.Show <UIFont>(OnNGUIFont); } else { ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } } bool isValid = false; SerializedProperty fnt = null; SerializedProperty ttf = null; if (mFontType == FontType.NGUI) { fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f)); if (fnt.objectReferenceValue != null) { NGUISettings.ambigiousFont = fnt.objectReferenceValue; isValid = true; } } else { ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f)); if (ttf.objectReferenceValue != null) { NGUISettings.ambigiousFont = ttf.objectReferenceValue; isValid = true; } } GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(!isValid); { UIFont uiFont = (fnt != null) ? fnt.objectReferenceValue as UIFont : null; Font dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null; if (uiFont != null && uiFont.isDynamic) { dynFont = uiFont.dynamicFont; uiFont = null; } if (dynFont != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); NGUISettings.fontSize = prop.intValue; prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f)); NGUISettings.fontStyle = (FontStyle)prop.intValue; GUILayout.Space(18f); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial"); } else if (uiFont != null) { GUILayout.BeginHorizontal(); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); EditorGUI.BeginDisabledGroup(true); if (!serializedObject.isEditingMultipleObjects) { GUILayout.Label(" Default: " + mLabel.defaultFontSize); } EditorGUI.EndDisabledGroup(); NGUISettings.fontSize = prop.intValue; GUILayout.EndHorizontal(); } bool ww = GUI.skin.textField.wordWrap; GUI.skin.textField.wordWrap = true; SerializedProperty sp = serializedObject.FindProperty("mText"); #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 GUI.changed = false; string text = EditorGUILayout.TextArea(sp.stringValue, GUI.skin.textArea, GUILayout.Height(100f)); if (GUI.changed) { sp.stringValue = text; } #else #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 GUILayout.Space(-16f); #endif if (sp.hasMultipleDifferentValues) { NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f)); } else { GUIStyle style = new GUIStyle(EditorStyles.textField); style.wordWrap = true; float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f); bool offset = true; if (height > 90f) { offset = false; height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(76f)); GUILayout.Space(3f); GUILayout.Label("Text"); GUILayout.EndVertical(); GUILayout.BeginVertical(); } Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height)); GUI.changed = false; string text = EditorGUI.TextArea(rect, sp.stringValue, style); if (GUI.changed) { sp.stringValue = text; } if (offset) { GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } #endif GUI.skin.textField.wordWrap = ww; SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow"); NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue; NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment"); if (dynFont != null) { NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk"); } EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader); GUILayout.BeginHorizontal(); SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", #if UNITY_3_5 GUILayout.Width(93f)); #else GUILayout.Width(95f)); #endif EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue); { NGUIEditorTools.SetLabelWidth(30f); NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(50f); #if UNITY_3_5 GUILayout.Space(81f); #else GUILayout.Space(79f); #endif NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f)); NGUIEditorTools.SetLabelWidth(80f); } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Effect", GUILayout.Width(76f)); sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f)); EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue); { NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(" ", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f)); GUILayout.Space(18f); NGUIEditorTools.SetLabelWidth(80f); } } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f)); GUILayout.Space(18f); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); GUILayout.BeginHorizontal(); sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f)); EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols); NGUIEditorTools.SetLabelWidth(60f); NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols"); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); return(isValid); }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties() { mLabel = mWidget as UILabel; GUILayout.BeginHorizontal(); #if DYNAMIC_FONT mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f)); if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f))) #else mFontType = FontType.NGUI; if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f))) #endif { if (mFontType == FontType.NGUI) { ComponentSelector.Show <UIFont>(OnNGUIFont); } else { ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } } bool isValid = false; SerializedProperty fnt = null; SerializedProperty ttf = null; if (mFontType == FontType.NGUI) { GUI.changed = false; fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f)); if (fnt.objectReferenceValue != null) { if (GUI.changed) { serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null; } NGUISettings.ambigiousFont = fnt.objectReferenceValue; isValid = true; } } else { GUI.changed = false; ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f)); if (ttf.objectReferenceValue != null) { if (GUI.changed) { serializedObject.FindProperty("mFont").objectReferenceValue = null; } NGUISettings.ambigiousFont = ttf.objectReferenceValue; isValid = true; } } GUILayout.EndHorizontal(); if (mFontType == FontType.Unity) { EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" + "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning); } EditorGUI.BeginDisabledGroup(!isValid); { UIFont uiFont = (fnt != null) ? fnt.objectReferenceValue as UIFont : null; Font dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null; if (uiFont != null && uiFont.isDynamic) { dynFont = uiFont.dynamicFont; uiFont = null; } if (dynFont != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); NGUISettings.fontSize = prop.intValue; prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f)); NGUISettings.fontStyle = (FontStyle)prop.intValue; NGUIEditorTools.DrawPadding(); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial"); } else if (uiFont != null) { GUILayout.BeginHorizontal(); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); EditorGUI.BeginDisabledGroup(true); if (!serializedObject.isEditingMultipleObjects) { if (mLabel.overflowMethod == UILabel.Overflow.ShrinkContent) { GUILayout.Label(" Actual: " + mLabel.finalFontSize + "/" + mLabel.defaultFontSize); } else { GUILayout.Label(" Default: " + mLabel.defaultFontSize); } } EditorGUI.EndDisabledGroup(); NGUISettings.fontSize = prop.intValue; GUILayout.EndHorizontal(); } bool ww = GUI.skin.textField.wordWrap; GUI.skin.textField.wordWrap = true; SerializedProperty sp = serializedObject.FindProperty("mText"); if (sp.hasMultipleDifferentValues) { NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f)); } else { GUIStyle style = new GUIStyle(EditorStyles.textField); style.wordWrap = true; float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f); bool offset = true; if (height > 90f) { offset = false; height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(76f)); GUILayout.Space(3f); GUILayout.Label("Text"); GUILayout.EndVertical(); GUILayout.BeginVertical(); } Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height)); GUI.changed = false; string text = EditorGUI.TextArea(rect, sp.stringValue, style); if (GUI.changed) { sp.stringValue = text; } if (offset) { GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } GUI.skin.textField.wordWrap = ww; SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow"); NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue; if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent) { NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f)); } if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely) { GUILayout.BeginHorizontal(); SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth"); if (s != null && s.intValue < 1) { GUILayout.Label("unlimited"); } GUILayout.EndHorizontal(); } NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment"); if (dynFont != null) { NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk"); } EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader); GUILayout.BeginHorizontal(); SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", GUILayout.Width(95f)); EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue); { NGUIEditorTools.SetLabelWidth(30f); NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(50f); GUILayout.Space(79f); NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f)); NGUIEditorTools.SetLabelWidth(80f); } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Effect", GUILayout.Width(76f)); sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f)); EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue); { NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(" ", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); } } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f)); if (!sp.boolValue) { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); GUILayout.BeginHorizontal(); sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f)); EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols); NGUIEditorTools.SetLabelWidth(60f); NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols"); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); return(isValid); }
public override void OnInspectorGUI() { mType = (Type)EditorGUILayout.EnumPopup("Type", mType); serializedObject.Update(); if (mType == Type.Manual) { NGUIEditorTools.DrawProperty("Thumbnail", serializedObject, "thumbnail"); } else { SerializedProperty sp = NGUIEditorTools.DrawProperty("Orthographic", serializedObject, "isOrthographic"); if (sp.hasMultipleDifferentValues) { NGUIEditorTools.DrawProperty("Ortho Size", serializedObject, "orthoSize"); NGUIEditorTools.DrawProperty("Field of View", serializedObject, "fieldOfView"); } else if (sp.boolValue) { NGUIEditorTools.DrawProperty("Ortho Size", serializedObject, "orthoSize"); } else { NGUIEditorTools.DrawProperty("Field of View", serializedObject, "fieldOfView"); } NGUIEditorTools.DrawProperty("Near Clip", serializedObject, "nearClip"); NGUIEditorTools.DrawProperty("Far Clip", serializedObject, "farClip"); } serializedObject.ApplyModifiedProperties(); GameObject prefab = GetPrefab(); if (prefab == null) { EditorGUILayout.HelpBox("This script should be attached to a prefab that you expect to place into the Prefab Toolbar. " + "It simply makes it easier to adjust the snapshot camera's settings.", MessageType.Info); } else if (GUILayout.Button("Update Snapshot")) { // Invalidate this prefab's preview if (UIPrefabTool.instance != null) { UISnapshotPoint snapshot = target as UISnapshotPoint; if (snapshot.isOrthographic) { target.name = "NGUI Snapshot Point " + snapshot.orthoSize; } else { target.name = "NGUI Snapshot Point " + snapshot.nearClip + " " + snapshot.farClip + " " + snapshot.fieldOfView; } UIPrefabTool.instance.RegenerateTexture(prefab, snapshot); UIPrefabTool.instance.Repaint(); } } }
protected override void OnDrawExtraFields() { NGUIEditorTools.DrawProperty("Thumb", serializedObject, "thumb"); }
/// <summary> /// Helper function that draws the suffix after the relative fields. /// </summary> void DrawAnchor(int index, bool targetSelection) { if (targetSelection) { GUILayout.Space(3f); } NGUIEditorTools.SetLabelWidth(16f); GUILayout.BeginHorizontal(); GUILayout.Label(PrefixName[index], GUILayout.Width(56f)); string name = FieldName[index]; SerializedProperty tar = serializedObject.FindProperty(name + ".target"); SerializedProperty rel = serializedObject.FindProperty(name + ".relative"); SerializedProperty abs = serializedObject.FindProperty(name + ".absolute"); if (targetSelection) { NGUIEditorTools.DrawProperty("", tar, false); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(64f); } UIRect targetRect = GetRect(tar); UIRect myRect = serializedObject.targetObject as UIRect; bool isRect = (targetRect != null); float relative = rel.floatValue; bool isCommon = !isRect || IsCommon(relative); int previousOrigin = 1; if (isRect) { if (mCustom[index] || !isCommon) { previousOrigin = 3; } else if (relative == 0f) { previousOrigin = 0; } else if (relative == 1f) { previousOrigin = 2; } } // Draw the origin selection list EditorGUI.BeginDisabledGroup(!isRect); int newOrigin = IsHorizontal[index] ? EditorGUILayout.Popup(previousOrigin, HorizontalList, GUILayout.MinWidth(110f)) : EditorGUILayout.Popup(previousOrigin, VerticalList, GUILayout.MinWidth(110f)); EditorGUI.EndDisabledGroup(); // "Set to Current" choice if (newOrigin == 4) { newOrigin = 3; Vector3[] sides = targetRect.GetSides(myRect.cachedTransform); float f0, f1; if (IsHorizontal[index]) { f0 = sides[0].x; f1 = sides[2].x; } else { f0 = sides[3].y; f1 = sides[1].y; } // Final position after both relative and absolute values are taken into consideration float final = Mathf.Floor(0.5f + Mathf.Lerp(0f, f1 - f0, rel.floatValue) + abs.intValue); rel.floatValue = final / (f1 - f0); abs.intValue = 0; serializedObject.ApplyModifiedProperties(); serializedObject.Update(); } mCustom[index] = (newOrigin == 3); // If the origin changes if (newOrigin != 3 && previousOrigin != newOrigin) { // Desired relative value if (newOrigin == 0) { relative = 0f; } else if (newOrigin == 2) { relative = 1f; } else { relative = 0.5f; } Vector3[] sides = targetRect.GetSides(myRect.cachedTransform); // Calculate the current position based from the bottom-left float f0, f1; if (IsHorizontal[index]) { f0 = sides[0].x; f1 = sides[2].x; } else { f0 = sides[3].y; f1 = sides[1].y; } // Final position after both relative and absolute values are taken into consideration float final = Mathf.Floor(0.5f + Mathf.Lerp(f0, f1, rel.floatValue) + abs.intValue); rel.floatValue = relative; abs.intValue = Mathf.FloorToInt(final + 0.5f - Mathf.Lerp(f0, f1, relative)); serializedObject.ApplyModifiedProperties(); serializedObject.Update(); } if (!mCustom[index]) { // Draw the absolute value NGUIEditorTools.SetLabelWidth(16f); NGUIEditorTools.DrawProperty("+", abs, true, GUILayout.MinWidth(10f)); } else { // Draw the relative value NGUIEditorTools.SetLabelWidth(16f); NGUIEditorTools.DrawProperty(" ", rel, true, GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(64f); relative = rel.floatValue; bool isOutside01 = relative <0f || relative> 1f; // Horizontal slider for relative values, for convenience EditorGUI.BeginDisabledGroup(isOutside01); { float val = GUILayout.HorizontalSlider(relative, 0f, 1f, GUILayout.MinWidth(110f)); if (!isOutside01 && val != relative) { Vector3[] sides = targetRect.GetSides(myRect.cachedTransform); // Calculate the current position based from the bottom-left float f0, f1; if (IsHorizontal[index]) { f0 = sides[0].x; f1 = sides[2].x; } else { f0 = sides[3].y; f1 = sides[1].y; } float size = (f1 - f0); int intVal = Mathf.FloorToInt(val * size + 0.5f); //intVal = ((intVal >> 1) << 1); rel.floatValue = intVal / size; } } EditorGUI.EndDisabledGroup(); // Draw the absolute value NGUIEditorTools.DrawProperty("+", abs, true, GUILayout.MinWidth(10f)); } GUILayout.EndHorizontal(); NGUIEditorTools.SetLabelWidth(62f); }
public override void OnInspectorGUI() { serializedObject.Update(); NGUIEditorTools.SetLabelWidth(100f); UIToggle toggle = target as UIToggle; GUILayout.Space(6f); GUI.changed = false; GUILayout.BeginHorizontal(); SerializedProperty sp = NGUIEditorTools.DrawProperty("Group", serializedObject, "group", GUILayout.Width(120f)); GUILayout.Label(" - zero means 'none'"); GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(sp.intValue == 0); NGUIEditorTools.DrawProperty(" State of 'None'", serializedObject, "optionCanBeNone"); EditorGUI.EndDisabledGroup(); NGUIEditorTools.DrawProperty("Starting State", serializedObject, "startsActive"); NGUIEditorTools.SetLabelWidth(80f); if (NGUIEditorTools.DrawMinimalisticHeader("State Transition")) { NGUIEditorTools.BeginContents(true); SerializedProperty sprite = serializedObject.FindProperty("activeSprite"); SerializedProperty animator = serializedObject.FindProperty("animator"); SerializedProperty animation = serializedObject.FindProperty("activeAnimation"); SerializedProperty tween = serializedObject.FindProperty("tween"); if (sprite.objectReferenceValue != null) { NGUIEditorTools.DrawProperty("Sprite", sprite, false); serializedObject.DrawProperty("invertSpriteState"); } else if (animator.objectReferenceValue != null) { NGUIEditorTools.DrawProperty("Animator", animator, false); } else if (animation.objectReferenceValue != null) { NGUIEditorTools.DrawProperty("Animation", animation, false); } else if (tween.objectReferenceValue != null) { NGUIEditorTools.DrawProperty("Tween", tween, false); } else { NGUIEditorTools.DrawProperty("Sprite", serializedObject, "activeSprite"); NGUIEditorTools.DrawProperty("Animator", animator, false); NGUIEditorTools.DrawProperty("Animation", animation, false); NGUIEditorTools.DrawProperty("Tween", tween, false); } if (serializedObject.isEditingMultipleObjects) { NGUIEditorTools.DrawProperty("Instant", serializedObject, "instantTween"); } else { GUI.changed = false; Transition tr = toggle.instantTween ? Transition.Instant : Transition.Smooth; GUILayout.BeginHorizontal(); tr = (Transition)EditorGUILayout.EnumPopup("Transition", tr); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Toggle Change", toggle); toggle.instantTween = (tr == Transition.Instant); NGUITools.SetDirty(toggle); } } NGUIEditorTools.EndContents(); } NGUIEditorTools.DrawEvents("On Value Change", toggle, toggle.onChange); serializedObject.ApplyModifiedProperties(); }
void DrawListLayout() { NGUIEditorTools.SetLabelWidth(80f); if (NGUIEditorTools.DrawHeader("List Layout")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } NGUIEditorTools.DrawProperty("", serializedObject, "atlas", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mList.atlas != null) { EditorGUILayout.Space(); NGUIEditorTools.DrawSpriteField("Background", serializedObject, serializedObject.FindProperty("atlas"), serializedObject.FindProperty("listBackgroundSprite"), true); NGUIEditorTools.DrawProperty("BG Color", serializedObject, "listBackgroundColor"); EditorGUILayout.Space(); NGUIEditorTools.DrawProperty("Offset", serializedObject, "listOffset"); EditorGUILayout.Space(); GUI.changed = false; NGUIEditorTools.IntVector paddingA = NGUIEditorTools.IntPair("Padding", "Left", "Right", mList.listPaddingLeft, mList.listPaddingRight); NGUIEditorTools.IntVector paddingB = NGUIEditorTools.IntPair(null, "Bottom", "Top", mList.listPaddingBottom, mList.listPaddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Select Field Padding Changed", mList); mList.listPaddingLeft = paddingA.x; mList.listPaddingRight = paddingA.y; mList.listPaddingBottom = paddingB.x; mList.listPaddingTop = paddingB.y; } EditorGUILayout.Space(); NGUIEditorTools.DrawProperty("Add to Size", serializedObject, "listAdditionalSize"); EditorGUILayout.Space(); NGUIEditorTools.DrawSpriteField("Separator", serializedObject, serializedObject.FindProperty("atlas"), serializedObject.FindProperty("listSeparatorSprite"), true); EditorGUILayout.Space(); GUI.changed = false; NGUIEditorTools.IntVector sepMarginA = NGUIEditorTools.IntPair("Sep margin", "Left", "Right", mList.listSepMarginLeft, mList.listSepMarginRight); NGUIEditorTools.IntVector sepMarginB = NGUIEditorTools.IntPair(null, "Bottom", "Top", mList.listSepMarginBottom, mList.listSepMarginTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Select Field Separator Margin Changed", mList); mList.listSepMarginLeft = sepMarginA.x; mList.listSepMarginRight = sepMarginA.y; mList.listSepMarginBottom = sepMarginB.x; mList.listSepMarginTop = sepMarginB.y; } } EditorGUILayout.Space(); NGUIEditorTools.DrawProperty("Animation", serializedObject, "listAnimation"); NGUIEditorTools.DrawProperty("An. Duration", serializedObject, "listAnimationDuration"); NGUIEditorTools.EndContents(); } }
public override void OnInspectorGUI() { serializedObject.Update(); GUILayout.Space(6f); NGUIEditorTools.SetLabelWidth(80f); GUILayout.BeginHorizontal(); // Key not found in the localization file -- draw it as a text field SerializedProperty sp = NGUIEditorTools.DrawProperty("Key", serializedObject, "key"); string myKey = sp.stringValue; bool isPresent = (mKeys != null) && mKeys.Contains(myKey); GUI.color = isPresent ? Color.green : Color.red; GUILayout.BeginVertical(GUILayout.Width(22f)); GUILayout.Space(2f); #if UNITY_3_5 GUILayout.Label(isPresent? "ok" : "!!", GUILayout.Height(20f)); #else GUILayout.Label(isPresent? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f)); #endif GUILayout.EndVertical(); GUI.color = Color.white; GUILayout.EndHorizontal(); if (isPresent) { if (NGUIEditorTools.DrawHeader("Preview")) { NGUIEditorTools.BeginContents(); string[] keys; string[] values; if (Localization.dictionary.TryGetValue("KEY", out keys) && Localization.dictionary.TryGetValue(myKey, out values)) { if (keys.Length != values.Length) { EditorGUILayout.HelpBox("Number of keys doesn't match the number of values! Did you modify the dictionaries by hand at some point?", MessageType.Error); } else { for (int i = 0; i < keys.Length; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label(keys[i], GUILayout.Width(66f)); if (GUILayout.Button(values[i], "AS TextArea", GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f))) { (target as UILocalize).value = values[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); } } } else { GUILayout.Label("No preview available"); } NGUIEditorTools.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, imax = mKeys.Count; i < imax; ++i) { if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey)) { #if UNITY_3_5 if (GUILayout.Button(mKeys[i] + " \u25B2")) #else if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge")) #endif { 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(); }
/// <summary> /// Draw the inspector widget. /// </summary> protected override bool ShouldDrawProperties() { mPanel.enableAlphaFunc = EditorGUILayout.Toggle("EnableAlphaFunc", mPanel.enableAlphaFunc); if (mPanel.enableAlphaFunc) { float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f); if (alpha != mPanel.alpha) { NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel); mPanel.alpha = alpha; } } GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Depth"); int depth = mPanel.depth; if (GUILayout.Button("Back", GUILayout.Width(60f))) { --depth; } depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f)); if (GUILayout.Button("Forward", GUILayout.Width(68f))) { ++depth; } if (mPanel.depth != depth) { NGUIEditorTools.RegisterUndo("Panel Depth", mPanel); mPanel.depth = depth; if (UIPanelTool.instance != null) { UIPanelTool.instance.Repaint(); } if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); int matchingDepths = 0; for (int i = 0, imax = UIPanel.list.Count; i < imax; ++i) { UIPanel p = UIPanel.list[i]; if (p != null && mPanel.depth == p.depth) { ++matchingDepths; } } if (matchingDepths > 1) { EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning); } UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping); if (mPanel.clipping != clipping) { mPanel.clipping = clipping; EditorUtility.SetDirty(mPanel); } if (mPanel.clipping != UIDrawCall.Clipping.None) { Vector4 range = mPanel.baseClipRegion; // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null); GUI.changed = false; GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipOffset = off; EditorUtility.SetDirty(mPanel); } //EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (size.x < 0f) { size.x = 0f; } if (size.y < 0f) { size.y = 0f; } range.x = pos.x; range.y = pos.y; range.z = size.x; range.w = size.y; if (mPanel.baseClipRegion != range) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.baseClipRegion = range; EditorUtility.SetDirty(mPanel); } if (mPanel.clipping == UIDrawCall.Clipping.SoftClip) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (soft.x < 0f) { soft.x = 0f; } if (soft.y < 0f) { soft.y = 0f; } if (mPanel.clipSoftness != soft) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipSoftness = soft; EditorUtility.SetDirty(mPanel); } } else if (mPanel.clipping == UIDrawCall.Clipping.TextureMask) { NGUIEditorTools.SetLabelWidth(0f); GUILayout.Space(-90f); Texture2D tex = (Texture2D)EditorGUILayout.ObjectField(mPanel.clipTexture, typeof(Texture2D), false, GUILayout.Width(70f), GUILayout.Height(70f)); GUILayout.Space(20f); if (mPanel.clipTexture != tex) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipTexture = tex; EditorUtility.SetDirty(mPanel); } NGUIEditorTools.SetLabelWidth(80f); } } if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale)) { EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error); if (GUILayout.Button("Auto-fix")) { NGUIEditorTools.FixUniform(mPanel.gameObject); } } if (NGUIEditorTools.DrawHeader("Advanced Options")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue); if (mPanel.renderQueue != rq) { mPanel.renderQueue = rq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } if (rq != UIPanel.RenderQueue.Automatic) { int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f)); if (mPanel.startingRenderQueue != sq) { mPanel.startingRenderQueue = sq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); GUI.changed = false; int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f)); if (GUI.changed) { mPanel.sortingOrder = so; } GUILayout.BeginHorizontal(); bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f)); GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.generateNormals != norms) { mPanel.generateNormals = norms; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f)); GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.cullWhileDragging != cull) { mPanel.cullWhileDragging = cull; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f)); GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.alwaysOnScreen != alw) { mPanel.alwaysOnScreen = alw; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool bLowFrequence = EditorGUILayout.Toggle("Low Frequence", mPanel.mbLowFrequence, GUILayout.Width(100f)); GUILayout.Label("LateUpdate will decrease frequence", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.mbLowFrequence != bLowFrequence) { mPanel.mbLowFrequence = bLowFrequence; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Padding", serializedObject, "softBorderPadding", GUILayout.Width(100f)); GUILayout.Label("Soft border pads content", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(mPanel.GetComponent <UIRoot>() != null); bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset && mPanel.GetComponent <UIRoot>() == null, GUILayout.Width(100f)); GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f)); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); if (mPanel.anchorOffset != off) { mPanel.anchorOffset = off; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f)); GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.widgetsAreStatic != stat) { mPanel.widgetsAreStatic = stat; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } if (stat) { EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning); } GUILayout.BeginHorizontal(); bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f)); GUILayout.Label("Show in panel tool"); GUILayout.EndHorizontal(); if (mPanel.showInPanelTool != tool) { mPanel.showInPanelTool = !mPanel.showInPanelTool; EditorUtility.SetDirty(mPanel); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } if (mPanel.clipping != UIDrawCall.Clipping.None) { GUILayout.BeginHorizontal(); bool dontRound = EditorGUILayout.Toggle("Dont Round", mPanel.dontRoundInClip, GUILayout.Width(100f)); GUILayout.Label("Dont Round In Clip"); GUILayout.EndHorizontal(); if (mPanel.dontRoundInClip != dontRound) { mPanel.dontRoundInClip = !mPanel.dontRoundInClip; NGUITools.SetDirty(mPanel); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } } NGUIEditorTools.EndContents(); } return(true); }
void DisplayCombatUnit() { _combatUnitFoldout = EditorGUILayout.Foldout(_combatUnitFoldout, new GUIContent("Combat unit", "Combat unit's image")); ++EditorGUI.indentLevel; if (_combatUnitFoldout) { int indexToRemoved = -1; //render each combat unit for (int i = 0; i < _target.combatUnitType.Count; i++) { EditorGUILayout.BeginHorizontal(); _combatUnitTypeFoldout[i] = EditorGUILayout.Foldout(_combatUnitTypeFoldout[i], _target.combatUnitType[i].ToString()); GUI.color = Color.red; if (GUILayout.Button(new GUIContent("X", "Delete combat unit type"), GUILayout.Width(30f))) { if (EditorUtility.DisplayDialogComplex("Delete this combat unit?", "Delete combat unit type " + _target.combatUnitType[i].ToString() + "?", "Ok", "Cancel", "") == 0) { indexToRemoved = i; } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (_combatUnitTypeFoldout[i]) { //set current working index combatUnitWorkingIndex = i; //only edit one at a time for (int j = 0; j < _combatUnitTypeFoldout.Count; j++) { if (i != j) { _combatUnitTypeFoldout[j] = false; } } ++EditorGUI.indentLevel; EditorGUILayout.Space(); //type EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Type:", "Combat unit type")); _target.combatUnitType[i] = (CombatUnitType)EditorGUILayout.EnumPopup(_target.combatUnitType[i]); EditorGUILayout.EndHorizontal(); //head image EditorGUILayout.LabelField(new GUIContent("Head image:", "Combat unit's head image")); EditorGUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlasForHead); } SerializedProperty headAtlas = serializedObject.FindProperty("combatUnitHeadAtlas").GetArrayElementAtIndex(i); NGUIEditorTools.DrawProperty("", headAtlas, GUILayout.MinWidth(20f)); EditorGUILayout.EndHorizontal(); NGUIEditorTools.DrawAdvancedSpriteField(headAtlas.objectReferenceValue as UIAtlas, _target.combatUnitHeadSpriteName[i], SelectSpriteForHead, false); if (string.IsNullOrEmpty(_target.combatUnitHeadSpriteName[i])) { EditorGUILayout.HelpBox("Please select a image for combat unit's head", MessageType.Error); } EditorGUILayout.Space(); //full body image EditorGUILayout.LabelField(new GUIContent("Full Body image:", "Combat unit's full body image")); EditorGUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlasForFullBody); } SerializedProperty fullBodyAtlas = serializedObject.FindProperty("combatunitFullBodyAtlas").GetArrayElementAtIndex(i); NGUIEditorTools.DrawProperty("", fullBodyAtlas, GUILayout.MinWidth(20f)); EditorGUILayout.EndHorizontal(); NGUIEditorTools.DrawAdvancedSpriteField(fullBodyAtlas.objectReferenceValue as UIAtlas, _target.combatUnitFullBodySpriteName[i], SelectSpriteForFullBody, false); if (string.IsNullOrEmpty(_target.combatUnitFullBodySpriteName[i])) { EditorGUILayout.HelpBox("Please select a image for combat unit's full body", MessageType.Error); } --EditorGUI.indentLevel; } } if (indexToRemoved >= 0) { _target.combatUnitType.RemoveAt(indexToRemoved); _target.combatUnitHeadSpriteName.RemoveAt(indexToRemoved); _target.combatUnitFullBodySpriteName.RemoveAt(indexToRemoved); _target.combatUnitHeadAtlas.RemoveAt(indexToRemoved); _target.combatunitFullBodyAtlas.RemoveAt(indexToRemoved); _combatUnitTypeFoldout.RemoveAt(indexToRemoved); serializedObject.Update(); } GUI.color = Color.green; if (GUILayout.Button(new GUIContent("+", "Add new combat unit's image"))) { _target.combatUnitType.Add(CombatUnitType.Unknow); _target.combatUnitHeadSpriteName.Add(""); _target.combatUnitFullBodySpriteName.Add(""); _target.combatUnitHeadAtlas.Add(NGUISettings.atlas); _target.combatunitFullBodyAtlas.Add(NGUISettings.atlas); _combatUnitTypeFoldout.Add(false); serializedObject.Update(); } GUI.color = Color.white; } --EditorGUI.indentLevel; }
/// <summary> /// Draw all the custom properties such as sprite type, flip setting, fill direction, etc. /// </summary> protected override void DrawCustomProperties() { GUILayout.Space(6f); SerializedProperty sp = NGUIEditorTools.DrawProperty("Type", serializedObject, "mType", GUILayout.MinWidth(20f)); UISprite.Type type = (UISprite.Type)sp.intValue; if (type == UISprite.Type.Simple || type == UISprite.Type.Sliced) { NGUIEditorTools.DrawBorderProperty("Trim", serializedObject, "mBorder"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); NGUIEditorTools.DrawProperty("Mirror", serializedObject, "mMirror"); ShowFillOptions(); EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues); { sp = serializedObject.FindProperty("centerType"); bool val = (sp.intValue != (int)UISprite.AdvancedType.Invisible); if (val != EditorGUILayout.Toggle("Fill Center", val)) { sp.intValue = val ? (int)UISprite.AdvancedType.Invisible : (int)UISprite.AdvancedType.Sliced; } NGUIEditorTools.DrawProperty("Fill Border", serializedObject, "mFillBorder"); } EditorGUI.EndDisabledGroup(); } else if (type == UISprite.Type.Tiled) { NGUIEditorTools.DrawBorderProperty("Trim", serializedObject, "mBorder"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); NGUIEditorTools.DrawProperty("Mirror", serializedObject, "mMirror"); NGUIEditorTools.DrawProperty("Tile Border", serializedObject, "mTileBorder"); } else if (type == UISprite.Type.Filled) { NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); NGUIEditorTools.DrawProperty("Fill Dir", serializedObject, "mFillDirection", GUILayout.MinWidth(20f)); UISprite.FillDirection fillDir = (UISprite.FillDirection)serializedObject.FindProperty("mFillDirection").intValue; if (fillDir != UISprite.FillDirection.Nothing) { GUILayout.BeginHorizontal(); GUILayout.Space(10f); GUILayout.BeginVertical(); NGUIEditorTools.DrawProperty("Fill Amount", serializedObject, "mFillAmount", GUILayout.MinWidth(20f)); NGUIEditorTools.DrawProperty("Invert Fill", serializedObject, "mInvert", GUILayout.MinWidth(20f)); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } else if (type == UISprite.Type.Advanced) { SerializedProperty mirrorSp = serializedObject.FindProperty("mMirror"); mirrorSp.intValue = (int)UISprite.Flip.Nothing; NGUIEditorTools.DrawBorderProperty("Border", serializedObject, "mBorder"); NGUIEditorTools.DrawProperty(" Left", serializedObject, "leftType"); NGUIEditorTools.DrawProperty(" Right", serializedObject, "rightType"); NGUIEditorTools.DrawProperty(" Top", serializedObject, "topType"); NGUIEditorTools.DrawProperty(" Bottom", serializedObject, "bottomType"); NGUIEditorTools.DrawProperty(" Center", serializedObject, "centerType"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); } if (type == UIBasicSprite.Type.Simple || type == UIBasicSprite.Type.Sliced) // Gradients get too complicated for tiled and filled. { GUILayout.BeginHorizontal(); SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", GUILayout.Width(95f)); EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue); { NGUIEditorTools.SetLabelWidth(30f); serializedObject.DrawProperty("mGradientTop", "Top", GUILayout.MinWidth(40f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(50f); GUILayout.Space(79f); serializedObject.DrawProperty("mGradientBottom", "Bottom", GUILayout.MinWidth(40f)); NGUIEditorTools.SetLabelWidth(80f); } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } base.DrawCustomProperties(); }
void DisplayResource() { _resourceFoldout = EditorGUILayout.Foldout(_resourceFoldout, new GUIContent("Resource", "Resource type's image")); ++EditorGUI.indentLevel; if (_resourceFoldout) { int indexToRemoved = -1; //render each resource for (int i = 0; i < _target.resourceType.Count; i++) { EditorGUILayout.BeginHorizontal(); _resourceTypeFoldout[i] = EditorGUILayout.Foldout(_resourceTypeFoldout[i], new GUIContent(_target.resourceType[i].ToString(), "Resource type's image")); GUI.color = Color.red; if (GUILayout.Button(new GUIContent("X", "Delete resource type"), GUILayout.Width(30f))) { if (EditorUtility.DisplayDialogComplex("Delete this resource?", "Delete resource type " + _target.resourceType[i].ToString() + "?", "Ok", "Cancel", "") == 0) { indexToRemoved = i; } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (_resourceTypeFoldout[i]) { resourceWorkingIndex = i; for (int j = 0; j < _resourceTypeFoldout.Count; j++) { if (i != j) { _resourceTypeFoldout[j] = false; } } ++EditorGUI.indentLevel; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Type:")); _target.resourceType[i] = (ResourceType)EditorGUILayout.EnumPopup(_target.resourceType[i]); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //Resource image EditorGUILayout.LabelField(new GUIContent("Resource image:", "Resource type's image")); EditorGUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlasForResource); } SerializedProperty resourceAtlas = serializedObject.FindProperty("resourceAtlas").GetArrayElementAtIndex(i); NGUIEditorTools.DrawProperty("", resourceAtlas, GUILayout.MinWidth(20f)); EditorGUILayout.EndHorizontal(); NGUIEditorTools.DrawAdvancedSpriteField(resourceAtlas.objectReferenceValue as UIAtlas, _target.resourceSpriteName[i], SelectSpriteForResource, false); if (string.IsNullOrEmpty(_target.resourceSpriteName[i])) { EditorGUILayout.HelpBox("Please select a image for resource type", MessageType.Error); } --EditorGUI.indentLevel; } } if (indexToRemoved >= 0) { _target.resourceType.RemoveAt(indexToRemoved); _target.resourceSpriteName.RemoveAt(indexToRemoved); _target.resourceAtlas.RemoveAt(indexToRemoved); _resourceTypeFoldout.RemoveAt(indexToRemoved); serializedObject.Update(); } GUI.color = Color.green; if (GUILayout.Button(new GUIContent("+", "Add new resource image"))) { _target.resourceType.Add(ResourceType.Unknow); _target.resourceSpriteName.Add(""); _target.resourceAtlas.Add(NGUISettings.atlas); _resourceTypeFoldout.Add(false); serializedObject.Update(); } GUI.color = Color.white; } --EditorGUI.indentLevel; }
/// <summary> /// Draw the inspector widget. /// </summary> protected override bool ShouldDrawProperties() { var alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f); if (alpha != mPanel.alpha) { NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel); mPanel.alpha = alpha; } GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Depth"); var depth = mPanel.depth; if (GUILayout.Button("Back", GUILayout.Width(60f))) { --depth; } depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f)); if (GUILayout.Button("Forward", GUILayout.Width(68f))) { ++depth; } if (mPanel.depth != depth) { NGUIEditorTools.RegisterUndo("Panel Depth", mPanel); mPanel.depth = depth; if (UIPanelTool.instance != null) { UIPanelTool.instance.Repaint(); } if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); var matchingDepths = 0; for (int i = 0, imax = UIPanel.list.Count; i < imax; ++i) { var p = UIPanel.list[i]; if (p != null && mPanel.depth == p.depth) { ++matchingDepths; } } if (matchingDepths > 1) { EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning); } var clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping); if (mPanel.clipping != clipping) { mPanel.clipping = clipping; EditorUtility.SetDirty(mPanel); } // Contributed by Benzino07: http://www.tasharen.com/forum/index.php?topic=6956.15 GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Sorting Layer"); // Get the names of the Sorting layers var internalEditorUtilityType = typeof(InternalEditorUtility); var sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); var names = (string[])sortingLayersProperty.GetValue(null, new object[0]); var index = 0; if (!string.IsNullOrEmpty(mPanel.sortingLayerName)) { for (var i = 0; i < names.Length; i++) { if (mPanel.sortingLayerName == names[i]) { index = i; break; } } } // Get the selected index and update the panel sorting layer if it has changed var selectedIndex = EditorGUILayout.Popup(index, names); if (index != selectedIndex) { mPanel.sortingLayerName = names[selectedIndex]; EditorUtility.SetDirty(mPanel); } } GUILayout.EndHorizontal(); if (mPanel.clipping != UIDrawCall.Clipping.None) { var range = mPanel.baseClipRegion; // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null); GUI.changed = false; GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipOffset = off; EditorUtility.SetDirty(mPanel); } //EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); var pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); var size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (size.x < 0f) { size.x = 0f; } if (size.y < 0f) { size.y = 0f; } range.x = pos.x; range.y = pos.y; range.z = size.x; range.w = size.y; if (mPanel.baseClipRegion != range) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.baseClipRegion = range; EditorUtility.SetDirty(mPanel); } if (mPanel.clipping == UIDrawCall.Clipping.SoftClip) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); var soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (soft.x < 0f) { soft.x = 0f; } if (soft.y < 0f) { soft.y = 0f; } if (mPanel.clipSoftness != soft) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipSoftness = soft; EditorUtility.SetDirty(mPanel); } } else if (mPanel.clipping == UIDrawCall.Clipping.TextureMask) { NGUIEditorTools.SetLabelWidth(0f); GUILayout.Space(-90f); var tex = (Texture2D)EditorGUILayout.ObjectField(mPanel.clipTexture, typeof(Texture2D), false, GUILayout.Width(70f), GUILayout.Height(70f)); GUILayout.Space(20f); if (mPanel.clipTexture != tex) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipTexture = tex; EditorUtility.SetDirty(mPanel); } NGUIEditorTools.SetLabelWidth(80f); } } if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale)) { EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error); if (GUILayout.Button("Auto-fix")) { NGUIEditorTools.FixUniform(mPanel.gameObject); } } if (NGUIEditorTools.DrawHeader("Advanced Options")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); var rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue); if (mPanel.renderQueue != rq) { mPanel.renderQueue = rq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } if (rq != UIPanel.RenderQueue.Automatic) { var sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f)); if (mPanel.startingRenderQueue != sq) { mPanel.startingRenderQueue = sq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); GUI.changed = false; var so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f)); if (GUI.changed) { mPanel.sortingOrder = so; } GUILayout.BeginHorizontal(); var norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f)); GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.generateNormals != norms) { mPanel.generateNormals = norms; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); var cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f)); GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.cullWhileDragging != cull) { mPanel.cullWhileDragging = cull; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); var alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f)); GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.alwaysOnScreen != alw) { mPanel.alwaysOnScreen = alw; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Padding", serializedObject, "softBorderPadding", GUILayout.Width(100f)); GUILayout.Label("Soft border pads content", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(mPanel.GetComponent <UIRoot>() != null); var off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset && mPanel.GetComponent <UIRoot>() == null, GUILayout.Width(100f)); GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f)); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); if (mPanel.anchorOffset != off) { mPanel.anchorOffset = off; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); var stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f)); GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.widgetsAreStatic != stat) { mPanel.widgetsAreStatic = stat; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } if (stat) { EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning); } GUILayout.BeginHorizontal(); var tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f)); GUILayout.Label("Show in panel tool"); GUILayout.EndHorizontal(); if (mPanel.showInPanelTool != tool) { mPanel.showInPanelTool = !mPanel.showInPanelTool; EditorUtility.SetDirty(mPanel); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } NGUIEditorTools.EndContents(); } return(true); }
/// <summary> /// Draw all the custom properties such as sprite type, flip setting, fill direction, etc. /// </summary> protected override void DrawCustomProperties() { GUILayout.Space(6f); SerializedProperty sp = NGUIEditorTools.DrawProperty("Type", serializedObject, "mType", GUILayout.MinWidth(20f)); UISprite.Type type = (UISprite.Type)sp.intValue; if (type == UISprite.Type.Simple) { NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); } else if (type == UISprite.Type.Tiled) { NGUIEditorTools.DrawBorderProperty("Trim", serializedObject, "mBorder"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); } else if (type == UISprite.Type.Sliced) { NGUIEditorTools.DrawBorderProperty("Border", serializedObject, "mBorder"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues); { sp = serializedObject.FindProperty("centerType"); bool val = (sp.intValue != (int)UISprite.AdvancedType.Invisible); if (val != EditorGUILayout.Toggle("Fill Center", val)) { sp.intValue = val ? (int)UISprite.AdvancedType.Invisible : (int)UISprite.AdvancedType.Sliced; } } EditorGUI.EndDisabledGroup(); } else if (type == UISprite.Type.Filled) { NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); NGUIEditorTools.DrawProperty("Fill Dir", serializedObject, "mFillDirection", GUILayout.MinWidth(20f)); GUILayout.BeginHorizontal(); GUILayout.Space(4f); NGUIEditorTools.DrawProperty("Fill Amount", serializedObject, "mFillAmount", GUILayout.MinWidth(20f)); GUILayout.Space(4f); GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Invert Fill", serializedObject, "mInvert", GUILayout.MinWidth(20f)); } else if (type == UIBasicSprite.Type.SlicedFilled) { NGUIEditorTools.DrawBorderProperty("Border", serializedObject, "mBorder"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); NGUIEditorTools.DrawProperty("Fill Dir", serializedObject, "mFillDirection", GUILayout.MinWidth(20f)); GUILayout.BeginHorizontal(); GUILayout.Space(4f); NGUIEditorTools.DrawProperty("Fill Amount", serializedObject, "mFillAmount", GUILayout.MinWidth(20f)); GUILayout.Space(4f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(4f); NGUIEditorTools.DrawProperty("Vertex Offset", serializedObject, "mVertexOffset", GUILayout.MinWidth(20f)); GUILayout.Space(4f); GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Invert Fill", serializedObject, "mInvert", GUILayout.MinWidth(20f)); } else if (type == UISprite.Type.Advanced) { NGUIEditorTools.DrawBorderProperty("Border", serializedObject, "mBorder"); NGUIEditorTools.DrawProperty(" Left", serializedObject, "leftType"); NGUIEditorTools.DrawProperty(" Right", serializedObject, "rightType"); NGUIEditorTools.DrawProperty(" Top", serializedObject, "topType"); NGUIEditorTools.DrawProperty(" Bottom", serializedObject, "bottomType"); NGUIEditorTools.DrawProperty(" Center", serializedObject, "centerType"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); } GUI.changed = false; Vector4 draw = EditorGUILayout.Vector4Field("Draw Region", mWidget.drawRegion); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Draw Region", mWidget); mWidget.drawRegion = draw; } GUI.changed = false; var basicSprite = mWidget as UIBasicSprite; Vector4 draw2 = EditorGUILayout.Vector4Field("Edge Cutoff", basicSprite.edgeCutoff); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Edge Cutoff", basicSprite); basicSprite.edgeCutoff = draw2; } base.DrawCustomProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); NGUIEditorTools.SetLabelWidth(80f); mList = target as UIPopupList; UILabel lbl = EditorGUILayout.ObjectField("Text Label", mList.textLabel, typeof(UILabel), true) as UILabel; if (mList.textLabel != lbl) { RegisterUndo(); mList.textLabel = lbl; if (lbl != null) { lbl.text = mList.value; } } if (mList.textLabel == null) { EditorGUILayout.HelpBox("This popup list has no label to update, so it will behave like a menu.", MessageType.Info); } if (mList.atlas != null) { GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUILayout.Label("Options"); GUILayout.EndHorizontal(); string text = ""; foreach (string s in mList.items) { text += s + "\n"; } GUILayout.Space(-14f); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string modified = EditorGUILayout.TextArea(text, GUILayout.Height(100f)); GUILayout.EndHorizontal(); if (modified != text) { RegisterUndo(); string[] split = modified.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries); mList.items.Clear(); foreach (string s in split) { mList.items.Add(s); } if (string.IsNullOrEmpty(mList.value) || !mList.items.Contains(mList.value)) { mList.value = mList.items.Count > 0 ? mList.items[0] : ""; } } GUI.changed = false; string sel = NGUIEditorTools.DrawList("Default", mList.items.ToArray(), mList.value); if (GUI.changed) { serializedObject.FindProperty("mSelectedItem").stringValue = sel; } NGUIEditorTools.DrawProperty("Position", serializedObject, "position"); NGUIEditorTools.DrawProperty("Localized", serializedObject, "isLocalized"); DrawAtlas(); DrawFont(); NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUILayout.Label("Options"); GUILayout.EndHorizontal(); string text = ""; foreach (string s in mList.items) { text += s + "\n"; } GUILayout.Space(-14f); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string modified = EditorGUILayout.TextArea(text, GUILayout.Height(100f)); GUILayout.EndHorizontal(); if (modified != text) { RegisterUndo(); string[] split = modified.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries); mList.items.Clear(); foreach (string s in split) { mList.items.Add(s); } if (string.IsNullOrEmpty(mList.value) || !mList.items.Contains(mList.value)) { mList.value = mList.items.Count > 0 ? mList.items[0] : ""; } } NGUIEditorTools.DrawProperty("Position", serializedObject, "position"); NGUIEditorTools.DrawProperty("Alignment", serializedObject, "alignment"); NGUIEditorTools.DrawProperty("Open on", serializedObject, "openOn"); NGUIEditorTools.DrawProperty("On Top", serializedObject, "separatePanel"); NGUIEditorTools.DrawProperty("Localized", serializedObject, "isLocalized"); GUI.changed = false; var sp = NGUIEditorTools.DrawProperty("Keep Value", serializedObject, "keepValue"); if (GUI.changed) { serializedObject.FindProperty("mSelectedItem").stringValue = (sp.boolValue && mList.items.Count > 0) ? mList.items[0] : ""; } EditorGUI.BeginDisabledGroup(!sp.boolValue); { GUI.changed = false; string sel = NGUIEditorTools.DrawList("Initial Value", mList.items.ToArray(), mList.value); if (GUI.changed) { serializedObject.FindProperty("mSelectedItem").stringValue = sel; } } EditorGUI.EndDisabledGroup(); DrawAtlas(); DrawFont(); NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange); serializedObject.ApplyModifiedProperties(); }
protected override void DrawProperties() { base.DrawProperties(); NGUIEditorTools.DrawProperty("Text", serializedObject, "buttonLabel"); }
public override void OnInspectorGUI() { GUILayout.Space(6f); NGUIEditorTools.SetLabelWidth(90f); string error = null; UIScrollView sv = null; if (!serializedObject.isEditingMultipleObjects) { UIWrapContent list = target as UIWrapContent; sv = NGUITools.FindInParents <UIScrollView>(list.gameObject); if (sv == null) { error = "UIWrappedList needs a Scroll View on its parent in order to work properly"; } else if (sv.movement != UIScrollView.Movement.Horizontal && sv.movement != UIScrollView.Movement.Vertical) { error = "Scroll View needs to be using Horizontal or Vertical movement"; } } serializedObject.Update(); NGUIEditorTools.DrawProperty("Item Width", serializedObject, "itemWidth"); NGUIEditorTools.DrawProperty("Item Height", serializedObject, "itemHeight"); GUILayout.BeginHorizontal(); SerializedProperty sp = NGUIEditorTools.DrawProperty("Column Limit", serializedObject, "maxPerLine", GUILayout.Width(130f)); NGUIEditorTools.SetLabelWidth(90f); if (sp.intValue <= 0) { if (sv != null) { if (sv.movement == UIScrollView.Movement.Horizontal) { GUILayout.Label("horizontal unlimited"); } else { GUILayout.Label("vertical unlimited"); } } else { GUILayout.Label("unlimited"); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); SerializedProperty sp1 = NGUIEditorTools.DrawProperty("Range Limit", serializedObject, "minIndex", GUILayout.Width(130f)); NGUIEditorTools.SetLabelWidth(20f); SerializedProperty sp2 = NGUIEditorTools.DrawProperty("to", serializedObject, "maxIndex", GUILayout.Width(60f)); NGUIEditorTools.SetLabelWidth(90f); if (sp1.intValue == sp2.intValue) { GUILayout.Label("unlimited"); } GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Cull Content", serializedObject, "cullContent"); if (sv != null) { if (sv.movement == UIScrollView.Movement.Horizontal) { NGUIEditorTools.DrawProperty("Left Arrow", serializedObject, "arrow1"); NGUIEditorTools.DrawProperty("Right Arrow", serializedObject, "arrow2"); } else { NGUIEditorTools.DrawProperty("Top Arrow", serializedObject, "arrow1"); NGUIEditorTools.DrawProperty("Bottom Arrow", serializedObject, "arrow2"); } } NGUIEditorTools.DrawProperty("Debug", serializedObject, "isDebug"); if (!string.IsNullOrEmpty(error)) { EditorGUILayout.HelpBox(error, MessageType.Error); if (sv != null && GUILayout.Button("Select the Scroll View")) { Selection.activeGameObject = sv.gameObject; } } serializedObject.ApplyModifiedProperties(); if (sp1.intValue != sp2.intValue) { if ((target as UIWrapContent).GetComponent <UICenterOnChild>() != null) { EditorGUILayout.HelpBox("Limiting indices doesn't play well with UICenterOnChild. You should either not limit the indices, or not use UICenterOnChild.", MessageType.Warning); } } }
protected override void DrawProperties() { NGUIEditorTools.DrawProperty("Label", serializedObject, "Label"); NGUIEditorTools.DrawProperty("relateChild", serializedObject, "relateChild"); base.DrawProperties(); }
public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(130f); GUILayout.Space(3f); serializedObject.Update(); SerializedProperty sppv = serializedObject.FindProperty("contentPivot"); UIWidget.Pivot before = (UIWidget.Pivot)sppv.intValue; NGUIEditorTools.DrawProperty("Content Origin", sppv, false); SerializedProperty sp = NGUIEditorTools.DrawProperty("Movement", serializedObject, "movement"); if (((UIScrollView.Movement)sp.intValue) == UIScrollView.Movement.Custom) { NGUIEditorTools.SetLabelWidth(20f); GUILayout.BeginHorizontal(); GUILayout.Space(114f); NGUIEditorTools.DrawProperty("X", serializedObject, "customMovement.x", GUILayout.MinWidth(20f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "customMovement.y", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); } NGUIEditorTools.SetLabelWidth(130f); NGUIEditorTools.DrawProperty("Drag Effect", serializedObject, "dragEffect"); NGUIEditorTools.DrawProperty("Scroll Wheel Factor", serializedObject, "scrollWheelFactor"); NGUIEditorTools.DrawProperty("Momentum Amount", serializedObject, "momentumAmount"); NGUIEditorTools.DrawProperty("Restrict Within Panel", serializedObject, "restrictWithinPanel"); NGUIEditorTools.DrawProperty("Cancel Drag If Fits", serializedObject, "disableDragIfFits"); NGUIEditorTools.DrawProperty("Smooth Drag Start", serializedObject, "smoothDragStart"); NGUIEditorTools.DrawProperty("IOS Drag Emulation", serializedObject, "iOSDragEmulation"); NGUIEditorTools.SetLabelWidth(100f); if (NGUIEditorTools.DrawHeader("Scroll Bars")) { NGUIEditorTools.BeginContents(); NGUIEditorTools.DrawProperty("Horizontal", serializedObject, "horizontalScrollBar"); NGUIEditorTools.DrawProperty("Vertical", serializedObject, "verticalScrollBar"); NGUIEditorTools.DrawProperty("page", serializedObject, "PageBar"); NGUIEditorTools.DrawProperty("Show Condition", serializedObject, "showScrollBars"); NGUIEditorTools.DrawProperty("Darg Begin", serializedObject, "DargBegin"); NGUIEditorTools.DrawProperty("Darg End", serializedObject, "DargEnd"); NGUIEditorTools.DrawProperty("Undarg Begin", serializedObject, "UndargBegin"); NGUIEditorTools.DrawProperty("UndargEnd", serializedObject, "UndargEnd"); NGUIEditorTools.EndContents(); } NGUIEditorTools.DrawProperty("This Grid", serializedObject, "thisGrid"); serializedObject.ApplyModifiedProperties(); if (before != (UIWidget.Pivot)sppv.intValue) { (target as UIScrollView).ResetPosition(); } }
public override void OnInspectorGUI() { serializedObject.Update(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUILayout.Label("Options"); GUILayout.EndHorizontal(); string text = ""; foreach (string s in mList.items) { text += s + "\n"; } GUILayout.Space(-14f); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string modified = EditorGUILayout.TextArea(text, GUI.skin.textArea, GUILayout.Height(100f)); GUILayout.EndHorizontal(); if (modified != text) { RegisterUndo(); string[] split = modified.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries); mList.items.Clear(); foreach (string s in split) { mList.items.Add(s); } if (string.IsNullOrEmpty(mList.value) || !mList.items.Contains(mList.value)) { mList.value = mList.items.Count > 0 ? mList.items[0] : ""; } } GUI.changed = false; string sel = NGUIEditorTools.DrawList("Default", mList.items.ToArray(), mList.value); if (GUI.changed) { serializedObject.FindProperty("mSelectedItem").stringValue = sel; } NGUIEditorTools.DrawProperty("Position", serializedObject, "position"); NGUIEditorTools.DrawProperty("Localized", serializedObject, "isLocalized"); EditorGUILayout.Space(); DrawLabelLayout(); DrawSelectField(); DrawArrowSprites(); DrawListLayout(); DrawListHighlightLayout(); DrawFont(); NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); NGUIEditorTools.SetLabelWidth(80f); UIButton button = target as UIButton; GUILayout.Space(6f); if (!serializedObject.isEditingMultipleObjects) { GUI.changed = false; GameObject tt = (GameObject)EditorGUILayout.ObjectField("Target", button.tweenTarget, typeof(GameObject), true); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Button Change", button); button.tweenTarget = tt; UnityEditor.EditorUtility.SetDirty(button); } if (tt != null) { UIWidget w = tt.GetComponent <UIWidget>(); if (w != null) { GUI.changed = false; Color c = EditorGUILayout.ColorField("Normal", w.color); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Button Change", w); w.color = c; UnityEditor.EditorUtility.SetDirty(w); } } } } NGUIEditorTools.DrawProperty("Hover", serializedObject, "hover"); NGUIEditorTools.DrawProperty("Pressed", serializedObject, "pressed"); NGUIEditorTools.DrawProperty("Disabled", serializedObject, "disabledColor"); SerializedProperty sp = serializedObject.FindProperty("dragHighlight"); Highlight ht = sp.boolValue ? Highlight.Press : Highlight.DoNothing; GUILayout.BeginHorizontal(); bool highlight = (Highlight)EditorGUILayout.EnumPopup("Drag Over", ht) == Highlight.Press; GUILayout.Space(18f); GUILayout.EndHorizontal(); if (sp.boolValue != highlight) { sp.boolValue = highlight; } GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Transition", serializedObject, "duration", GUILayout.Width(120f)); GUILayout.Label("seconds"); GUILayout.EndHorizontal(); serializedObject.ApplyModifiedProperties(); GUILayout.Space(3f); NGUIEditorTools.DrawEvents("On Click", button, button.onClick); }
protected override void DrawProperties() { SerializedProperty sp = serializedObject.FindProperty("dragHighlight"); Highlight ht = sp.boolValue ? Highlight.Press : Highlight.DoNothing; GUILayout.BeginHorizontal(); bool highlight = (Highlight)EditorGUILayout.EnumPopup("Drag Over", ht) == Highlight.Press; NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (sp.boolValue != highlight) { sp.boolValue = highlight; } DrawTransition(); DrawColors(); UIButton btn = target as UIButton; if (btn.tweenTarget != null) { UISprite sprite = btn.tweenTarget.GetComponent <UISprite>(); UI2DSprite s2d = btn.tweenTarget.GetComponent <UI2DSprite>(); if (sprite != null) { if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true)) { NGUIEditorTools.BeginContents(true); EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects); { SerializedObject obj = new SerializedObject(sprite); obj.Update(); SerializedProperty atlas = obj.FindProperty("mAtlas"); NGUIEditorTools.DrawSpriteField("Normal", obj, atlas, obj.FindProperty("mSpriteName")); obj.ApplyModifiedProperties(); NGUIEditorTools.DrawSpriteField("Hover", serializedObject, atlas, serializedObject.FindProperty("hoverSprite"), true); NGUIEditorTools.DrawSpriteField("Pressed", serializedObject, atlas, serializedObject.FindProperty("pressedSprite"), true); NGUIEditorTools.DrawSpriteField("Disabled", serializedObject, atlas, serializedObject.FindProperty("disabledSprite"), true); } EditorGUI.EndDisabledGroup(); NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap"); NGUIEditorTools.EndContents(); } } else if (s2d != null) { if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true)) { NGUIEditorTools.BeginContents(true); EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects); { SerializedObject obj = new SerializedObject(s2d); obj.Update(); NGUIEditorTools.DrawProperty("Normal", obj, "mSprite"); obj.ApplyModifiedProperties(); NGUIEditorTools.DrawProperty("Hover", serializedObject, "hoverSprite2D"); NGUIEditorTools.DrawProperty("Pressed", serializedObject, "pressedSprite2D"); NGUIEditorTools.DrawProperty("Disabled", serializedObject, "disabledSprite2D"); } EditorGUI.EndDisabledGroup(); NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap"); NGUIEditorTools.EndContents(); } } } UIButton button = target as UIButton; NGUIEditorTools.DrawEvents("On Click", button, button.onClick, false); NGUIEditorTools.DrawEvents("On Pressure", button, button.onPressure, false); }
/// <summary> /// Draw widget's dimensions. /// </summary> static void DrawDimensions(SerializedObject so, UIWidget w, bool isPrefab) { GUILayout.BeginHorizontal(); { bool freezeSize = so.isEditingMultipleObjects; UILabel lbl = w as UILabel; if (!freezeSize && lbl) { freezeSize = (lbl.overflowMethod == UILabel.Overflow.ResizeFreely); } if (freezeSize) { EditorGUI.BeginDisabledGroup(true); NGUIEditorTools.DrawProperty("Size", so, "mWidth", GUILayout.MinWidth(100f)); EditorGUI.EndDisabledGroup(); } else { GUI.changed = false; int val = EditorGUILayout.IntField("Size", w.width, GUILayout.MinWidth(100f)); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Dimensions Change", w); w.width = val; } } if (!freezeSize && lbl) { UILabel.Overflow ov = lbl.overflowMethod; freezeSize = (ov == UILabel.Overflow.ResizeFreely || ov == UILabel.Overflow.ResizeHeight); } NGUIEditorTools.SetLabelWidth(12f); if (freezeSize) { EditorGUI.BeginDisabledGroup(true); NGUIEditorTools.DrawProperty("x", so, "mHeight", GUILayout.MinWidth(30f)); EditorGUI.EndDisabledGroup(); } else { GUI.changed = false; int val = EditorGUILayout.IntField("x", w.height, GUILayout.MinWidth(30f)); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Dimensions Change", w); w.height = val; } } NGUIEditorTools.SetLabelWidth(80f); if (isPrefab) { GUILayout.Space(70f); } else { EditorGUI.BeginDisabledGroup(so.isEditingMultipleObjects); if (GUILayout.Button("Snap", GUILayout.Width(60f))) { foreach (GameObject go in Selection.gameObjects) { UIWidget pw = go.GetComponent <UIWidget>(); if (pw != null) { NGUIEditorTools.RegisterUndo("Snap Dimensions", pw); NGUIEditorTools.RegisterUndo("Snap Dimensions", pw.transform); pw.MakePixelPerfect(); } } } EditorGUI.EndDisabledGroup(); } } GUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { UIInput input = target as UIInput; serializedObject.Update(); GUILayout.Space(3f); NGUIEditorTools.SetLabelWidth(110f); //NGUIEditorTools.DrawProperty(serializedObject, "m_Script"); EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects); SerializedProperty label = NGUIEditorTools.DrawProperty(serializedObject, "label"); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(label == null || label.objectReferenceValue == null); { if (Application.isPlaying) { NGUIEditorTools.DrawPaddedProperty("Value", serializedObject, "mValue"); } else { NGUIEditorTools.DrawPaddedProperty("Starting Value", serializedObject, "mValue"); } NGUIEditorTools.DrawPaddedProperty(serializedObject, "savedAs"); NGUIEditorTools.DrawProperty("Active Text Color", serializedObject, "activeTextColor"); EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects); { if (label != null && label.objectReferenceValue != null) { SerializedObject ob = new SerializedObject(label.objectReferenceValue); ob.Update(); NGUIEditorTools.DrawProperty("Inactive Color", ob, "mColor"); ob.ApplyModifiedProperties(); } else { EditorGUILayout.ColorField("Inactive Color", Color.white); } } EditorGUI.EndDisabledGroup(); NGUIEditorTools.DrawProperty("Caret Color", serializedObject, "caretColor"); NGUIEditorTools.DrawProperty("Selection Color", serializedObject, "selectionColor"); NGUIEditorTools.DrawPaddedProperty(serializedObject, "inputType"); NGUIEditorTools.DrawPaddedProperty(serializedObject, "validation"); NGUIEditorTools.DrawPaddedProperty("Mobile Keyboard", serializedObject, "keyboardType"); NGUIEditorTools.DrawPaddedProperty(" Hide Input", serializedObject, "hideInput"); NGUIEditorTools.DrawPaddedProperty(serializedObject, "onReturnKey"); NGUIEditorTools.DrawPaddedProperty(serializedObject, "keepOpenWhenTouchOutside"); // Deprecated, use UIKeyNavigation instead. //NGUIEditorTools.DrawProperty(serializedObject, "selectOnTab"); SerializedProperty sp = serializedObject.FindProperty("characterLimit"); GUILayout.BeginHorizontal(); if (sp.hasMultipleDifferentValues || input.characterLimit > 0) { EditorGUILayout.PropertyField(sp); NGUIEditorTools.DrawPadding(); } else { EditorGUILayout.PropertyField(sp); GUILayout.Label("unlimited"); } GUILayout.EndHorizontal(); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects); NGUIEditorTools.DrawEvents("On Submit", input, input.onSubmit); NGUIEditorTools.DrawEvents("On Change", input, input.onChange); EditorGUI.EndDisabledGroup(); } EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Draw widget's depth. /// </summary> static void DrawDepth(SerializedObject so, UIWidget w, bool isPrefab) { if (isPrefab) { return; } GUILayout.Space(2f); GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Depth"); if (GUILayout.Button("Back", GUILayout.MinWidth(46f))) { foreach (GameObject go in Selection.gameObjects) { UIWidget pw = go.GetComponent <UIWidget>(); if (pw != null) { pw.depth = w.depth - 1; } } } NGUIEditorTools.DrawProperty("", so, "mDepth", GUILayout.MinWidth(20f)); if (GUILayout.Button("Forward", GUILayout.MinWidth(60f))) { foreach (GameObject go in Selection.gameObjects) { UIWidget pw = go.GetComponent <UIWidget>(); if (pw != null) { pw.depth = w.depth + 1; } } } } GUILayout.EndHorizontal(); int matchingDepths = 1; UIPanel p = w.panel; if (p != null) { for (int i = 0, imax = p.widgets.Count; i < imax; ++i) { UIWidget pw = p.widgets[i]; if (pw != w && pw.depth == w.depth) { ++matchingDepths; } } } if (matchingDepths > 1) { EditorGUILayout.HelpBox(matchingDepths + " widgets are sharing the depth value of " + w.depth, MessageType.Info); } }
void DrawFont() { if (NGUIEditorTools.DrawHeader("Font")) { NGUIEditorTools.BeginContents(); SerializedProperty ttf = null; GUILayout.BeginHorizontal(); { if (NGUIEditorTools.DrawPrefixButton("Font")) { if (mType == FontType.Bitmap) { ComponentSelector.Show <UIFont>(OnBitmapFont); } else { ComponentSelector.Show <Font>(OnDynamicFont, new string[] { ".ttf", ".otf" }); } } #if DYNAMIC_FONT GUI.changed = false; mType = (FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f)); if (GUI.changed) { GUI.changed = false; if (mType == FontType.Bitmap) { serializedObject.FindProperty("trueTypeFont").objectReferenceValue = null; } else { serializedObject.FindProperty("bitmapFont").objectReferenceValue = null; } } #else mType = FontType.Bitmap; #endif if (mType == FontType.Bitmap) { NGUIEditorTools.DrawProperty("", serializedObject, "bitmapFont", GUILayout.MinWidth(40f)); } else { ttf = NGUIEditorTools.DrawProperty("", serializedObject, "trueTypeFont", GUILayout.MinWidth(40f)); } } GUILayout.EndHorizontal(); if (ttf != null && ttf.objectReferenceValue != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup(ttf.hasMultipleDifferentValues); NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f)); NGUIEditorTools.DrawProperty("", serializedObject, "fontStyle", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); } else { NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f)); } NGUIEditorTools.DrawProperty("Text Color", serializedObject, "textColor"); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(66f); EditorGUILayout.PrefixLabel("Padding"); NGUIEditorTools.SetLabelWidth(14f); NGUIEditorTools.DrawProperty("X", serializedObject, "padding.x", GUILayout.MinWidth(30f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "padding.y", GUILayout.MinWidth(30f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool DrawProperties() { mLabel = mWidget as UILabel; GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Font")) { if (mType == FontType.Bitmap) { ComponentSelector.Show <UIFont>(OnBitmapFont); } else { ComponentSelector.Show <Font>(OnDynamicFont); } } #if DYNAMIC_FONT mType = (FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f)); #else mType = FontType.Bitmap; #endif bool isValid = false; SerializedProperty fnt = null; SerializedProperty ttf = null; if (mType == FontType.Bitmap) { fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f)); if (fnt.objectReferenceValue != null) { NGUISettings.ambigiousFont = fnt.objectReferenceValue; isValid = true; } } else { ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f)); if (ttf.objectReferenceValue != null) { NGUISettings.ambigiousFont = ttf.objectReferenceValue; isValid = true; } } GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(!isValid); { if (ttf != null && ttf.objectReferenceValue != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup(ttf.hasMultipleDifferentValues); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); NGUISettings.fontSize = prop.intValue; prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f)); NGUISettings.fontStyle = (FontStyle)prop.intValue; GUILayout.Space(18f); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial"); } bool ww = GUI.skin.textField.wordWrap; GUI.skin.textField.wordWrap = true; #if UNITY_3_5 GUI.changed = false; SerializedProperty textField = serializedObject.FindProperty("mText"); string text = EditorGUILayout.TextArea(textField.stringValue, GUI.skin.textArea, GUILayout.Height(100f)); if (GUI.changed) { textField.stringValue = text; } #else #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 GUILayout.Space(-16f); #endif GUILayout.BeginHorizontal(); GUILayout.Space(4f); NGUIEditorTools.DrawProperty("", serializedObject, "mText", GUILayout.Height(80f)); GUILayout.Space(4f); GUILayout.EndHorizontal(); #endif GUI.skin.textField.wordWrap = ww; SerializedProperty ov = NGUIEditorTools.DrawProperty("Overflow", serializedObject, "mOverflow"); NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue; if (ov.intValue == (int)UILabel.Overflow.ShrinkContent && ttf != null && ttf.objectReferenceValue != null) { NGUIEditorTools.DrawProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk"); } GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f)); GUILayout.Space(18f); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Encoding", serializedObject, "mEncoding", GUILayout.Width(100f)); GUILayout.Label("use emoticons and colors"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", GUILayout.Width(100f)); if (gr.hasMultipleDifferentValues || gr.boolValue) { NGUIEditorTools.DrawProperty("", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("", serializedObject, "mGradientTop", GUILayout.MinWidth(40f)); } GUILayout.EndHorizontal(); GUILayout.Space(4f); if (mLabel.supportEncoding && mLabel.bitmapFont != null && mLabel.bitmapFont.hasSymbols) { NGUIEditorTools.DrawProperty("Symbols", serializedObject, "mSymbols"); } GUILayout.BeginHorizontal(); SerializedProperty sp = NGUIEditorTools.DrawProperty("Effect", serializedObject, "mEffectStyle", GUILayout.MinWidth(170f)); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (sp.hasMultipleDifferentValues || sp.boolValue) { NGUIEditorTools.DrawProperty("Effect Color", serializedObject, "mEffectColor", GUILayout.MinWidth(30f)); } if (sp.hasMultipleDifferentValues || sp.boolValue) { GUILayout.BeginHorizontal(); GUILayout.Label("Distance", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f)); GUILayout.Space(18f); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } } EditorGUI.EndDisabledGroup(); return(isValid); }
/// <summary> /// Sprites's custom properties based on the type. /// </summary> protected override void DrawCustomProperties() { GUILayout.Space(6f); NGUIEditorTools.DrawProperty("Additive", serializedObject, "Additive", GUILayout.MinWidth(20f)); SerializedProperty sp = NGUIEditorTools.DrawProperty("Sprite Type", serializedObject, "mType", GUILayout.MinWidth(20f)); EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues); { UISprite.Type type = (UISprite.Type)sp.intValue; if (type == UISprite.Type.Simple) { NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); NGUIEditorTools.DrawProperty("UseCircle", serializedObject, "mUseCircle"); NGUIEditorTools.DrawProperty("CircleRadius", serializedObject, "mCircleRadius"); } else if (type == UISprite.Type.Sliced) { NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); sp = serializedObject.FindProperty("centerType"); bool val = (sp.intValue != (int)UISprite.AdvancedType.Invisible); if (val != EditorGUILayout.Toggle("Fill Center", val)) { sp.intValue = val ? (int)UISprite.AdvancedType.Invisible : (int)UISprite.AdvancedType.Sliced; } } else if (type == UISprite.Type.Filled) { NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); NGUIEditorTools.DrawProperty("Fill Dir", serializedObject, "mFillDirection", GUILayout.MinWidth(20f)); GUILayout.BeginHorizontal(); GUILayout.Space(4f); NGUIEditorTools.DrawProperty("Fill Amount", serializedObject, "mFillAmount", GUILayout.MinWidth(20f)); GUILayout.Space(4f); GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Invert Fill", serializedObject, "mInvert", GUILayout.MinWidth(20f)); } else if (type == UISprite.Type.Advanced) { NGUIEditorTools.DrawProperty(" - Left", serializedObject, "leftType"); NGUIEditorTools.DrawProperty(" - Right", serializedObject, "rightType"); NGUIEditorTools.DrawProperty(" - Top", serializedObject, "topType"); NGUIEditorTools.DrawProperty(" - Bottom", serializedObject, "bottomType"); NGUIEditorTools.DrawProperty(" - Center", serializedObject, "centerType"); NGUIEditorTools.DrawProperty("Flip", serializedObject, "mFlip"); } else if (type == UISprite.Type.Custom) { //NGUIEditorTools.DrawProperty(" - Custom", serializedObject, "customType"); } NGUIEditorTools.DrawProperty("MirrorHorizontal", serializedObject, "mMirrorHorizontal"); NGUIEditorTools.DrawProperty("MirrorVertical", serializedObject, "mMirrorVertical"); } EditorGUI.EndDisabledGroup(); //GUI.changed = false; //Vector4 draw = EditorGUILayout.Vector4Field("Draw Region", mWidget.drawRegion); //if (GUI.changed) //{ // NGUIEditorTools.RegisterUndo("Draw Region", mWidget); // mWidget.drawRegion = draw; //} GUILayout.Space(4f); base.DrawCustomProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); NGUIEditorTools.SetLabelWidth(110f); SerializedProperty sp = NGUIEditorTools.DrawProperty("Scaling Style", serializedObject, "scalingStyle"); UIRoot.Scaling scaling = (UIRoot.Scaling)sp.intValue; if (scaling == UIRoot.Scaling.Flexible) { NGUIEditorTools.DrawProperty("Minimum Height", serializedObject, "minimumHeight"); NGUIEditorTools.DrawProperty("Maximum Height", serializedObject, "maximumHeight"); NGUIEditorTools.DrawProperty("Shrink Portrait UI", serializedObject, "shrinkPortraitUI"); NGUIEditorTools.DrawProperty("Adjust by DPI", serializedObject, "adjustByDPI"); EditorGUILayout.HelpBox("Also known as the 'Pixel-Perfect' mode, this setting makes NGUI's virtual pixels match the screen. This means that your UI will look smaller on high resolution devices and bigger on lower resolution devices, but it will always be as crisp as it can be." + "\n\nIdeal usage: PC games with a modular user interface that takes advantage of widget anchoring.", MessageType.Info); } else { GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Content Width", serializedObject, "manualWidth", GUILayout.Width(160f)); NGUIEditorTools.SetLabelWidth(26f); bool fitWidth = NGUIEditorTools.DrawProperty("Fit", serializedObject, "fitWidth").boolValue; NGUIEditorTools.SetLabelWidth(110f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Content Height", serializedObject, "manualHeight", GUILayout.Width(160f)); NGUIEditorTools.SetLabelWidth(26f); bool fitHeight = NGUIEditorTools.DrawProperty("Fit", serializedObject, "fitHeight").boolValue; NGUIEditorTools.SetLabelWidth(110f); GUILayout.EndHorizontal(); if (fitHeight) { if (fitWidth) { EditorGUILayout.HelpBox("Whatever you create within the content frame (blue outline) will always be visible, regardless of the screen's aspect ratio." + "\n\nThink of it as choosing the 'Fit' desktop background style.", MessageType.Info); } else { EditorGUILayout.HelpBox("This setting will keep your UI look the same on all screen sizes relative to the height of the screen." + "\n\nYou will still be able to see more or less on the left and right sides of the screen as the aspect ratio changes.", MessageType.Info); } } else if (fitWidth) { EditorGUILayout.HelpBox("This setting will keep your UI look the same on all screen sizes relative to the width of the screen." + "\n\nYou will still be able to see more or less on the top and bottom sides sides of the screen as the aspect ratio changes.", MessageType.Info); } else { EditorGUILayout.HelpBox("Your UI within the content frame (blue outline) will always fill the screen, and edges will be cropped based on the aspect ratio." + "\n\nThink of it as choosing the 'Fill' desktop background style.", MessageType.Info); } } serializedObject.ApplyModifiedProperties(); }