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 custom wizard. /// </summary> void OnGUI() { // Load the saved preferences if (!mLoaded) { mLoaded = true; Load(); #if DYNAMIC_FONT Object font = NGUISettings.ambigiousFont; mType = ((font != null) && (font is UIFont)) ? UILabelInspector.FontType.NGUI : UILabelInspector.FontType.Unity; #else mType = UILabelInspector.FontType.NGUI; #endif } NGUIEditorTools.SetLabelWidth(80f); GameObject go = NGUIEditorTools.SelectedRoot(); if (go == null) { GUILayout.Label("You must create a UI first."); if (GUILayout.Button("Open the New UI Wizard")) { EditorWindow.GetWindow <UICreateNewUIWizard>(false, "New UI", true); } } else { GUILayout.Space(4f); GUILayout.BeginHorizontal(); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false, GUILayout.Width(140f)); GUILayout.Label("Texture atlas used by widgets", GUILayout.Width(10000f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Font")) { if (mType == UILabelInspector.FontType.NGUI) { ComponentSelector.Show <UIFont>(OnFont); } else { ComponentSelector.Show <Font>(OnFont, new string[] { ".ttf", ".otf" }); } } #if DYNAMIC_FONT GUI.changed = false; if (mType == UILabelInspector.FontType.Unity) { NGUISettings.ambigiousFont = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont, typeof(Font), false, GUILayout.Width(140f)); } else { NGUISettings.ambigiousFont = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont, typeof(UIFont), false, GUILayout.Width(140f)); } mType = (UILabelInspector.FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f)); #else NGUISettings.ambigiousFont = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont, typeof(UIFont), false, GUILayout.Width(140f)); #endif GUILayout.Label("size", GUILayout.Width(30f)); EditorGUI.BeginDisabledGroup(mType == UILabelInspector.FontType.NGUI); NGUISettings.fontSize = EditorGUILayout.IntField(NGUISettings.fontSize, GUILayout.Width(30f)); EditorGUI.EndDisabledGroup(); GUILayout.Label("font used by the labels"); GUILayout.EndHorizontal(); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); WidgetType wt = (WidgetType)EditorGUILayout.EnumPopup("Template", mWidgetType, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Select a widget template to use"); GUILayout.EndHorizontal(); if (mWidgetType != wt) { mWidgetType = wt; Save(); } switch (mWidgetType) { case WidgetType.Label: CreateLabel(go); break; case WidgetType.Sprite: CreateSprite(go); break; case WidgetType.Texture: CreateSimpleTexture(go); break; case WidgetType.Button: CreateButton(go); break; case WidgetType.ImageButton: CreateImageButton(go); break; case WidgetType.Toggle: CreateToggle(go); break; case WidgetType.ProgressBar: CreateSlider(go, false); break; case WidgetType.Slider: CreateSlider(go, true); break; case WidgetType.Input: CreateInput(go); break; case WidgetType.PopupList: CreatePopup(go, true); break; case WidgetType.PopupMenu: CreatePopup(go, false); break; case WidgetType.ScrollBar: CreateScrollBar(go); break; } EditorGUILayout.HelpBox("Widget Tool has become far less useful with NGUI 3.0.6. Search the Project view for 'Control', then simply drag & drop one of them into your Scene View.", MessageType.Warning); } }
/// <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; NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment"); NGUIEditorTools.DrawPaddedProperty("Anim Type", serializedObject, "mAnimName"); NGUIEditorTools.DrawPaddedProperty("Loop Type", serializedObject, "mPlayBackType"); 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); }
protected override bool ShouldDrawProperties() { if (target == null) { return(false); } if (Application.isPlaying == false && NGUIEditorTools.DrawHeader("Tex to Spr")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } UIAtlas curAtlas = NGUISettings.atlas; if (curAtlas != null) { GUILayout.Label(curAtlas.name, "HelpBox", GUILayout.Height(18f)); } else { GUILayout.Label("No Atlas", "HelpBox", GUILayout.Height(18f)); } GUILayout.FlexibleSpace(); if (GUILayout.Button("ToS", GUILayout.Width(40f))) { if (curAtlas == null) { CreateOwnAtlas(); curAtlas = NGUISettings.atlas; } List <UIAtlasMaker.SpriteEntry> entries = UIAtlasMaker.CreateSprites(new List <Texture>() { mTex.mainTexture }); UIAtlasMaker.ExtractSprites(curAtlas, entries); UIAtlasMaker.UpdateAtlas(curAtlas, entries); UISprite sprite = mTex.gameObject.AddComponent <UISprite>(); sprite.atlas = curAtlas; sprite.spriteName = mTex.mainTexture.name; sprite.type = mTex.type; UISpriteData data = sprite.GetAtlasSprite(); data.SetBorder((int)mTex.border.w, (int)mTex.border.y, (int)mTex.border.x, (int)mTex.border.z); sprite.depth = mTex.depth; sprite.width = mTex.width; sprite.height = mTex.height; UITexture.DestroyImmediate(mTex); EditorGUIUtility.ExitGUI(); return(false); } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } SerializedProperty sp = NGUIEditorTools.DrawProperty("Texture", serializedObject, "mTexture"); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat"); if (sp != null) { NGUISettings.texture = sp.objectReferenceValue as Texture; } if (mTex != null && (mTex.material == null || serializedObject.isEditingMultipleObjects)) { NGUIEditorTools.DrawProperty("Shader", serializedObject, "mShader"); } EditorGUI.BeginDisabledGroup(mTex == null || mTex.mainTexture == null || serializedObject.isEditingMultipleObjects); NGUIEditorTools.DrawRectProperty("UV Rect", serializedObject, "mRect"); sp = serializedObject.FindProperty("mFixedAspect"); bool before = sp.boolValue; NGUIEditorTools.DrawProperty("Fixed Aspect", sp); if (sp.boolValue != before) { (target as UIWidget).drawRegion = new Vector4(0f, 0f, 1f, 1f); } if (sp.boolValue) { EditorGUILayout.HelpBox("Note that Fixed Aspect mode is not compatible with Draw Region modifications done by sliders and progress bars.", MessageType.Info); } EditorGUI.EndDisabledGroup(); return(true); }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties() { mLabel = mWidget as UILabel; GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Font")) { if (mFontType == FontType.NGUI) { ComponentSelector.Show <UIFont>(OnNGUIFont); } else { ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } } #if DYNAMIC_FONT mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, GUILayout.Width(62f)); #else mFontType = FontType.NGUI; #endif 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; #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; NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment"); SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow"); NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue; if (dynFont != null) { NGUIEditorTools.DrawPaddedProperty("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.DrawPaddedProperty("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> /// Draw the atlas and sprite selection fields. /// </summary> protected override bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; if (atl != null) { NGUIEditorTools.Select(atl.gameObject); } } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false); UIPolygonSprite sprite = target as UIPolygonSprite; GUILayout.BeginHorizontal(); SerializedProperty fill = serializedObject.FindProperty("mFillCenter"); fill.boolValue = EditorGUILayout.Toggle("Fill", fill.boolValue, GUILayout.Width(95f)); if (!fill.boolValue) { SerializedProperty thickness = serializedObject.FindProperty("mThickness"); thickness.intValue = EditorGUILayout.IntSlider("Thickness", thickness.intValue, 1, sprite.width / 2); } GUILayout.EndHorizontal(); SerializedProperty test = serializedObject.FindProperty("mTest"); test.boolValue = EditorGUILayout.Toggle("SliceTest", test.boolValue, GUILayout.Width(95f)); SerializedProperty spSide = serializedObject.FindProperty("mSideSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, spSide.stringValue, SelectSideSprite, false); SerializedProperty sides = serializedObject.FindProperty("mPolygonSides"); sides.intValue = EditorGUILayout.IntSlider("Sides", sides.intValue, 3, 360); SerializedProperty verticesDistance = serializedObject.FindProperty("mVerticesDistances"); SerializedProperty spriteSides = serializedObject.FindProperty("mSpriteSides"); if (verticesDistance.arraySize != sides.intValue + 1) { verticesDistance.ClearArray(); verticesDistance.arraySize = sides.intValue + 1; for (int i = 0; i < sides.intValue; i++) { verticesDistance.GetArrayElementAtIndex(i).floatValue = 1f; } if (test.boolValue) { for (int i = 0; i < spriteSides.arraySize; ++i) { UISprite spriteSide = spriteSides.GetArrayElementAtIndex(i).objectReferenceValue as UISprite; if (spriteSide != null) { NGUITools.Destroy(spriteSide.gameObject); spriteSide = null; } } spriteSides.ClearArray(); spriteSides.arraySize = sides.intValue; for (int i = 0; i < sides.intValue; ++i) { if (spSide.stringValue.Length > 0) { UISprite spriteSide = NGUITools.AddSprite(sprite.gameObject, sprite.atlas, spSide.stringValue, sprite.depth + 1); spriteSide.MakePixelPerfect(); spriteSides.GetArrayElementAtIndex(i).objectReferenceValue = spriteSide; } } } } if (NGUIEditorTools.DrawMinimalisticHeader("Distance")) { NGUIEditorTools.BeginContents(true); for (int i = 0; i < sides.intValue; i++) { verticesDistance.GetArrayElementAtIndex(i).floatValue = EditorGUILayout.Slider("Distances " + i, verticesDistance.GetArrayElementAtIndex(i).floatValue, 0, 1); if (test.boolValue) { if (sprite.width * verticesDistance.GetArrayElementAtIndex(i).floatValue < sprite.minWidth) { verticesDistance.GetArrayElementAtIndex(i).floatValue = sprite.minWidth / (float)sprite.width; } } } NGUIEditorTools.EndContents(); } // last vertex is also the first! verticesDistance.GetArrayElementAtIndex(sides.intValue).floatValue = verticesDistance.GetArrayElementAtIndex(0).floatValue; return(true); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { // Load the saved preferences if (!mLoaded) { mLoaded = true; Load(); #if DYNAMIC_FONT mType = (NGUISettings.bitmapFont != null) ? UILabelInspector.FontType.Bitmap : UILabelInspector.FontType.Dynamic; #else mType = UILabelInspector.FontType.Bitmap; #endif } NGUIEditorTools.SetLabelWidth(80f); GameObject go = NGUIEditorTools.SelectedRoot(); if (go == null) { GUILayout.Label("You must create a UI first."); if (GUILayout.Button("Open the New UI Wizard")) { EditorWindow.GetWindow <UICreateNewUIWizard>(false, "New UI", true); } } else { GUILayout.Space(4f); GUILayout.BeginHorizontal(); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false, GUILayout.Width(140f)); GUILayout.Label("Texture atlas used by widgets", GUILayout.Width(10000f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Font")) { if (mType == UILabelInspector.FontType.Bitmap) { ComponentSelector.Show <UIFont>(OnBitmapFont); } else { ComponentSelector.Show <Font>(OnDynamicFont); } } #if DYNAMIC_FONT GUI.changed = false; if (mType == UILabelInspector.FontType.Dynamic) { NGUISettings.trueTypeFont = (Font)EditorGUILayout.ObjectField(NGUISettings.trueTypeFont, typeof(Font), false, GUILayout.Width(140f)); if (GUI.changed) { NGUISettings.bitmapFont = null; } } else { NGUISettings.bitmapFont = (UIFont)EditorGUILayout.ObjectField(NGUISettings.bitmapFont, typeof(UIFont), false, GUILayout.Width(140f)); if (GUI.changed) { NGUISettings.trueTypeFont = null; } } mType = (UILabelInspector.FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f)); #else NGUISettings.bitmapFont = (UIFont)EditorGUILayout.ObjectField(NGUISettings.bitmapFont, typeof(UIFont), false, GUILayout.Width(140f)); mType = UILabelInspector.FontType.Bitmap; #endif GUILayout.Label("size", GUILayout.Width(30f)); EditorGUI.BeginDisabledGroup(mType == UILabelInspector.FontType.Bitmap); NGUISettings.fontSize = EditorGUILayout.IntField(NGUISettings.fontSize, GUILayout.Width(30f)); EditorGUI.EndDisabledGroup(); GUILayout.Label("font used by the labels"); GUILayout.EndHorizontal(); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); WidgetType wt = (WidgetType)EditorGUILayout.EnumPopup("Template", mWidgetType, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Select a widget template to use"); GUILayout.EndHorizontal(); if (mWidgetType != wt) { mWidgetType = wt; Save(); } switch (mWidgetType) { case WidgetType.Label: CreateLabel(go); break; case WidgetType.Sprite: CreateSprite(go, mSprite); break; case WidgetType.Texture: CreateSimpleTexture(go); break; case WidgetType.Button: CreateButton(go); break; case WidgetType.ImageButton: CreateImageButton(go); break; case WidgetType.Toggle: CreateToggle(go); break; case WidgetType.ProgressBar: CreateSlider(go, false); break; case WidgetType.Slider: CreateSlider(go, true); break; case WidgetType.Input: CreateInput(go); break; case WidgetType.PopupList: CreatePopup(go, true); break; case WidgetType.PopupMenu: CreatePopup(go, false); break; case WidgetType.ScrollBar: CreateScrollBar(go); break; } } }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties() { mLabel = mWidget as UIRichText; GUILayout.BeginHorizontal(); mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f)); if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f))) { 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)); 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; NGUIEditorTools.DrawProperty("Resize hight", serializedObject, "mResizeHight"); 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(); 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(); } } EditorGUI.EndDisabledGroup(); return(isValid); }
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) { isValid = true; } } else { ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f)); if (ttf.objectReferenceValue != null) { isValid = true; } } GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(!isValid); { if (ttf != null && ttf.objectReferenceValue != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup(ttf.hasMultipleDifferentValues); NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f)); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); } 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"); if (ov.intValue == (int)UILabel.Overflow.ShrinkContent && ttf != null && ttf.objectReferenceValue != null) { NGUIEditorTools.DrawProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk"); } GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Encoding", serializedObject, "mEncoding", GUILayout.Width(100f)); GUILayout.Label("use emoticons and colors"); GUILayout.EndHorizontal(); if (mLabel.supportEncoding && mLabel.bitmapFont != null && mLabel.bitmapFont.hasSymbols) { NGUIEditorTools.DrawProperty("Symbols", serializedObject, "mSymbols"); } GUILayout.BeginHorizontal(); SerializedProperty sp = NGUIEditorTools.DrawProperty("Effect", serializedObject, "mEffectStyle", GUILayout.Width(170f)); if (sp.hasMultipleDifferentValues || sp.boolValue) { NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(40f)); } GUILayout.EndHorizontal(); 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(); } NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); } EditorGUI.EndDisabledGroup(); return(isValid); }
/// <summary> /// Draw all the custom properties such as sprite type, flip setting, fill direction, etc. /// </summary> protected override void DrawCustomProperties() { Particle2D obj = target as Particle2D; //-------------------------------------------- // Atlas GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "atlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; NGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); //-------------------------------------------- // Sprites if (isSpriteListFoldout = EditorGUILayout.Foldout(isSpriteListFoldout, "Sprites", EditorStyles.foldout)) { if (atlas != null) { int idx = 0; { var __list1 = obj.sprites; var __listCount1 = __list1.Count; for (int __i1 = 0; __i1 < __listCount1; ++__i1) { var str = (string)__list1[__i1]; { GUILayout.BeginHorizontal(); DrawSpriteField(atlas.objectReferenceValue as UIAtlas, obj.sprites[idx], idx, SelectSprite); if (obj.sprites.Count > 1) { if (GUILayout.Button("X", GUILayout.Width(32))) { NGUIEditorTools.RegisterUndo("Sprite Delete", target); obj.sprites.Remove(str); break; } } GUILayout.EndHorizontal(); idx++; } } } if (GUILayout.Button("Add Sprite", GUILayout.Height(16))) { if (obj.atlas.spriteList.Count >= 1) { NGUIEditorTools.RegisterUndo("Sprite Add", target); obj.sprites.Add(obj.atlas.spriteList[0].name); } } } //-------------------------------------------- // Depth EditorGUIUtility.LookLikeControls(80f, 0); GUILayout.Space(3f); DrawDepth(serializedObject, mWidget, false); //-------------------------------------------- // Color GUILayout.Space(3f); NGUIEditorTools.DrawProperty("Color Tint", serializedObject, "mColor", GUILayout.MinWidth(20f)); } //-------------------------------------------- // Emitter type if (isEmitterFoldout = EditorGUILayout.Foldout(isEmitterFoldout, "Emitter Settings", EditorStyles.foldout)) { // Looping bool replacementWorldSpace = EditorGUILayout.Toggle("World Space", obj.worldSpace); if (obj.worldSpace != replacementWorldSpace) { NGUIEditorTools.RegisterUndo("World Position Change", target); obj.worldSpace = replacementWorldSpace; } Particle2D.Emitter replacementEmitter = (Particle2D.Emitter)EditorGUILayout.EnumPopup("Emitter Type", obj.emitter); if (obj.emitter != replacementEmitter) { NGUIEditorTools.RegisterUndo("Max particles Change", target); obj.emitter = replacementEmitter; } if (obj.emitter == Particle2D.Emitter.CIRCLE) { float replacementRadius = EditorGUILayout.FloatField("Radius", obj.emitterRadius); if (replacementRadius < 0) { replacementRadius = 0; } if (obj.emitterRadius != replacementRadius) { NGUIEditorTools.RegisterUndo("Radius Change", target); obj.emitterRadius = replacementRadius; } } else if (obj.emitter == Particle2D.Emitter.RECT) { EditorGUIUtility.LookLikeControls(40f, 0); GUILayout.BeginHorizontal(); float replacementWidth = EditorGUILayout.FloatField("Width", obj.emitterWidth); float replacementHeight = EditorGUILayout.FloatField("Height", obj.emitterHeight); if (obj.emitterWidth != replacementWidth || obj.emitterHeight != replacementHeight) { NGUIEditorTools.RegisterUndo("Emitter Size Change", target); obj.emitterWidth = replacementWidth; obj.emitterHeight = replacementHeight; } GUILayout.EndHorizontal(); EditorGUIUtility.LookLikeControls(80f, 0); } EditorGUILayout.Space(); //-------------------------------------------- // Spwn rate float replacementSpwnRate = EditorGUILayout.FloatField("Spwn Rate", obj.spwnRate); if (replacementSpwnRate <= 0.001f) { replacementSpwnRate = 0.001f; } if (obj.spwnRate != replacementSpwnRate) { NGUIEditorTools.RegisterUndo("Spwn Rate Change", target); obj.spwnRate = replacementSpwnRate; } //-------------------------------------------- // Looping bool replacementLooping = EditorGUILayout.Toggle("Looping", obj.looping); if (obj.looping != replacementLooping) { NGUIEditorTools.RegisterUndo("Looping Change", target); obj.looping = replacementLooping; } if (!obj.looping) { //-------------------------------------------- // Max particles int replacementMaxParticles = EditorGUILayout.IntField("Max particles", obj.maxParticles); if (replacementMaxParticles <= 0) { replacementMaxParticles = 1; } if (obj.maxParticles != replacementMaxParticles) { NGUIEditorTools.RegisterUndo("Max particles Change", target); obj.maxParticles = replacementMaxParticles; } //-------------------------------------------- // Duration float replacementDuration = EditorGUILayout.FloatField("Duration", obj.duration); if (replacementDuration < 0) { replacementDuration = 0; } if (obj.duration != replacementDuration) { NGUIEditorTools.RegisterUndo("Duration Change", target); obj.duration = replacementDuration; } bool replacementPlayOnce = EditorGUILayout.Toggle("Play Once", obj.playOnce); if (obj.playOnce != replacementPlayOnce) { NGUIEditorTools.RegisterUndo("Play Once Change", target); obj.playOnce = replacementPlayOnce; } } //-------------------------------------------- // Life time EditorGUIUtility.LookLikeControls(80f, 0); GUILayout.BeginHorizontal(); float replacementMinLifeTime = EditorGUILayout.FloatField("Min Life", obj.minLifeTime); float replacementMaxLifeTime = EditorGUILayout.FloatField("Max Life", obj.maxLifeTime); if (replacementMinLifeTime <= 0) { replacementMinLifeTime = 1; } if (replacementMaxLifeTime <= 0) { replacementMaxLifeTime = 1; } if (obj.minLifeTime != replacementMinLifeTime || obj.maxLifeTime != replacementMaxLifeTime) { NGUIEditorTools.RegisterUndo("Life Time Change", target); obj.minLifeTime = replacementMinLifeTime; obj.maxLifeTime = replacementMaxLifeTime; } GUILayout.EndHorizontal(); } //-------------------------------------------- // Size if (isSizeFoldout = EditorGUILayout.Foldout(isSizeFoldout, "Size Settings", EditorStyles.foldout)) { EditorGUIUtility.LookLikeControls(80f, 0); GUILayout.BeginHorizontal(); float replacementMinSize = EditorGUILayout.FloatField("Min Size", obj.minSize); float replacementMaxSize = EditorGUILayout.FloatField("Max Size", obj.maxSize); if (replacementMinSize <= 0) { replacementMinSize = 1; } if (replacementMaxSize <= 0) { replacementMaxSize = 1; } if (obj.minSize != replacementMinSize || obj.maxSize != replacementMaxSize) { NGUIEditorTools.RegisterUndo("Size Change", target); obj.minSize = replacementMinSize; obj.maxSize = replacementMaxSize; } GUILayout.EndHorizontal(); bool replacementSizeRate = EditorGUILayout.BeginToggleGroup("Size Rate", obj.useSizeRate); if (obj.useSizeRate != replacementSizeRate) { NGUIEditorTools.RegisterUndo("Use Size Rate Change", target); obj.useSizeRate = replacementSizeRate; } if (obj.useSizeRate) { GUILayout.BeginHorizontal(); obj.sizeRate = EditorGUILayout.CurveField("Size", obj.sizeRate); if (GUILayout.Button("Copy", GUILayout.Width(40))) { copiedAnimationCurve = new AnimationCurve(obj.sizeRate.keys); } if (GUILayout.Button("Paste", GUILayout.Width(40))) { NGUIEditorTools.RegisterUndo("Paste", target); obj.sizeRate = new AnimationCurve(copiedAnimationCurve.keys); } GUILayout.EndHorizontal(); } EditorGUILayout.EndToggleGroup(); EditorGUIUtility.LookLikeControls(); } //-------------------------------------------- // Velocity EditorGUIUtility.LookLikeControls(); bool replacementVelocity = EditorGUILayout.Foldout(obj.useVelocity, "Use Velocity?", EditorStyles.toggleGroup); if (obj.useVelocity != replacementVelocity) { NGUIEditorTools.RegisterUndo("Use Velocity Change", target); obj.useVelocity = replacementVelocity; } if (obj.useVelocity) { GUILayout.BeginHorizontal(); EditorGUIUtility.LookLikeControls(80f, 0); float replacementMinAngle = EditorGUILayout.FloatField("Min Angle", obj.minAngle); float replacementMaxAngle = EditorGUILayout.FloatField("Max Angle", obj.maxAngle); if (replacementMinAngle != obj.minAngle || replacementMaxAngle != obj.maxAngle) { NGUIEditorTools.RegisterUndo("Angle Change", target); obj.minAngle = replacementMinAngle; obj.maxAngle = replacementMaxAngle; } GUILayout.EndHorizontal(); EditorGUILayout.MinMaxSlider(ref obj.minAngle, ref obj.maxAngle, -360f, 360f); GUILayout.BeginHorizontal(); float replacementMinPower = EditorGUILayout.FloatField("Min Power", obj.minPower); float replacementMaxPower = EditorGUILayout.FloatField("Max Power", obj.maxPower); if (replacementMinPower < 0f) { replacementMinPower = 0f; } if (replacementMaxPower < 0f) { replacementMaxPower = 0f; } if (replacementMinPower > 99999999f) { replacementMinPower = 99999999f; } if (replacementMaxPower > 99999999f) { replacementMaxPower = 99999999f; } if (replacementMinPower != obj.minPower || replacementMaxPower != obj.maxPower) { NGUIEditorTools.RegisterUndo("Angle Change", target); obj.minPower = replacementMinPower; obj.maxPower = replacementMaxPower; } GUILayout.EndHorizontal(); //-------------------------------------------- // Acceleration bool replacementAcceleration = EditorGUILayout.BeginToggleGroup("Acceleration", obj.useAcceleration); if (obj.useAcceleration != replacementAcceleration) { NGUIEditorTools.RegisterUndo("Use Acceleration Change", target); obj.useAcceleration = replacementAcceleration; } if (obj.useAcceleration) { GUILayout.BeginHorizontal(); obj.accelerationRate = EditorGUILayout.CurveField("Accel", obj.accelerationRate); if (GUILayout.Button("Copy", GUILayout.Width(40))) { copiedAnimationCurve = new AnimationCurve(obj.accelerationRate.keys); } if (GUILayout.Button("Paste", GUILayout.Width(40))) { NGUIEditorTools.RegisterUndo("Paste", target); obj.accelerationRate = new AnimationCurve(copiedAnimationCurve.keys); } GUILayout.EndHorizontal(); } EditorGUILayout.EndToggleGroup(); //-------------------------------------------- // Force bool replacementForce = EditorGUILayout.BeginToggleGroup("Force", obj.useForce); if (obj.useForce != replacementForce) { NGUIEditorTools.RegisterUndo("Use Force Change", target); obj.useForce = replacementForce; } if (obj.useForce) { Vector2 replacementForceForce = EditorGUILayout.Vector2Field("Force", obj.force); if (obj.force != replacementForceForce) { NGUIEditorTools.RegisterUndo("Force Change", target); obj.force = replacementForceForce; } } EditorGUILayout.EndToggleGroup(); EditorGUIUtility.LookLikeControls(); } //-------------------------------------------- // Rotation EditorGUIUtility.LookLikeControls(); bool replacementRotation = EditorGUILayout.Foldout(obj.useRotation, "Use Rotation?", EditorStyles.toggleGroup); if (obj.useRotation != replacementRotation) { NGUIEditorTools.RegisterUndo("Use Rotation Change", target); obj.useRotation = replacementRotation; } if (obj.useRotation) { EditorGUIUtility.LookLikeControls(80f, 0); Vector3 replacementMinRotation = EditorGUILayout.Vector3Field("Min Rotation", obj.minRotation); Vector3 replacementMaxRotation = EditorGUILayout.Vector3Field("Max Rotation", obj.maxRotation); if (obj.minRotation != replacementMinRotation || obj.maxRotation != replacementMaxRotation) { NGUIEditorTools.RegisterUndo("Rotation Change", target); obj.minRotation = replacementMinRotation; obj.maxRotation = replacementMaxRotation; } // Rotation Rate bool replacementRotationRate = EditorGUILayout.BeginToggleGroup("Rotation Rate", obj.useRotationRate); if (obj.useRotationRate != replacementRotationRate) { NGUIEditorTools.RegisterUndo("Use Rotation Rate Change", target); obj.useRotationRate = replacementRotationRate; } GUILayout.BeginHorizontal(); obj.rotationRateX = EditorGUILayout.CurveField("X", obj.rotationRateX); if (GUILayout.Button("Copy", GUILayout.Width(40))) { copiedAnimationCurve = new AnimationCurve(obj.rotationRateX.keys); } if (GUILayout.Button("Paste", GUILayout.Width(40))) { NGUIEditorTools.RegisterUndo("Paste", target); obj.rotationRateX = new AnimationCurve(copiedAnimationCurve.keys); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); obj.rotationRateY = EditorGUILayout.CurveField("Y", obj.rotationRateY); if (GUILayout.Button("Copy", GUILayout.Width(40))) { copiedAnimationCurve = new AnimationCurve(obj.rotationRateY.keys); } if (GUILayout.Button("Paste", GUILayout.Width(40))) { NGUIEditorTools.RegisterUndo("Paste", target); obj.rotationRateY = new AnimationCurve(copiedAnimationCurve.keys); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); obj.rotationRateZ = EditorGUILayout.CurveField("Z", obj.rotationRateZ); if (GUILayout.Button("Copy", GUILayout.Width(40))) { copiedAnimationCurve = new AnimationCurve(obj.rotationRateZ.keys); } if (GUILayout.Button("Paste", GUILayout.Width(40))) { NGUIEditorTools.RegisterUndo("Paste", target); obj.rotationRateZ = new AnimationCurve(copiedAnimationCurve.keys); } GUILayout.EndHorizontal(); EditorGUILayout.EndToggleGroup(); EditorGUIUtility.LookLikeControls(); } //-------------------------------------------- // Animate color EditorGUIUtility.LookLikeControls(); bool replacementAnimatedColor = EditorGUILayout.Foldout(obj.useAnimatedColor, "Use Animated Color?", EditorStyles.toggleGroup); if (obj.useAnimatedColor != replacementAnimatedColor) { NGUIEditorTools.RegisterUndo("Use Animated Color Change", target); obj.useAnimatedColor = replacementAnimatedColor; } if (obj.useAnimatedColor) { if (obj.colors.Count < 2) { obj.colors.Add(Color.white); obj.colors.Add(new Color(1, 1, 1, 0)); } int idx = 0; { var __list2 = obj.colors; var __listCount2 = __list2.Count; for (int __i2 = 0; __i2 < __listCount2; ++__i2) { var col = (Color)__list2[__i2]; { GUILayout.BeginHorizontal(); obj.colors[idx] = EditorGUILayout.ColorField(col); if (obj.colors.Count > 2) { if (GUILayout.Button("X", GUILayout.Width(32))) { NGUIEditorTools.RegisterUndo("Color Delete", target); obj.colors.RemoveAt(idx); break; } } GUILayout.EndHorizontal(); idx++; } } } if (GUILayout.Button("Add Color", GUILayout.Height(16))) { NGUIEditorTools.RegisterUndo("Color Add", target); obj.colors.Add(Color.white); } } }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties() { mRichTextLabel = mWidget as UIRichTextLabel; 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); } NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat"); 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(); } else if (uiFont != null) { GUILayout.BeginHorizontal(); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); EditorGUI.BeginDisabledGroup(true); if (!serializedObject.isEditingMultipleObjects) { if (mRichTextLabel.overflowMethod == UIRichTextLabel.Overflow.ShrinkContent) { GUILayout.Label(" Actual: " + mRichTextLabel.finalFontSize + "/" + mRichTextLabel.defaultFontSize); } else { GUILayout.Label(" Default: " + mRichTextLabel.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; NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier"); 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(mRichTextLabel.bitmapFont != null && mRichTextLabel.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 || mRichTextLabel.bitmapFont == null || !mRichTextLabel.bitmapFont.hasSymbols); NGUIEditorTools.SetLabelWidth(60f); NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols"); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); if (NGUIEditorTools.DrawHeader("RichTextPrefabs")) { NGUIEditorTools.BeginContents(); List <RichTextPrefabItem> prefabs = mRichTextLabel.Prefabs; for (int i = prefabs.Count - 1; i >= 0; i--) { RichTextPrefabItem prefab = prefabs[i]; if (prefab.prefabObject == null) { prefabs.RemoveAt(i); } } for (int i = 0; i < prefabs.Count; i++) { RichTextPrefabItem prefab = prefabs[i]; if (prefab.prefabObject == null) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(prefab.sequence, GUILayout.Width(100f)); GUILayout.Label(prefab.prefabObject.name, GUILayout.Width(100f)); GUILayout.Label("width:" + prefab.width); GUILayout.Label("height:" + prefab.height); GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove prefab", mRichTextLabel); mPrefabSequence = prefab.sequence; //mPrefabGameObject = prefab.prefab; prefabs.Remove(prefab); mRichTextLabel.MarkAsChanged(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); } if (prefabs.Count > 0) { GUILayout.Space(6f); } GUILayout.BeginHorizontal(); mPrefabSequence = EditorGUILayout.TextField(mPrefabSequence, GUILayout.Width(100f)); mPrefabGameObject = (GameObject)EditorGUILayout.ObjectField(mPrefabGameObject, typeof(GameObject), GUILayout.Width(100f)); mPrefabWidth = EditorGUILayout.FloatField(mPrefabWidth); mPrefabHeight = EditorGUILayout.FloatField(mPrefabHeight); isValid = (!string.IsNullOrEmpty(mPrefabSequence)) && (mPrefabGameObject != null); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add prefab", mRichTextLabel); RichTextPrefabItem tprefab = new RichTextPrefabItem(); tprefab.sequence = mPrefabSequence; tprefab.prefabObject = mPrefabGameObject; tprefab.width = mPrefabWidth; tprefab.height = mPrefabHeight; mRichTextLabel.Prefabs.Add(tprefab); mRichTextLabel.MarkAsChanged(); mPrefabSequence = ""; mPrefabGameObject = null; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (prefabs.Count == 0) { EditorGUILayout.HelpBox("In the field above type ':)', choose a Prefab, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("RichTextEmotion")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mEmotionAtlas", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mRichTextLabel.EmotionAtlas != null) { List <RichTextEmotionItem> emotions = mRichTextLabel.Emotions; for (int i = 0; i < emotions.Count; i++) { RichTextEmotionItem emotion = emotions[i]; GUILayout.BeginHorizontal(); GUILayout.Label(emotion.sequence, GUILayout.Width(40f)); GUILayout.Label(emotion.spriteName); GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove emotion", mRichTextLabel); mEmotionSequence = emotion.sequence; emotions.Remove(emotion); mRichTextLabel.MarkAsChanged(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); } if (emotions.Count > 0) { GUILayout.Space(6f); } GUILayout.BeginHorizontal(); mEmotionSequence = EditorGUILayout.TextField(mEmotionSequence, GUILayout.Width(40f)); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, mSpriteName, SelectSprite, false); isValid = (!string.IsNullOrEmpty(mEmotionSequence)) && (!string.IsNullOrEmpty(mSpriteName)); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add Sprite", mRichTextLabel); RichTextEmotionItem temotion = new RichTextEmotionItem(); temotion.sequence = mEmotionSequence; temotion.spriteName = mSpriteName; mRichTextLabel.Emotions.Add(temotion); mRichTextLabel.MarkAsChanged(); mEmotionSequence = ""; mSpriteName = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (emotions.Count == 0) { EditorGUILayout.HelpBox("In the field above type ':)', choose a Sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } } NGUIEditorTools.EndContents(); } isValid = true; return(isValid); }
private void DrawReplaceAtalasTool() { GUI.backgroundColor = Color.white; GUI.Box(replaceAtalsRect, ""); GUILayout.BeginArea(replaceAtalsRect); EditorGUILayout.LabelField(curReplacePrefabPath); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("该预制体含有的所有图集:", GUILayout.Width(150)); if (curPrefabAtlas.Count > 0) { for (int i = 0; i < curPrefabAtlas.Count; i++) { if (GUILayout.Button(curPrefabAtlas[i].name)) { curAtlas = curPrefabAtlas[i]; } if (GUILayout.Button("Edit")) { //NGUISettings.atlas = mFont.atlas; //NGUISettings.selectedSprite = sym.spriteName; NGUIEditorTools.Select(curPrefabAtlas[i].gameObject); } } } GUILayout.EndHorizontal(); //原图集 GUILayout.BeginHorizontal(); curAtlas = (UIAtlas)EditorGUILayout.ObjectField("被替换图集", curAtlas, typeof(UIAtlas), true); if (NGUIEditorTools.DrawPrefixButton("选择Atlas", GUILayout.Width(200))) { isSelectCurAtlas = true; ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } GUILayout.EndHorizontal(); //目标图集 GUILayout.BeginHorizontal(); targetAtlas = (UIAtlas)EditorGUILayout.ObjectField("目标图集", targetAtlas, typeof(UIAtlas), true); if (NGUIEditorTools.DrawPrefixButton("选择Atlas", GUILayout.Width(200))) { isSelectTargetAtlas = true; ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } GUILayout.EndHorizontal(); if (GUILayout.Button("互换")) { UIAtlas tmpCurAtlas = curAtlas; curAtlas = targetAtlas; targetAtlas = tmpCurAtlas; OnTargetAtlasChanged(targetAtlas); } //替换按钮 if (GUILayout.Button("替换图集")) { if (string.IsNullOrEmpty(curReplacePrefabPath)) { EditorUtility.DisplayDialog("提示", "请先选择一个预制体!", "确定"); } else if (curAtlas == null) { EditorUtility.DisplayDialog("提示", "请先指定被替换图集!", "确定"); } else { bool ReplaceSucc = false; if (targetAtlas == null) { if (EditorUtility.DisplayDialog("提示", "原图集将被清空,确定替换吗?", "确定", "取消")) { ReplacePrefabAtalas(curReplacePrefabPath); ReplaceSucc = true; } } else { ReplacePrefabAtalas(curReplacePrefabPath); ReplaceSucc = true; } if (ReplaceSucc) { m_TreeView.treeModel.SetData(GetData()); m_TreeView.Reload(); } } } //保存按钮 //撤销按钮 GUILayout.EndArea(); }
public override void OnGUI() { base.OnGUI(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Font")) { if (mType == UILabelInspector.FontType.NGUI) { ComponentSelector.Show <UIFont>(OnBitmapFont); } else { ComponentSelector.Show <Font>(OnDynamicFont); } } #if DYNAMIC_FONT GUI.changed = false; if (mType == UILabelInspector.FontType.Unity) { mTrueTypeFont = (Font)EditorGUILayout.ObjectField(mTrueTypeFont, typeof(Font), false, GUILayout.Width(140f)); if (GUI.changed) { mBitmapFont = null; } } else { mBitmapFont = (UIFont)EditorGUILayout.ObjectField(mBitmapFont, typeof(UIFont), false, GUILayout.Width(140f)); if (GUI.changed) { mTrueTypeFont = null; } } mType = (UILabelInspector.FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f)); #else NGUISettings.bitmapFont = (UIFont)EditorGUILayout.ObjectField(NGUISettings.bitmapFont, typeof(UIFont), false, GUILayout.Width(140f)); mType = UILabelInspector.FontType.NGUI; #endif GUILayout.Label("size", GUILayout.Width(30f)); EditorGUI.BeginDisabledGroup(mType == UILabelInspector.FontType.NGUI); NGUISettings.fontSize = EditorGUILayout.IntField(NGUISettings.fontSize, GUILayout.Width(30f)); EditorGUI.EndDisabledGroup(); GUILayout.Label("font used by the labels"); GUILayout.EndHorizontal(); NGUIEditorTools.DrawSeparator(); GameObject go = NGUIEditorTools.SelectedRoot(); if (ShouldCreate(go, go != null && (mBitmapFont != null || mTrueTypeFont != null))) { UINgraph pUINgraph = CreateGraphGo <UINgraph>(go); pUINgraph.fontSize = NGUISettings.fontSize; if (mType == UILabelInspector.FontType.NGUI) { pUINgraph.AxisLabelBitmapFont = mBitmapFont; } else { pUINgraph.AxisLabelDynamicFont = mTrueTypeFont; } } }
public override void OnInspectorGUI() { FXBillboardParticle billboards = target as FXBillboardParticle; //////////////////////////////////////////////////////////////////////////////// /// Atlas Settings GUILayout.BeginHorizontal(); GUILayout.Label("Atlas Type", GUILayout.Width(76f)); FXAtlasType atlas_type = (FXAtlasType)EditorGUILayout.EnumPopup("", billboards.AtlasType); GUILayout.EndHorizontal(); if (atlas_type != billboards.AtlasType) { billboards.AtlasType = atlas_type; } // if (atlas_type == FXAtlasType.Static) { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas_prop = NGUIEditorTools.DrawProperty("", serializedObject, "m_Atlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas_prop != null) { UIAtlas atlas = atlas_prop.objectReferenceValue as UIAtlas; NGUISettings.atlas = atlas; NGUIEditorTools.Select(atlas.gameObject); } } if (atlas_prop != null) { UIAtlas atlas = atlas_prop.objectReferenceValue as UIAtlas; if (billboards.atlas != atlas) { billboards.atlas = atlas; } } GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Sprite Settings SerializedProperty sprite_name_prop = serializedObject.FindProperty("m_SpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas_prop.objectReferenceValue as UIAtlas, sprite_name_prop.stringValue, SelectSprite, false); } else if (atlas_type == FXAtlasType.Dynamic) { GUILayout.BeginHorizontal(); GUILayout.Label("Atlas", GUILayout.Width(76f)); eDynamicAtlasType dynamic_atlas_type = (eDynamicAtlasType)EditorGUILayout.EnumPopup("", billboards.dynamicAtlasType); GUILayout.EndHorizontal(); if (dynamic_atlas_type != billboards.dynamicAtlasType) { billboards.dynamicAtlasType = dynamic_atlas_type; } GUILayout.BeginHorizontal(); GUILayout.Label("Sprite", GUILayout.Width(76f)); SerializedProperty sprite_name_prop = NGUIEditorTools.DrawProperty("", serializedObject, "m_SpriteName", GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); billboards.spriteName = sprite_name_prop.stringValue; } //////////////////////////////////////////////////////////////////////////////// /// From Color GUILayout.BeginHorizontal(); GUILayout.Label("From Color", GUILayout.Width(76f)); SerializedProperty from_color_prop = NGUIEditorTools.DrawProperty("", serializedObject, "FromColor", GUILayout.MinWidth(10f)); billboards.FromColor = from_color_prop.colorValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// To Color GUILayout.BeginHorizontal(); GUILayout.Label("To Color", GUILayout.Width(76f)); SerializedProperty to_color_prop = NGUIEditorTools.DrawProperty("", serializedObject, "ToColor", GUILayout.MinWidth(10f)); billboards.ToColor = to_color_prop.colorValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// From Size GUILayout.BeginHorizontal(); GUILayout.Label("From Size", GUILayout.Width(76f)); SerializedProperty from_size_prop = NGUIEditorTools.DrawProperty("", serializedObject, "FromSize", GUILayout.MinWidth(10f)); billboards.FromSize = from_size_prop.floatValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// To Size GUILayout.BeginHorizontal(); GUILayout.Label("To Size", GUILayout.Width(76f)); SerializedProperty to_size_prop = NGUIEditorTools.DrawProperty("", serializedObject, "ToSize", GUILayout.MinWidth(10f)); billboards.ToSize = to_size_prop.floatValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Tile X GUILayout.BeginHorizontal(); GUILayout.Label("Tile X", GUILayout.Width(76f)); SerializedProperty tilte_x_prop = NGUIEditorTools.DrawProperty("", serializedObject, "TileX", GUILayout.MinWidth(10f)); billboards.TileX = tilte_x_prop.intValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Tile Y GUILayout.BeginHorizontal(); GUILayout.Label("Tile Y", GUILayout.Width(76f)); SerializedProperty tilte_y_prop = NGUIEditorTools.DrawProperty("", serializedObject, "TileY", GUILayout.MinWidth(10f)); billboards.TileY = tilte_y_prop.intValue; GUILayout.EndHorizontal(); }
/// <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); }
// ========================================================================== // /* public - [Do] Function * 외부 객체가 호출 */ /* public - [Event] Function * 프랜드 객체가 호출 */ // ========================================================================== // /* protected - [abstract & virtual] */ /* protected - [Event] Function * 자식 객체가 호출 */ /* protected - Override & Unity API */ public override void OnInspectorGUI() { //base.OnInspectorGUI(); _pTarget = target as CUIButtonMultiToggle; _pAtlas = _pTarget.GetComponent <UISprite>().atlas; if (_pTarget.listEvent == null) { _pTarget.listEvent = new List <CUIButtonMultiToggle.SButtonToggle>(); } _iOriginStateCount = _pTarget.listEvent.Count; _iOriginStateCount = EditorGUILayout.IntField("상태 개수", _iOriginStateCount); if (_pTarget.listEvent == null) { _pTarget.listEvent = new List <CUIButtonMultiToggle.SButtonToggle>(); } if (_pAtlas == null) { Debug.LogWarning("UI Sprite의 Atlas가 세팅되지 않았습니다..", _pTarget); return; } if (_iOriginStateCount != _pTarget.listEvent.Count) { if (_iOriginStateCount < _pTarget.listEvent.Count) { int iLoopCount = _pTarget.listEvent.Count - _iOriginStateCount; try { for (int i = 0; i < iLoopCount; i++) { _pTarget.listEvent.Remove(_pTarget.listEvent[i]); } } catch (System.Exception e) { Debug.LogWarning(e); } } else { int iLoopCount = _iOriginStateCount - _pTarget.listEvent.Count; for (int i = 0; i < iLoopCount; i++) { _pTarget.listEvent.Add(new CUIButtonMultiToggle.SButtonToggle()); } } } if (_iOriginStateCount != 0) { _pTarget.iDefaultState = EditorGUILayout.IntField(string.Format("기본 상태 1 ~ {0}", _pTarget.listEvent.Count), _pTarget.iDefaultState); } if (_pTarget.iDefaultState > _pTarget.listEvent.Count || _pTarget.iDefaultState <= 0) { Debug.LogError("상태개수 범위안의 숫자를 선택해 주십시오."); } _pTarget._eButtonToggleOption = (CUIButtonMultiToggle.EButtonToggleOption)EditorGUILayout.EnumPopup("옵션선택", _pTarget._eButtonToggleOption); for (int i = 0; i < _pTarget.listEvent.Count; i++) { CUIButtonMultiToggle.SButtonToggle sToggle = _pTarget.listEvent[i]; //NGUIEditorTools.DrawEvents("On StateChange", _pTarget, sToggle.listEvent, false); if (NGUIEditorTools.DrawHeader(string.Format("OnChangeState_{0}", i + 1)) == false) { continue; } if (_pTarget.listEvent[i].listEvent == null) { _pTarget.listEvent[i].listEvent = new List <EventDelegate>(); } EventDelegateEditor.Field(_pTarget, _pTarget.listEvent[i].listEvent, false); // 여기서 필요한 로직만 가져옴 //NGUIEditorTools.DrawAdvancedSpriteField(_pAtlas, sToggle.strSpriteName, SelectSprite, false); GUILayout.BeginHorizontal(); { if (NGUIEditorTools.DrawPrefixButton("Sprite")) { NGUISettings.atlas = _pAtlas; NGUISettings.selectedSprite = sToggle.strSpriteName; SpriteSelector.Show(SelectSprite); _iCurrentEditItemIndex = i; } GUILayout.BeginHorizontal(); GUILayout.Label(sToggle.strSpriteName, "HelpBox", GUILayout.Height(18f)); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); } }
/// <summary> /// Draw the UI for this tool. /// </summary> void OnGUI() { Object fnt = NGUISettings.ambigiousFont; UIFont uiFont = (fnt as UIFont); NGUIEditorTools.SetLabelWidth(80f); GUILayout.Space(3f); NGUIEditorTools.DrawHeader("Input", true); NGUIEditorTools.BeginContents(false); GUILayout.BeginHorizontal(); mType = (FontType)EditorGUILayout.EnumPopup("Type", mType, GUILayout.MinWidth(200f)); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); Create create = Create.None; if (mType == FontType.ImportedBitmap) { NGUISettings.fontData = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(TextAsset), false) as TextAsset; NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false, GUILayout.Width(140f)) as Texture2D; NGUIEditorTools.EndContents(); // Draw the atlas selection only if we have the font data and texture specified, just to make it easier EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null); { NGUIEditorTools.DrawHeader("Output", true); NGUIEditorTools.BeginContents(false); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false); NGUIEditorTools.EndContents(); } EditorGUI.EndDisabledGroup(); if (NGUISettings.fontData == null) { EditorGUILayout.HelpBox("To create a font from a previously exported FNT file, you need to use BMFont on " + "Windows or your choice of Glyph Designer or the less expensive bmGlyph on the Mac.\n\n" + "Either of these tools will create a FNT file for you that you will drag & drop into the field above.", MessageType.Info); } else if (NGUISettings.fontTexture == null) { EditorGUILayout.HelpBox("When exporting your font, you should get two files: the FNT, and the texture. Only one texture can be used per font.", MessageType.Info); } else if (NGUISettings.atlas == null) { EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " + "labels using this font will generate an extra draw call.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info); } EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null); { GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Create the Font")) { create = Create.Import; } GUILayout.Space(20f); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); } else { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Source")) { ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } Font ttf = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont as Font, typeof(Font), false) as Font; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { NGUISettings.fontSize = EditorGUILayout.IntField("Size", NGUISettings.fontSize, GUILayout.Width(120f)); if (mType == FontType.Dynamic) { NGUISettings.fontStyle = (FontStyle)EditorGUILayout.EnumPopup(NGUISettings.fontStyle); NGUIEditorTools.DrawPadding(); } } GUILayout.EndHorizontal(); // Choose the font style if there are multiple faces present if (mType == FontType.GeneratedBitmap) { if (!FreeType.isPresent) { string filename = (Application.platform == RuntimePlatform.WindowsEditor) ? "FreeType.dll" : "FreeType.dylib"; EditorGUILayout.HelpBox("Assets/NGUI/Editor/" + filename + " is missing", MessageType.Error); GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Find " + filename)) { string path = EditorUtility.OpenFilePanel("Find " + filename, NGUISettings.currentPath, (Application.platform == RuntimePlatform.WindowsEditor) ? "dll" : "dylib"); if (!string.IsNullOrEmpty(path)) { if (System.IO.Path.GetFileName(path) == filename) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); NGUISettings.pathToFreeType = path; } else { Debug.LogError("The library must be named '" + filename + "'"); } } } GUILayout.Space(20f); GUILayout.EndHorizontal(); } else if (ttf != null) { string[] faces = FreeType.GetFaces(ttf); if (faces != null) { if (mFaceIndex >= faces.Length) { mFaceIndex = 0; } if (faces.Length > 1) { GUILayout.Label("Style", EditorStyles.boldLabel); for (int i = 0; i < faces.Length; ++i) { GUILayout.BeginHorizontal(); GUILayout.Space(10f); if (DrawOption(i == mFaceIndex, " " + faces[i])) { mFaceIndex = i; } GUILayout.EndHorizontal(); } } } GUILayout.Label("Characters", EditorStyles.boldLabel); CharacterMap cm = characterMap; GUILayout.BeginHorizontal(GUILayout.Width(100f)); GUILayout.BeginVertical(); GUI.changed = false; if (DrawOption(cm == CharacterMap.Numeric, " Numeric")) { cm = CharacterMap.Numeric; } if (DrawOption(cm == CharacterMap.Ascii, " ASCII")) { cm = CharacterMap.Ascii; } if (DrawOption(cm == CharacterMap.Latin, " Latin")) { cm = CharacterMap.Latin; } if (DrawOption(cm == CharacterMap.Custom, " Custom")) { cm = CharacterMap.Custom; } if (GUI.changed) { characterMap = cm; } GUILayout.EndVertical(); EditorGUI.BeginDisabledGroup(cm != CharacterMap.Custom); { if (cm != CharacterMap.Custom) { string chars = ""; if (cm == CharacterMap.Ascii) { for (int i = 33; i < 127; ++i) { chars += System.Convert.ToChar(i); } } else if (cm == CharacterMap.Numeric) { chars = "01234567890"; } else if (cm == CharacterMap.Latin) { for (int i = 33; i < 127; ++i) { chars += System.Convert.ToChar(i); } for (int i = 161; i < 256; ++i) { chars += System.Convert.ToChar(i); } } NGUISettings.charsToInclude = chars; } GUI.changed = false; string text = NGUISettings.charsToInclude; if (cm == CharacterMap.Custom) { text = EditorGUILayout.TextArea(text, GUI.skin.textArea, GUILayout.Height(80f), GUILayout.Width(Screen.width - 100f)); } else { GUILayout.Label(text, GUI.skin.textArea, GUILayout.Height(80f), GUILayout.Width(Screen.width - 100f)); } if (GUI.changed) { string final = ""; for (int i = 0; i < text.Length; ++i) { char c = text[i]; if (c < 33) { continue; } string s = c.ToString(); if (!final.Contains(s)) { final += s; } } if (final.Length > 0) { char[] chars = final.ToCharArray(); System.Array.Sort(chars); final = new string(chars); } else { final = ""; } NGUISettings.charsToInclude = final; } } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } } NGUIEditorTools.EndContents(); if (mType == FontType.Dynamic) { EditorGUI.BeginDisabledGroup(ttf == null); GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Create the Font")) { create = Create.Dynamic; } GUILayout.Space(20f); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else // Helpful info if (ttf == null) { EditorGUILayout.HelpBox("You don't have to create a UIFont to use dynamic fonts. You can just reference the Unity Font directly on the label.", MessageType.Info); } EditorGUILayout.HelpBox("Please note that dynamic fonts can't be made a part of an atlas, and using dynamic fonts will result in at least one extra draw call.", MessageType.Warning); #endif } else { bool isBuiltIn = (ttf != null) && string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(ttf)); // Draw the atlas selection only if we have the font data and texture specified, just to make it easier EditorGUI.BeginDisabledGroup(ttf == null || isBuiltIn || !FreeType.isPresent); { NGUIEditorTools.DrawHeader("Output", true); NGUIEditorTools.BeginContents(false); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false); NGUIEditorTools.EndContents(); if (ttf == null) { EditorGUILayout.HelpBox("You can create a bitmap font by specifying a dynamic font to use as the source.", MessageType.Info); } else if (isBuiltIn) { EditorGUILayout.HelpBox("You chose an embedded font. You can't create a bitmap font from an embedded resource.", MessageType.Warning); } else if (NGUISettings.atlas == null) { EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " + "labels using this font will generate an extra draw call.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info); } GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Create the Font")) { create = Create.Bitmap; } GUILayout.Space(20f); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); } } if (create == Create.None) { return; } // Open the "Save As" file dialog #if UNITY_3_5 string prefabPath = EditorUtility.SaveFilePanel("Save As", NGUISettings.currentPath, "New Font.prefab", "prefab"); #else string prefabPath = EditorUtility.SaveFilePanelInProject("Save As", "New Font.prefab", "prefab", "Save font as...", NGUISettings.currentPath); #endif if (string.IsNullOrEmpty(prefabPath)) { return; } NGUISettings.currentPath = System.IO.Path.GetDirectoryName(prefabPath); // Load the font's prefab GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; Object prefab = null; string fontName; // Font doesn't exist yet if (go == null || go.GetComponent <UIFont>() == null) { // Create a new prefab for the atlas prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); fontName = prefabPath.Replace(".prefab", ""); fontName = fontName.Substring(prefabPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1); // Create a new game object for the font go = new GameObject(fontName); uiFont = go.AddComponent <UIFont>(); } else { uiFont = go.GetComponent <UIFont>(); fontName = go.name; } if (create == Create.Dynamic) { uiFont.atlas = null; uiFont.dynamicFont = NGUISettings.dynamicFont; uiFont.dynamicFontStyle = NGUISettings.fontStyle; uiFont.defaultSize = NGUISettings.fontSize; } else if (create == Create.Import) { Material mat = null; if (NGUISettings.atlas != null) { // Add the font's texture to the atlas UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, NGUISettings.fontTexture); } else { // Create a material for the font string matPath = prefabPath.Replace(".prefab", ".mat"); mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; // If the material doesn't exist, create it if (mat == null) { Shader shader = Shader.Find("Unlit/Transparent Colored"); mat = new Material(shader); // Save the material AssetDatabase.CreateAsset(mat, matPath); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); // Load the material so it's usable mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; } mat.mainTexture = NGUISettings.fontTexture; } uiFont.dynamicFont = null; BMFontReader.Load(uiFont.bmFont, NGUITools.GetHierarchy(uiFont.gameObject), NGUISettings.fontData.bytes); if (NGUISettings.atlas == null) { uiFont.atlas = null; uiFont.material = mat; } else { uiFont.spriteName = NGUISettings.fontTexture.name; uiFont.atlas = NGUISettings.atlas; } NGUISettings.fontSize = uiFont.defaultSize; } else if (create == Create.Bitmap) { // Create the bitmap font BMFont bmFont; Texture2D tex; if (FreeType.CreateFont( NGUISettings.dynamicFont, NGUISettings.fontSize, mFaceIndex, NGUISettings.charsToInclude, out bmFont, out tex)) { uiFont.bmFont = bmFont; tex.name = fontName; if (NGUISettings.atlas != null) { // Add this texture to the atlas and destroy it UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, tex); NGUITools.DestroyImmediate(tex); NGUISettings.fontTexture = null; tex = null; uiFont.atlas = NGUISettings.atlas; uiFont.spriteName = fontName; } else { string texPath = prefabPath.Replace(".prefab", ".png"); string matPath = prefabPath.Replace(".prefab", ".mat"); byte[] png = tex.EncodeToPNG(); FileStream fs = File.OpenWrite(texPath); fs.Write(png, 0, png.Length); fs.Close(); // See if the material already exists Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; // If the material doesn't exist, create it if (mat == null) { Shader shader = Shader.Find("Unlit/Transparent Colored"); mat = new Material(shader); // Save the material AssetDatabase.CreateAsset(mat, matPath); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); // Load the material so it's usable mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; } else { AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); } // Re-load the texture tex = AssetDatabase.LoadAssetAtPath(texPath, typeof(Texture2D)) as Texture2D; // Assign the texture mat.mainTexture = tex; NGUISettings.fontTexture = tex; uiFont.atlas = null; uiFont.material = mat; } } else { return; } } if (prefab != null) { // Update the prefab PrefabUtility.ReplacePrefab(go, prefab); DestroyImmediate(go); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); // Select the atlas go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; uiFont = go.GetComponent <UIFont>(); } if (uiFont != null) { NGUISettings.ambigiousFont = uiFont; } MarkAsChanged(); Selection.activeGameObject = go; }
private void OnGUI() { //向下空出5个像素 GUILayout.Space(8); //创建是否改变当前字体开关 isChangFont = EditorGUILayout.Toggle("是否改变当前字体", isChangFont); GUILayout.Space(5); //如果改变当前字体则创建字体文件选择框 if (isChangFont) { if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f))) { ComponentSelector.Show <Font>(OnNGUIFont); } curFont = (Font)EditorGUILayout.ObjectField("", curFont, typeof(Font), true); GUILayout.Space(5); } //创建是否改变字体类型开关 isChangeStyle = EditorGUILayout.Toggle("是否改变字体类型", isChangeStyle); GUILayout.Space(5); //如果改变,则创建字体类型的枚举下拉框 if (isChangeStyle) { curFontStyle = (FontStyle)EditorGUILayout.EnumPopup("字体类型", curFontStyle); GUILayout.Space(5); } //创建是否增加字体大小的开关 isChangeSize = EditorGUILayout.Toggle("是否设置字体大小", isChangeSize); GUILayout.Space(5); if (isChangeSize) { //fontSize = EditorGUILayout.IntField(fontSize, GUI.skin.textArea, // GUILayout.Height(20f), GUILayout.Width(Screen.width - 100f)); beforFontSize = EditorGUILayout.IntField("被替换的字体大小", beforFontSize); GUILayout.Space(5); nowFontSize = EditorGUILayout.IntField("替换后的字体大小", nowFontSize); GUILayout.Space(5); } isChangeEffect = EditorGUILayout.Toggle("是否改变阴影特效", isChangeEffect); GUILayout.Space(5); if (isChangeEffect) { fontEffect = (UILabel.Effect)EditorGUILayout.EnumPopup("阴影特效", fontEffect); GUILayout.Space(5); } isSetGradientApply = EditorGUILayout.Toggle("是否设置颜色渐变", isSetGradientApply); if (isSetGradientApply) { isGradientApply = EditorGUILayout.Toggle("使用", isGradientApply); } isChangeColor = EditorGUILayout.Toggle("是否改变颜色", isChangeColor); GUILayout.Space(10); if (isChangeColor) { isSelfWrite = EditorGUILayout.Toggle("是否自己填写颜色", isSelfWrite); GUILayout.Space(5); if (isSelfWrite) { selfColor = (Color)EditorGUILayout.ColorField("初始的颜色", selfColor); } else { beforColor = (ClientColorConfig.ClientColor)EditorGUILayout.EnumPopup("初始的颜色", beforColor); GUILayout.Space(8); } nowColor = (ClientColorConfig.ClientColor)EditorGUILayout.EnumPopup("修改后的颜色", nowColor); GUILayout.Space(5); } //创建确认按钮 if (GUILayout.Button("确认修改", GUILayout.Height(30), GUILayout.Width(300))) { Change(); } }