static byte InterpolateComponent( Color endPoint1, Color endPoint2, double lambda, ComponentSelector selector) { return (byte)(selector(endPoint1) + (selector(endPoint2) - selector(endPoint1)) * lambda); }
/// <summary> /// Draw the UI for this tool. /// </summary> void OnGUI() { if (mLastAtlas != NGUISettings.atlas) { mLastAtlas = NGUISettings.atlas; atlasName = (NGUISettings.atlas != null) ? NGUISettings.atlas.name : "New Atlas"; } bool create = false; bool update = false; bool replace = false; string prefabPath = ""; string matPath = ""; // If we have an atlas to work with, see if we can figure out the path for it and its material if (NGUISettings.atlas != null && NGUISettings.atlas.name == atlasName) { prefabPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.gameObject.GetInstanceID()); if (NGUISettings.atlas.spriteMaterial != null) { matPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.spriteMaterial.GetInstanceID()); } } // Assume default values if needed if (string.IsNullOrEmpty(atlasName)) { atlasName = "New Atlas"; } if (string.IsNullOrEmpty(prefabPath)) { prefabPath = NGUIEditorTools.GetSelectionFolder() + atlasName + ".prefab"; } if (string.IsNullOrEmpty(matPath)) { matPath = NGUIEditorTools.GetSelectionFolder() + atlasName + ".mat"; } // Try to load the prefab GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (NGUISettings.atlas == null && go != null) { NGUISettings.atlas = go.GetComponent <UIAtlas>(); } NGUIEditorTools.SetLabelWidth(80f); GUILayout.Space(6f); GUILayout.BeginHorizontal(); if (go == null) { GUI.backgroundColor = Color.green; create = GUILayout.Button("Create", GUILayout.Width(76f)); } else { GUI.backgroundColor = Color.red; create = GUILayout.Button("Replace", GUILayout.Width(76f)); } GUI.backgroundColor = Color.white; atlasName = GUILayout.TextField(atlasName); GUILayout.EndHorizontal(); if (create) { // If the prefab already exists, confirm that we want to overwrite it if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " + atlasName + " atlas with the textures currently selected in the Project View? All other sprites will be deleted.", "Yes", "No")) { replace = true; // Try to load the material Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; // If the material doesn't exist, create it if (mat == null) { Shader shader = Shader.Find(NGUISettings.atlasPMA ? "Unlit/Premultiplied Colored" : "Unlit/Transparent Colored"); mat = new Material(shader); // Save the material AssetDatabase.CreateAsset(mat, matPath); AssetDatabase.Refresh(); // Load the material so it's usable mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; } if (NGUISettings.atlas == null || NGUISettings.atlas.name != atlasName) { // Create a new prefab for the atlas Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(prefabPath); // Create a new game object for the atlas go = new GameObject(atlasName); go.AddComponent <UIAtlas>().spriteMaterial = mat; // Update the prefab PrefabUtility.ReplacePrefab(go, prefab); DestroyImmediate(go); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); // Select the atlas go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; NGUISettings.atlas = go.GetComponent <UIAtlas>(); } } } ComponentSelector.Draw <UIAtlas>("Select", NGUISettings.atlas, OnSelectAtlas, true); List <Texture> textures = GetSelectedTextures(); if (NGUISettings.atlas != null && NGUISettings.atlas.name == atlasName) { Material mat = NGUISettings.atlas.spriteMaterial; Texture tex = NGUISettings.atlas.texture; // Material information GUILayout.BeginHorizontal(); { if (mat != null) { if (GUILayout.Button("Material", GUILayout.Width(76f))) { Selection.activeObject = mat; } GUILayout.Label(" " + mat.name); } else { GUI.color = Color.grey; GUILayout.Button("Material", GUILayout.Width(76f)); GUI.color = Color.white; GUILayout.Label(" N/A"); } } GUILayout.EndHorizontal(); // Texture atlas information GUILayout.BeginHorizontal(); { if (tex != null) { if (GUILayout.Button("Texture", GUILayout.Width(76f))) { Selection.activeObject = tex; } GUILayout.Label(" " + tex.width + "x" + tex.height); } else { GUI.color = Color.grey; GUILayout.Button("Texture", GUILayout.Width(76f)); GUI.color = Color.white; GUILayout.Label(" N/A"); } } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); NGUISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", NGUISettings.atlasPadding, GUILayout.Width(100f)), 0, 8); GUILayout.Label((NGUISettings.atlasPadding == 1 ? "pixel" : "pixels") + " in-between of sprites"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", NGUISettings.atlasTrimming, GUILayout.Width(100f)); GUILayout.Label("Remove empty space"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.atlasPMA = EditorGUILayout.Toggle("PMA Shader", NGUISettings.atlasPMA, GUILayout.Width(100f)); GUILayout.Label("Pre-multiply color by alpha"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.Width(100f)); GUILayout.Label("if off, use a custom packer"); GUILayout.EndHorizontal(); if (!NGUISettings.unityPacking) { GUILayout.BeginHorizontal(); NGUISettings.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", NGUISettings.forceSquareAtlas, GUILayout.Width(100f)); GUILayout.Label("if on, forces a square atlas texture"); GUILayout.EndHorizontal(); } #if UNITY_IPHONE || UNITY_ANDROID GUILayout.BeginHorizontal(); NGUISettings.allow4096 = EditorGUILayout.Toggle("4096x4096", NGUISettings.allow4096, GUILayout.Width(100f)); GUILayout.Label("if off, limit atlases to 2048x2048"); GUILayout.EndHorizontal(); #endif if (NGUISettings.atlas != null && NGUISettings.atlas.name == atlasName) { if (textures.Count > 0) { GUI.backgroundColor = Color.green; update = GUILayout.Button("Add/Update All"); GUI.backgroundColor = Color.white; } else { EditorGUILayout.HelpBox("You can reveal more options by selecting one or more textures in the Project View window.", MessageType.Info); } } else { EditorGUILayout.HelpBox("You can create a new atlas by selecting one or more textures in the Project View window, then clicking \"Create\".", MessageType.Info); } string selection = null; Dictionary <string, int> spriteList = GetSpriteList(textures); if (spriteList.Count > 0) { NGUIEditorTools.DrawHeader("Sprites", true); { GUILayout.BeginHorizontal(); GUILayout.Space(3f); GUILayout.BeginVertical(); mScroll = GUILayout.BeginScrollView(mScroll); bool delete = false; int index = 0; foreach (KeyValuePair <string, int> iter in spriteList) { ++index; GUILayout.Space(-1f); bool highlight = (UIAtlasInspector.instance != null) && (NGUISettings.selectedSprite == iter.Key); GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f); GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f)); GUI.backgroundColor = Color.white; GUILayout.Label(index.ToString(), GUILayout.Width(24f)); if (GUILayout.Button(iter.Key, "OL TextField", GUILayout.Height(20f))) { selection = iter.Key; } if (iter.Value == 2) { GUI.color = Color.green; GUILayout.Label("Add", GUILayout.Width(27f)); GUI.color = Color.white; } else if (iter.Value == 1) { GUI.color = Color.cyan; GUILayout.Label("Update", GUILayout.Width(45f)); GUI.color = Color.white; } else { if (mDelNames.Contains(iter.Key)) { GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete", GUILayout.Width(60f))) { delete = true; } GUI.backgroundColor = Color.green; if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Remove(iter.Key); delete = false; } GUI.backgroundColor = Color.white; } else { // If we have not yet selected a sprite for deletion, show a small "X" button if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Add(iter.Key); } } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.Space(3f); GUILayout.EndHorizontal(); // If this sprite was marked for deletion, remove it from the atlas if (delete) { List <SpriteEntry> sprites = new List <SpriteEntry>(); ExtractSprites(NGUISettings.atlas, sprites); for (int i = sprites.Count; i > 0;) { SpriteEntry ent = sprites[--i]; if (mDelNames.Contains(ent.name)) { sprites.RemoveAt(i); } } UpdateAtlas(NGUISettings.atlas, sprites); mDelNames.Clear(); } else if (update) { UpdateAtlas(textures, true); } else if (replace) { UpdateAtlas(textures, false); } if (NGUISettings.atlas != null && !string.IsNullOrEmpty(selection)) { NGUISettings.selectedSprite = selection; Selection.activeGameObject = NGUISettings.atlas.gameObject; if (UIAtlasInspector.instance != null) { UIAtlasInspector.instance.Repaint(); } } else if (update || replace) { NGUIEditorTools.UpgradeTexturesToSprites(NGUISettings.atlas); } } } // Uncomment this line if you want to be able to force-sort the atlas //if (NGUISettings.atlas != null && GUILayout.Button("Sort Alphabetically")) NGUISettings.atlas.SortAlphabetically(); }
/// <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(); 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) { 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"); 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(); 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(); NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); GUILayout.BeginHorizontal(); sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f)); EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols); NGUIEditorTools.SetLabelWidth(60f); NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols"); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); return(isValid); }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; var sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); var after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; NGUITools.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); var mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsChanged(); } if (mat != null) { var ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsChanged(); } var pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } } if (mAtlas.spriteMaterial != null) { var blueColor = new Color(0f, 0.7f, 1f, 1f); var greenColor = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { var spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } var tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; var sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); var sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; var borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); var borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; var padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); var padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } GUILayout.Space(3f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Duplicate")) { var se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); if (se != null) { NGUISettings.selectedSprite = se.name; } } if (GUILayout.Button("Save As...")) { var path = EditorUtility.SaveFilePanel("Save As", NGUISettings.currentPath, sprite.name + ".png", "png"); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); var se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name); if (se != null) { var bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); if (GUILayout.Button("Add a Shadow")) { AddShadow(sprite); } if (GUILayout.Button("Add a Soft Outline")) { AddOutline(sprite); } if (GUILayout.Button("Add a Transparent Border")) { AddTransparentBorder(sprite); } if (GUILayout.Button("Add a Clamped Border")) { AddClampedBorder(sprite); } if (GUILayout.Button("Add a Tiled Border")) { AddTiledBorder(sprite); } EditorGUI.BeginDisabledGroup(!sprite.hasBorder); if (GUILayout.Button("Crop Border")) { CropBorder(sprite); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
override protected bool DrawProperties() { mLabel = mWidget as UILabel; ComponentSelector.Draw <UIFont>(mLabel.font, OnSelectFont); if (mLabel.font == null) { return(false); } GUI.skin.textArea.wordWrap = true; string text = string.IsNullOrEmpty(mLabel.text) ? "" : mLabel.text; text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f)); if (!text.Equals(mLabel.text)) { RegisterUndo(); mLabel.text = text; } GUILayout.BeginHorizontal(); { int len = EditorGUILayout.IntField("Line Width", mLabel.lineWidth, GUILayout.Width(120f)); if (len != mLabel.lineWidth) { RegisterUndo(); mLabel.lineWidth = len; } int count = EditorGUILayout.IntField("Line Count", mLabel.maxLineCount, GUILayout.Width(100f)); if (count != mLabel.maxLineCount) { RegisterUndo(); mLabel.maxLineCount = count; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(120f)); if (password != mLabel.password) { RegisterUndo(); mLabel.password = password; } bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f)); if (encoding != mLabel.supportEncoding) { RegisterUndo(); mLabel.supportEncoding = encoding; } GUILayout.EndHorizontal(); if (encoding && mLabel.font.hasSymbols) { UIFont.SymbolStyle sym = (UIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f)); if (sym != mLabel.symbolStyle) { RegisterUndo(); mLabel.symbolStyle = sym; } } GUILayout.BeginHorizontal(); { UILabel.Effect effect = (UILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f)); if (effect != mLabel.effectStyle) { RegisterUndo(); mLabel.effectStyle = effect; } if (effect != UILabel.Effect.None) { Color c = EditorGUILayout.ColorField(mLabel.effectColor); if (mLabel.effectColor != c) { RegisterUndo(); mLabel.effectColor = c; } } } GUILayout.EndHorizontal(); if (mLabel.effectStyle != UILabel.Effect.None) { GUILayout.Label("Distance", GUILayout.Width(70f)); GUILayout.Space(-34f); GUILayout.BeginHorizontal(); GUILayout.Space(70f); Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance); GUILayout.Space(20f); if (offset != mLabel.effectDistance) { RegisterUndo(); mLabel.effectDistance = offset; } GUILayout.EndHorizontal(); } return(true); }
public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); GUILayout.Space(6f); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement; } else if (mFont.dynamicFont != null) { mType = FontType.Dynamic; } GUI.changed = false; GUILayout.BeginHorizontal(); mType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (GUI.changed) { if (mType == FontType.Bitmap) { OnSelectFont(null); } if (mType != FontType.Dynamic && mFont.dynamicFont != null) { mFont.dynamicFont = null; } } if (mType == FontType.Reference) { ComponentSelector.Draw(mFont.replacement, OnSelectFont, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one font simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "font with another one, for example for " + "swapping an SD font with an HD one, or " + "replacing an English font with a Chinese " + "one. All the labels referencing this font " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont as Object); mFont.replacement = mReplacement; NGUITools.SetDirty(mFont as Object); } return; } else if (mType == FontType.Dynamic) { #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font; if (fnt != mFont.dynamicFont) { NGUIEditorTools.RegisterUndo("Font change", mFont as Object); mFont.dynamicFont = fnt; } Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont as Object); mFont.material = mat; } GUILayout.BeginHorizontal(); int size = EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f)); FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (size != mFont.defaultSize) { NGUIEditorTools.RegisterUndo("Font change", mFont as Object); mFont.defaultSize = size; } if (style != mFont.dynamicFontStyle) { NGUIEditorTools.RegisterUndo("Font change", mFont as Object); mFont.dynamicFontStyle = style; } #endif } else { ComponentSelector.Draw(mFont.atlas, OnSelectAtlas, true); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont as Object); mFont.material = mat; } } if (!mFont.isDynamic) { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f)); EditorGUI.EndDisabledGroup(); } EditorGUILayout.Space(); // For updating the font's data when importing from an external source, such as the texture packer bool resetWidthHeight = false; if (mFont.atlas != null || mFont.material != null) { TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont as Object); BMFontReader.Load(mFont.bmFont, (mFont as Object).name, data.bytes); mFont.MarkAsChanged(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } if (mFont is UIFont && mFont.bmFont.isValid) { EditorGUILayout.HelpBox("Legacy font type should be upgraded in order to maintain compatibility with Unity 2018 and newer.", MessageType.Warning, true); if (GUILayout.Button("Upgrade")) { var path = EditorUtility.SaveFilePanelInProject("Save As", (mFont as Object).name + ".asset", "asset", "Save atlas as...", NGUISettings.currentPath); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); var asset = ScriptableObject.CreateInstance <NGUIFont>(); asset.bmFont = mFont.bmFont; asset.symbols = mFont.symbols; asset.atlas = mFont.atlas; asset.spriteName = mFont.spriteName; asset.uvRect = mFont.uvRect; asset.defaultSize = mFont.defaultSize; var fontName = path.Replace(".asset", ""); fontName = fontName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1); asset.name = fontName; AssetDatabase.CreateAsset(asset, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); asset = AssetDatabase.LoadAssetAtPath <NGUIFont>(path); NGUISettings.ambigiousFont = asset; Selection.activeObject = asset; if (asset != null) { mFont.replacement = asset; mFont.MarkAsChanged(); } } } } if (mFont.bmFont.isValid) { Texture2D tex = mFont.texture; if (tex != null && mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle pixels = EditorGUILayout.RectField("Pixel Rect", pixels); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont as Object); mFont.uvRect = uvRect; } //NGUIEditorTools.DrawSeparator(); EditorGUILayout.Space(); } } } // Dynamic fonts don't support emoticons if (!mFont.isDynamic && mFont.bmFont.isValid) { if (mFont.atlas != null) { if (NGUIEditorTools.DrawHeader("Symbols and Emoticons")) { NGUIEditorTools.BeginContents(); List <BMSymbol> symbols = mFont.symbols; for (int i = 0; i < symbols.Count;) { BMSymbol sym = symbols[i]; GUILayout.BeginHorizontal(); GUILayout.Label(sym.sequence, GUILayout.Width(40f)); if (NGUIEditorTools.DrawSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite, GUILayout.MinWidth(100f))) { mSelectedSymbol = sym; } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (mFont.atlas != null) { NGUISettings.atlas = mFont.atlas; NGUISettings.selectedSprite = sym.spriteName; NGUIEditorTools.Select(mFont.atlas as Object); } } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove symbol", mFont as Object); mSymbolSequence = sym.sequence; mSymbolSprite = sym.spriteName; symbols.Remove(sym); mFont.MarkAsChanged(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); ++i; } if (symbols.Count > 0) { GUILayout.Space(6f); } GUILayout.BeginHorizontal(); mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f)); NGUIEditorTools.DrawSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite); bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add symbol", mFont as Object); mFont.AddSymbol(mSymbolSequence, mSymbolSprite); mFont.MarkAsChanged(); mSymbolSequence = ""; mSymbolSprite = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (symbols.Count == 0) { EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } NGUIEditorTools.EndContents(); } } } if (mFont.bmFont != null && mFont.bmFont.isValid) { if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); UISpriteData sd = mFont.sprite; bool disable = (sd != null && (sd.paddingLeft != 0 || sd.paddingBottom != 0)); EditorGUI.BeginDisabledGroup(disable || mFont.packedFontShader); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); NGUISettings.foregroundColor = EditorGUILayout.ColorField("Foreground", NGUISettings.foregroundColor); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); GUILayout.EndVertical(); mCurve = EditorGUILayout.CurveField("", mCurve, GUILayout.Width(40f), GUILayout.Height(40f)); GUILayout.EndHorizontal(); if (GUILayout.Button("Add a Shadow")) { ApplyEffect(Effect.Shadow, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Add a Soft Outline")) { ApplyEffect(Effect.Outline, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Rebalance Colors")) { ApplyEffect(Effect.Rebalance, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Apply Curve to Alpha")) { ApplyEffect(Effect.AlphaCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Apply Curve to Foreground")) { ApplyEffect(Effect.ForegroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Apply Curve to Background")) { ApplyEffect(Effect.BackgroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } GUILayout.Space(10f); if (GUILayout.Button("Add Transparent Border (+1)")) { ApplyEffect(Effect.Border, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } if (GUILayout.Button("Remove Border (-1)")) { ApplyEffect(Effect.Crop, NGUISettings.foregroundColor, NGUISettings.backgroundColor); } EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); if (disable) { GUILayout.Space(3f); EditorGUILayout.HelpBox("The sprite used by this font has been trimmed and is not suitable for modification. " + "Try re-adding this sprite with 'Trim Alpha' disabled.", MessageType.Warning); } NGUIEditorTools.EndContents(); } } // The font must be valid at this point for the rest of the options to show up if (mFont.isDynamic || mFont.bmFont.isValid) { if (mFont.atlas == null) { mView = View.Font; mUseShader = false; } } // Preview option if (!mFont.isDynamic && mFont.atlas != null) { GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Preview", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)); } GUILayout.EndHorizontal(); } }
/// <summary> /// Draw the UI for this tool. /// </summary> void OnGUI() { if (mLastAtlas != NGUISettings.atlas) { mLastAtlas = NGUISettings.atlas; } bool update = false; bool replace = false; NGUIEditorTools.SetLabelWidth(84f); GUILayout.Space(3f); NGUIEditorTools.DrawHeader("Input", true); NGUIEditorTools.BeginContents(false); GUILayout.BeginHorizontal(); { ComponentSelector.Draw <UIAtlas>("Atlas", NGUISettings.atlas, OnSelectAtlas, true, GUILayout.MinWidth(80f)); EditorGUI.BeginDisabledGroup(NGUISettings.atlas == null); if (GUILayout.Button("New", GUILayout.Width(40f))) { NGUISettings.atlas = null; } EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); List <Texture> textures = GetSelectedTextures(); if (NGUISettings.atlas != null) { Material mat = NGUISettings.atlas.spriteMaterial; Texture tex = NGUISettings.atlas.texture; // Material information GUILayout.BeginHorizontal(); { if (mat != null) { if (GUILayout.Button("Material", GUILayout.Width(76f))) { Selection.activeObject = mat; } GUILayout.Label(" " + mat.name); } else { GUI.color = Color.grey; GUILayout.Button("Material", GUILayout.Width(76f)); GUI.color = Color.white; GUILayout.Label(" N/A"); } } GUILayout.EndHorizontal(); // Texture atlas information GUILayout.BeginHorizontal(); { if (tex != null) { if (GUILayout.Button("Texture", GUILayout.Width(76f))) { Selection.activeObject = tex; } GUILayout.Label(" " + tex.width + "x" + tex.height); } else { GUI.color = Color.grey; GUILayout.Button("Texture", GUILayout.Width(76f)); GUI.color = Color.white; GUILayout.Label(" N/A"); } } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); NGUISettings.atlasExtendPadding = Mathf.Clamp(EditorGUILayout.IntField("Extend", NGUISettings.atlasExtendPadding, GUILayout.Width(100f)), 0, 8); GUILayout.Label((NGUISettings.atlasExtendPadding == 1 ? "pixel" : "pixels") + " around every sprite"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", NGUISettings.atlasPadding, GUILayout.Width(100f)), 0, 8); GUILayout.Label((NGUISettings.atlasPadding == 1 ? "pixel" : "pixels") + " between sprites"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", NGUISettings.atlasTrimming, GUILayout.Width(100f)); GUILayout.Label("Remove empty space"); GUILayout.EndHorizontal(); bool fixedShader = false; if (NGUISettings.atlas != null) { Material mat = NGUISettings.atlas.spriteMaterial; if (mat != null) { Shader shader = mat.shader; if (shader != null) { if (shader.name == "Unlit/Transparent Colored") { NGUISettings.atlasPMA = false; fixedShader = true; } else if (shader.name == "Unlit/Premultiplied Colored") { NGUISettings.atlasPMA = true; fixedShader = true; } } } } if (!fixedShader) { GUILayout.BeginHorizontal(); NGUISettings.atlasPMA = EditorGUILayout.Toggle("PMA Shader", NGUISettings.atlasPMA, GUILayout.Width(100f)); GUILayout.Label("Pre-multiplied alpha", GUILayout.MinWidth(70f)); GUILayout.EndHorizontal(); } //GUILayout.BeginHorizontal(); //NGUISettings.keepPadding = EditorGUILayout.Toggle("Keep Padding", NGUISettings.keepPadding, GUILayout.Width(100f)); //GUILayout.Label("or replace with trimmed pixels", GUILayout.MinWidth(70f)); //GUILayout.EndHorizontal(); #if !UNITY_5_6 GUILayout.BeginHorizontal(); NGUISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.Width(100f)); GUILayout.Label("or custom packer", GUILayout.MinWidth(70f)); GUILayout.EndHorizontal(); #endif GUILayout.BeginHorizontal(); NGUISettings.trueColorAtlas = EditorGUILayout.Toggle("Truecolor", NGUISettings.trueColorAtlas, GUILayout.Width(100f)); GUILayout.Label("force ARGB32 textures", GUILayout.MinWidth(70f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.autoUpgradeSprites = EditorGUILayout.Toggle("Auto-upgrade", NGUISettings.autoUpgradeSprites, GUILayout.Width(100f)); GUILayout.Label("replace textures with sprites", GUILayout.MinWidth(70f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.atlasAlphaSplit = EditorGUILayout.Toggle("Alpha Split", NGUISettings.atlasAlphaSplit, GUILayout.Width(100f)); GUILayout.Label("split alpha to another texture"); GUILayout.EndHorizontal(); #if !UNITY_5_6 if (!NGUISettings.unityPacking) { GUILayout.BeginHorizontal(); NGUISettings.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", NGUISettings.forceSquareAtlas, GUILayout.Width(100f)); GUILayout.Label("if on, forces a square atlas texture", GUILayout.MinWidth(70f)); GUILayout.EndHorizontal(); } #endif #if UNITY_IPHONE || UNITY_ANDROID GUILayout.BeginHorizontal(); NGUISettings.allow4096 = EditorGUILayout.Toggle("4096x4096", NGUISettings.allow4096, GUILayout.Width(100f)); GUILayout.Label("if off, limit atlases to 2048x2048"); GUILayout.EndHorizontal(); #endif NGUIEditorTools.EndContents(); if (NGUISettings.atlas != null) { GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (textures.Count > 0) { update = GUILayout.Button("Add/Update"); } else if (GUILayout.Button("View Sprites")) { SpriteSelector.ShowSelected(); } GUILayout.Space(20f); GUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("You can create a new atlas by selecting one or more textures in the Project View window, then clicking \"Create\".", MessageType.Info); EditorGUI.BeginDisabledGroup(textures.Count == 0); GUILayout.BeginHorizontal(); GUILayout.Space(20f); bool create = GUILayout.Button("Create"); GUILayout.Space(20f); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); if (create) { string path = EditorUtility.SaveFilePanelInProject("Save As", "New Atlas.prefab", "prefab", "Save atlas as...", NGUISettings.currentPath); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); GameObject go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; string matPath = path.Replace(".prefab", ".mat"); replace = true; // Try to load the material Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; // If the material doesn't exist, create it if (mat == null) { Shader shader = Shader.Find(NGUISettings.atlasPMA && !NGUISettings.atlasAlphaSplit ? "Unlit/Premultiplied Colored" : "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; } // Create a new prefab for the atlas Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(path); // Create a new game object for the atlas string atlasName = path.Replace(".prefab", ""); atlasName = atlasName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1); go = new GameObject(atlasName); go.AddComponent <UIAtlas>().spriteMaterial = mat; // Update the prefab PrefabUtility.ReplacePrefab(go, prefab); DestroyImmediate(go); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); // Select the atlas go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; NGUISettings.atlas = go.GetComponent <UIAtlas>(); Selection.activeGameObject = go; } } } string selection = null; Dictionary <string, int> spriteList = GetSpriteList(textures); if (spriteList.Count > 0) { NGUIEditorTools.DrawHeader("Sprites", true); { GUILayout.BeginHorizontal(); GUILayout.Space(3f); GUILayout.BeginVertical(); mScroll = GUILayout.BeginScrollView(mScroll); bool delete = false; int index = 0; foreach (KeyValuePair <string, int> iter in spriteList) { ++index; GUILayout.Space(-1f); bool highlight = (UIAtlasInspector.instance != null) && (NGUISettings.selectedSprite == iter.Key); GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f); GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f)); GUI.backgroundColor = Color.white; GUILayout.Label(index.ToString(), GUILayout.Width(24f)); if (GUILayout.Button(iter.Key, "OL TextField", GUILayout.Height(20f))) { selection = iter.Key; } if (iter.Value == 2) { GUI.color = Color.green; GUILayout.Label("Add", GUILayout.Width(27f)); GUI.color = Color.white; } else if (iter.Value == 1) { GUI.color = Color.cyan; GUILayout.Label("Update", GUILayout.Width(45f)); GUI.color = Color.white; } else { if (mDelNames.Contains(iter.Key)) { GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete", GUILayout.Width(60f))) { delete = true; } GUI.backgroundColor = Color.green; if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Remove(iter.Key); delete = false; } GUI.backgroundColor = Color.white; } else { // If we have not yet selected a sprite for deletion, show a small "X" button if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Add(iter.Key); } } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.Space(3f); GUILayout.EndHorizontal(); // If this sprite was marked for deletion, remove it from the atlas if (delete) { List <SpriteEntry> sprites = new List <SpriteEntry>(); ExtractSprites(NGUISettings.atlas, sprites); for (int i = sprites.Count; i > 0;) { SpriteEntry ent = sprites[--i]; if (mDelNames.Contains(ent.name)) { sprites.RemoveAt(i); } } UpdateAtlas(NGUISettings.atlas, sprites); mDelNames.Clear(); NGUIEditorTools.RepaintSprites(); } else if (update) { UpdateAtlas(textures, true); } else if (replace) { UpdateAtlas(textures, false); } if (NGUISettings.atlas != null && !string.IsNullOrEmpty(selection)) { NGUIEditorTools.SelectSprite(selection); } else if (NGUISettings.autoUpgradeSprites && (update || replace)) { NGUIEditorTools.UpgradeTexturesToSprites(NGUISettings.atlas); NGUIEditorTools.RepaintSprites(); } } } if (NGUISettings.atlas != null && textures.Count == 0) { EditorGUILayout.HelpBox("You can reveal more options by selecting one or more textures in the Project View window.", MessageType.Info); } // Uncomment this line if you want to be able to force-sort the atlas //if (NGUISettings.atlas != null && GUILayout.Button("Sort Alphabetically")) NGUISettings.atlas.SortAlphabetically(); }
override public void OnInspectorGUI() { mFont = target as UIFont; EditorGUIUtility.LookLikeControls(80f); NGUIEditorTools.DrawSeparator(); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement; } FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); if (mType != after) { if (after == FontType.Normal) { OnSelectFont(null); } else { mType = FontType.Reference; } } if (mType == FontType.Reference) { ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont); NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can have one font simply point to\n" + "another one. This is useful if you want to be\n" + "able to quickly replace the contents of one\n" + "font with another one, for example for\n" + "swapping an SD font with an HD one, or\n" + "replacing an English font with a Chinese\n" + "one. All the labels referencing this font\n" + "will update their references to the new one."); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mFont); } return; } NGUIEditorTools.DrawSeparator(); ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas); if (mFont.atlas != null) { if (mFont.bmFont.LegacyCheck()) { Debug.Log(mFont.name + " uses a legacy font data structure. Upgrading, please save."); EditorUtility.SetDirty(mFont); } if (mFont.bmFont.isValid) { NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } } bool resetWidthHeight = false; if (mFont.atlas != null || mFont.material != null) { TextAsset data = EditorGUILayout.ObjectField("Import Font", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont); BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes); mFont.MarkAsDirty(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } if (mFont.bmFont.isValid) { Color green = new Color(0.4f, 1f, 0f, 1f); Texture2D tex = mFont.texture; if (tex != null) { if (mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle GUI.backgroundColor = green; pixels = EditorGUILayout.RectField("Pixel Rect", pixels); GUI.backgroundColor = Color.white; // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { GUILayout.Label("Correction", GUILayout.Width(75f)); Rect corrected = NGUIMath.MakePixelPerfect(pixels); if (corrected == pixels) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { pixels = corrected; GUI.changed = true; } } GUILayout.EndHorizontal(); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont); mFont.uvRect = uvRect; } } // Font spacing GUILayout.BeginHorizontal(); { EditorGUIUtility.LookLikeControls(0f); GUILayout.Label("Spacing", GUILayout.Width(60f)); GUILayout.Label("X", GUILayout.Width(12f)); int x = EditorGUILayout.IntField(mFont.horizontalSpacing); GUILayout.Label("Y", GUILayout.Width(12f)); int y = EditorGUILayout.IntField(mFont.verticalSpacing); EditorGUIUtility.LookLikeControls(80f); if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y) { NGUIEditorTools.RegisterUndo("Font Spacing", mFont); mFont.horizontalSpacing = x; mFont.verticalSpacing = y; } } GUILayout.EndHorizontal(); if (mFont.atlas == null) { mView = View.Font; mUseShader = false; float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f)); if (pixelSize != mFont.pixelSize) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.pixelSize = pixelSize; } } else { GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Preview", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)); } GUILayout.EndHorizontal(); } } } }
override protected bool DrawProperties() { mLabel = mWidget as EmojiUILabel; ComponentSelector.Draw <UIFont>(mLabel.font, OnSelectFont); if (mLabel.font == null) { return(false); } GUI.skin.textArea.wordWrap = true; string text = string.IsNullOrEmpty(mLabel.text) ? "" : mLabel.text; text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f)); if (!text.Equals(mLabel.text)) { RegisterUndo(); mLabel.text = text; } EditorGUILayout.LabelField("*Language Id代替text序列化"); EditorGUILayout.LabelField("*固定内容直接把中文表id填到Language Id"); GUILayout.BeginHorizontal(); int languageId = EditorGUILayout.IntField("Language Id", mLabel.LanguageId, GUILayout.Width(220f)); if (languageId != mLabel.LanguageId) { SystemSwitch.ReleaseMode = false; SystemSwitch.UseHmf = false; UILabel.GetContent = Mogo.GameData.LanguageData.GetContent; RegisterUndo(); mLabel.LanguageId = languageId; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { int len = EditorGUILayout.IntField("Line Width", mLabel.lineWidth, GUILayout.Width(120f)); if (len != mLabel.lineWidth) { RegisterUndo(); mLabel.lineWidth = len; } int count = EditorGUILayout.IntField("Line Count", mLabel.maxLineCount, GUILayout.Width(120f)); if (count != mLabel.maxLineCount) { RegisterUndo(); mLabel.maxLineCount = count; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { int len = EditorGUILayout.IntField("Spacing X", mLabel.spacingX, GUILayout.Width(120f)); if (len != mLabel.spacingX) { RegisterUndo(); mLabel.spacingX = len; } int count = EditorGUILayout.IntField("Spacing Y", mLabel.spacingY, GUILayout.Width(120f)); if (count != mLabel.spacingY) { RegisterUndo(); mLabel.spacingY = count; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(120f)); if (password != mLabel.password) { RegisterUndo(); mLabel.password = password; } bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f)); if (encoding != mLabel.supportEncoding) { RegisterUndo(); mLabel.supportEncoding = encoding; } bool tranlateReturn = EditorGUILayout.Toggle("TranslateReturn", mLabel.TranslateReturn, GUILayout.Width(120f)); if (tranlateReturn != mLabel.TranslateReturn) { RegisterUndo(); mLabel.TranslateReturn = tranlateReturn; } GUILayout.EndHorizontal(); if (encoding && mLabel.font.hasSymbols) { UIFont.SymbolStyle sym = (UIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f)); if (sym != mLabel.symbolStyle) { RegisterUndo(); mLabel.symbolStyle = sym; } } GUILayout.BeginHorizontal(); { EmojiUILabel.Effect effect = (EmojiUILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f)); if (effect != mLabel.effectStyle) { RegisterUndo(); mLabel.effectStyle = effect; } if (effect != EmojiUILabel.Effect.None) { Color c = EditorGUILayout.ColorField(mLabel.effectColor); if (mLabel.effectColor != c) { RegisterUndo(); mLabel.effectColor = c; } } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (mLabel.effectStyle != EmojiUILabel.Effect.None) { GUILayout.BeginHorizontal(); GUILayout.Label("Distance", GUILayout.Width(70f)); Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance); GUILayout.Space(20f); if (offset != mLabel.effectDistance) { RegisterUndo(); mLabel.effectDistance = offset; } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); return(true); }
override public void OnInspectorGUI() { mFont = target as UIFont; EditorGUIUtility.LookLikeControls(80f); NGUIEditorTools.DrawSeparator(); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement; } else if (mFont.dynamicFont != null) { mType = FontType.Dynamic; } GUILayout.BeginHorizontal(); FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (mType != fontType) { if (fontType == FontType.Normal) { OnSelectFont(null); } else { mType = fontType; } if (mType != FontType.Dynamic && mFont.dynamicFont != null) { mFont.dynamicFont = null; } } if (mType == FontType.Reference) { ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont); NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can have one font simply point to\n" + "another one. This is useful if you want to be\n" + "able to quickly replace the contents of one\n" + "font with another one, for example for\n" + "swapping an SD font with an HD one, or\n" + "replacing an English font with a Chinese\n" + "one. All the labels referencing this font\n" + "will update their references to the new one."); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mFont); } return; } else if (mType == FontType.Dynamic) { #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else NGUIEditorTools.DrawSeparator(); Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font; if (fnt != mFont.dynamicFont) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFont = fnt; } GUILayout.BeginHorizontal(); int size = EditorGUILayout.IntField("Size", mFont.dynamicFontSize, GUILayout.Width(120f)); FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (size != mFont.dynamicFontSize) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFontSize = size; } if (style != mFont.dynamicFontStyle) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFontStyle = style; } Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } #endif } else { NGUIEditorTools.DrawSeparator(); ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } EditorGUILayout.Space(); } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } } // For updating the font's data when importing from an external source, such as the texture packer bool resetWidthHeight = false; if (mFont.atlas != null || mFont.material != null) { TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont); BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes); mFont.MarkAsDirty(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } if (mFont.bmFont.isValid) { Color green = new Color(0.4f, 1f, 0f, 1f); Texture2D tex = mFont.texture; if (tex != null) { if (mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle GUI.backgroundColor = green; pixels = EditorGUILayout.RectField("Pixel Rect", pixels); GUI.backgroundColor = Color.white; // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { Rect corrected = NGUIMath.MakePixelPerfect(pixels); if (corrected == pixels) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { pixels = corrected; GUI.changed = true; } } GUILayout.EndHorizontal(); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont); mFont.uvRect = uvRect; } //NGUIEditorTools.DrawSeparator(); EditorGUILayout.Space(); } } } } // The font must be valid at this point for the rest of the options to show up if (mFont.isDynamic || mFont.bmFont.isValid) { // Font spacing GUILayout.BeginHorizontal(); { EditorGUIUtility.LookLikeControls(0f); GUILayout.Label("Spacing", GUILayout.Width(60f)); GUILayout.Label("X", GUILayout.Width(12f)); int x = EditorGUILayout.IntField(mFont.horizontalSpacing); GUILayout.Label("Y", GUILayout.Width(12f)); int y = EditorGUILayout.IntField(mFont.verticalSpacing); GUILayout.Space(18f); EditorGUIUtility.LookLikeControls(80f); if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y) { NGUIEditorTools.RegisterUndo("Font Spacing", mFont); mFont.horizontalSpacing = x; mFont.verticalSpacing = y; } } GUILayout.EndHorizontal(); if (mFont.atlas == null) { mView = View.Font; mUseShader = false; float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f)); if (pixelSize != mFont.pixelSize) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.pixelSize = pixelSize; } } EditorGUILayout.Space(); } // Preview option if (!mFont.isDynamic && mFont.atlas != null) { GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Preview", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)); } GUILayout.EndHorizontal(); } // Dynamic fonts don't support emoticons if (!mFont.isDynamic && mFont.bmFont.isValid) { if (mFont.atlas != null) { NGUIEditorTools.DrawHeader("Symbols and Emoticons"); List <BMSymbol> symbols = mFont.symbols; for (int i = 0; i < symbols.Count;) { BMSymbol sym = symbols[i]; GUILayout.BeginHorizontal(); GUILayout.Label(sym.sequence, GUILayout.Width(40f)); if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite)) { mSelectedSymbol = sym; } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (mFont.atlas != null) { EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName); NGUIEditorTools.Select(mFont.atlas.gameObject); } } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove symbol", mFont); mSymbolSequence = sym.sequence; mSymbolSprite = sym.spriteName; symbols.Remove(sym); mFont.MarkAsDirty(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); ++i; } if (symbols.Count > 0) { NGUIEditorTools.DrawSeparator(); } GUILayout.BeginHorizontal(); mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f)); NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite); bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add symbol", mFont); mFont.AddSymbol(mSymbolSequence, mSymbolSprite); mFont.MarkAsDirty(); mSymbolSequence = ""; mSymbolSprite = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (symbols.Count == 0) { EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { #pragma warning disable 0618 EditorGUIUtility.LookLikeControls(80f); #pragma warning restore 0618 mAtlas = target as UIAtlas; NGUIEditorTools.DrawSeparator(); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement as UIAtlas; } AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); if (mType != after) { if (after == AtlasType.Normal) { OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement as UIAtlas, OnSelectAtlas); NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can have one atlas simply point to\n" + "another one. This is useful if you want to be\n" + "able to quickly replace the contents of one\n" + "atlas with another one, for example for\n" + "swapping an SD atlas with an HD one, or\n" + "replacing an English atlas with a Chinese\n" + "one. All the sprites referencing this atlas\n" + "will update their references to the new one."); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mAtlas); } return; } if (!mConfirmDelete) { NGUIEditorTools.DrawSeparator(); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false); } mAtlas.MarkAsDirty(); mConfirmDelete = false; } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (mSprite != null) { mSprite = mAtlas.GetSprite(mSprite.name); } mAtlas.MarkAsDirty(); } UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates); if (coords != mAtlas.coordinates) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.coordinates = coords; mConfirmDelete = false; } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; mConfirmDelete = false; } } } if (mAtlas.spriteMaterial != null) { Color blue = new Color(0f, 0.7f, 1f, 1f); Color green = new Color(0.4f, 1f, 0f, 1f); if (mConfirmDelete) { if (mSprite != null) { // Show the confirmation dialog NGUIEditorTools.DrawSeparator(); GUILayout.Label("Are you sure you want to delete '" + mSprite.name + "'?"); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); { GUI.backgroundColor = Color.green; if (GUILayout.Button("Cancel")) { mConfirmDelete = false; } GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete")) { NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas); mAtlas.spriteList.Remove(mSprite); mConfirmDelete = false; } GUI.backgroundColor = Color.white; } GUILayout.EndHorizontal(); } else { mConfirmDelete = false; } } else { if (mSprite == null && mAtlas.spriteList.Count > 0) { string spriteName = EditorPrefs.GetString("NGUI Selected Sprite"); if (!string.IsNullOrEmpty(spriteName)) { mSprite = mAtlas.GetSprite(spriteName); } if (mSprite == null) { mSprite = mAtlas.spriteList[0]; } } GUI.backgroundColor = Color.green; GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Add/Delete"); if (GUILayout.Button("New Sprite")) { NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas); UIAtlas.Sprite newSprite = new UIAtlas.Sprite(); if (mSprite != null) { newSprite.name = "Copy of " + mSprite.name; newSprite.outer = mSprite.outer; newSprite.inner = mSprite.inner; } else { newSprite.name = "New Sprite"; } mAtlas.spriteList.Add(newSprite); mSprite = newSprite; } // Show the delete button GUI.backgroundColor = Color.red; if (mSprite != null && GUILayout.Button("Delete", GUILayout.Width(55f))) { mConfirmDelete = true; } GUI.backgroundColor = Color.white; } GUILayout.EndHorizontal(); if (!mConfirmDelete && mSprite != null) { NGUIEditorTools.DrawSeparator(); string spriteName = UISpriteInspector.SpriteField(mAtlas, mSprite.name); if (spriteName != mSprite.name) { mSprite = mAtlas.GetSprite(spriteName); EditorPrefs.SetString("NGUI Selected Sprite", spriteName); } if (mSprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { Rect inner = mSprite.inner; Rect outer = mSprite.outer; string name = EditorGUILayout.TextField("Edit Name", mSprite.name); if (mSprite.name != name && !string.IsNullOrEmpty(name)) { bool found = false; foreach (UIAtlas.Sprite sp in mAtlas.spriteList) { if (sp.name == name) { found = true; break; } } if (!found) { NGUIEditorTools.RegisterUndo("Edit Sprite Name", mAtlas); mSprite.name = name; } } if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { GUI.backgroundColor = green; outer = NGUIEditorTools.IntRect("Dimensions", mSprite.outer); Vector4 border = new Vector4( mSprite.inner.xMin - mSprite.outer.xMin, mSprite.inner.yMin - mSprite.outer.yMin, mSprite.outer.xMax - mSprite.inner.xMax, mSprite.outer.yMax - mSprite.inner.yMax); GUI.backgroundColor = blue; border = NGUIEditorTools.IntPadding("Border", border); GUI.backgroundColor = Color.white; inner.xMin = mSprite.outer.xMin + border.x; inner.yMin = mSprite.outer.yMin + border.y; inner.xMax = mSprite.outer.xMax - border.z; inner.yMax = mSprite.outer.yMax - border.w; } else { // Draw the inner and outer rectangle dimensions GUI.backgroundColor = green; outer = EditorGUILayout.RectField("Outer Rect", mSprite.outer); GUI.backgroundColor = blue; inner = EditorGUILayout.RectField("Inner Rect", mSprite.inner); GUI.backgroundColor = Color.white; } if (outer.xMax < outer.xMin) { outer.xMax = outer.xMin; } if (outer.yMax < outer.yMin) { outer.yMax = outer.yMin; } if (outer != mSprite.outer) { float x = outer.xMin - mSprite.outer.xMin; float y = outer.yMin - mSprite.outer.yMin; inner.x += x; inner.y += y; } // Sanity checks to ensure that the inner rect is always inside the outer inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax); inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax); inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax); inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax); EditorGUILayout.Separator(); // Padding is mainly meant to be used by the 'trimmed' feature of TexturePacker if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { int left = Mathf.RoundToInt(mSprite.paddingLeft * mSprite.outer.width); int right = Mathf.RoundToInt(mSprite.paddingRight * mSprite.outer.width); int top = Mathf.RoundToInt(mSprite.paddingTop * mSprite.outer.height); int bottom = Mathf.RoundToInt(mSprite.paddingBottom * mSprite.outer.height); NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top); NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom); if (a.x != left || a.y != top || b.x != right || b.y != bottom) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mSprite.paddingLeft = a.x / mSprite.outer.width; mSprite.paddingTop = a.y / mSprite.outer.width; mSprite.paddingRight = b.x / mSprite.outer.height; mSprite.paddingBottom = b.y / mSprite.outer.height; MarkSpriteAsDirty(); } } else { // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { GUILayout.Label("Correction", GUILayout.Width(75f)); Rect corrected0 = outer; Rect corrected1 = inner; if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { corrected0 = NGUIMath.MakePixelPerfect(corrected0); corrected1 = NGUIMath.MakePixelPerfect(corrected1); } else { corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height); corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height); } if (corrected0 == mSprite.outer && corrected1 == mSprite.inner) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { outer = corrected0; inner = corrected1; GUI.changed = true; } } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Show", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); if (mUseShader != EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f))) { mUseShader = !mUseShader; if (mUseShader && mView == View.Sprite) { // TODO: Remove this when Unity fixes the bug with DrawPreviewTexture not being affected by BeginGroup Debug.LogWarning("There is a bug in Unity that prevents the texture from getting clipped properly.\n" + "Until it's fixed by Unity, your texture may spill onto the rest of the Unity's GUI while using this mode."); } } } GUILayout.EndHorizontal(); if (mSprite.outer != outer || mSprite.inner != inner) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mSprite.outer = outer; mSprite.inner = inner; mConfirmDelete = false; MarkSpriteAsDirty(); } Rect uv0 = outer; Rect uv1 = inner; if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { uv0 = NGUIMath.ConvertToTexCoords(uv0, tex.width, tex.height); uv1 = NGUIMath.ConvertToTexCoords(uv1, tex.width, tex.height); } // Draw the atlas EditorGUILayout.Separator(); Material m = mUseShader ? mAtlas.spriteMaterial : null; Rect rect = (mView == View.Atlas) ? NGUIEditorTools.DrawAtlas(tex, m) : NGUIEditorTools.DrawSprite(tex, uv0, m); // Draw the sprite outline NGUIEditorTools.DrawOutline(rect, uv0, uv1); EditorGUILayout.Separator(); } } } } }
override public void OnInspectorGUI() { mFont = target as UIFont; EditorGUIUtility.LookLikeControls(80f); NGUIEditorTools.DrawSeparator(); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement; } FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); if (mType != after) { if (after == FontType.Normal) { OnSelectFont(null); } else { mType = FontType.Reference; } } if (mType == FontType.Reference) { ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont); NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can have one font simply point to\n" + "another one. This is useful if you want to be\n" + "able to quickly replace the contents of one\n" + "font with another one, for example for\n" + "swapping an SD font with an HD one, or\n" + "replacing an English font with a Chinese\n" + "one. All the labels referencing this font\n" + "will update their references to the new one."); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mFont); } return; } NGUIEditorTools.DrawSeparator(); ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } } if (mFont.bmFont.isValid) { Color green = new Color(0.4f, 1f, 0f, 1f); Texture2D tex = mFont.texture; if (tex != null) { if (mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Font sprite rectangle GUI.backgroundColor = green; pixels = EditorGUILayout.RectField("Pixel Rect", pixels); GUI.backgroundColor = Color.white; // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { GUILayout.Label("Correction", GUILayout.Width(75f)); Rect corrected = NGUIMath.MakePixelPerfect(pixels); if (corrected == pixels) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { pixels = corrected; GUI.changed = true; } } GUILayout.EndHorizontal(); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont); mFont.uvRect = uvRect; } } // Font spacing GUILayout.BeginHorizontal(); { EditorGUIUtility.LookLikeControls(0f); GUILayout.Label("Spacing", GUILayout.Width(60f)); GUILayout.Label("X", GUILayout.Width(12f)); int x = EditorGUILayout.IntField(mFont.horizontalSpacing); GUILayout.Label("Y", GUILayout.Width(12f)); int y = EditorGUILayout.IntField(mFont.verticalSpacing); GUILayout.Space(62f); EditorGUIUtility.LookLikeControls(80f); if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y) { NGUIEditorTools.RegisterUndo("Font Spacing", mFont); mFont.horizontalSpacing = x; mFont.verticalSpacing = y; } } GUILayout.EndHorizontal(); if (mFont.atlas == null) { mView = View.Font; mUseShader = false; float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f)); if (pixelSize != mFont.pixelSize) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.pixelSize = pixelSize; } } else { GUILayout.Space(4f); GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Preview", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)); } GUILayout.EndHorizontal(); } } if (mFont.atlas != null) { NGUIEditorTools.DrawHeader("Symbols and Emoticons"); List <BMSymbol> symbols = mFont.symbols; for (int i = 0; i < symbols.Count;) { BMSymbol sym = symbols[i]; GUILayout.BeginHorizontal(); GUILayout.Label(sym.sequence, GUILayout.Width(40f)); if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite)) { mSelectedSymbol = sym; } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (mFont.atlas != null) { EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName); NGUIEditorTools.Select(mFont.atlas.gameObject); } } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove symbol", mFont); mSymbolSequence = sym.sequence; mSymbolSprite = sym.spriteName; symbols.Remove(sym); mFont.MarkAsDirty(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); ++i; } if (symbols.Count > 0) { NGUIEditorTools.DrawSeparator(); } GUILayout.BeginHorizontal(); mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f)); NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite); bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add symbol", mFont); mFont.AddSymbol(mSymbolSequence, mSymbolSprite); mFont.MarkAsDirty(); mSymbolSequence = ""; mSymbolSprite = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (symbols.Count == 0) { EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } } } }
protected override bool DrawProperties() { mLabel = mWidget as UILabel; ComponentSelector.Draw <UIFont>(mLabel.font, OnSelectFont); if (mLabel.font != null) { GUI.skin.textArea.wordWrap = true; string text = string.IsNullOrEmpty(mLabel.text) ? "" : mLabel.text; text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f)); if (!text.Equals(mLabel.text)) { RegisterUndo(); mLabel.text = text; } UILabel.Overflow ov = (UILabel.Overflow)EditorGUILayout.EnumPopup("Overflow", mLabel.overflowMethod); if (ov != mLabel.overflowMethod) { RegisterUndo(); mLabel.overflowMethod = ov; } // Only input fields need this setting exposed, and they have their own "is password" setting, so hiding it here. //GUILayout.BeginHorizontal(); //bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(100f)); //GUILayout.Label("- hide characters"); //GUILayout.EndHorizontal(); //if (password != mLabel.password) { RegisterUndo(); mLabel.password = password; } GUILayout.BeginHorizontal(); bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f)); GUILayout.Label("use emoticons and colors"); GUILayout.EndHorizontal(); if (encoding != mLabel.supportEncoding) { RegisterUndo(); mLabel.supportEncoding = encoding; } //GUILayout.EndHorizontal(); if (encoding && mLabel.font.hasSymbols) { UIFont.SymbolStyle sym = (UIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f)); if (sym != mLabel.symbolStyle) { RegisterUndo(); mLabel.symbolStyle = sym; } } GUILayout.BeginHorizontal(); bool useTableDic = EditorGUILayout.Toggle("UseTableDic", mLabel.useDicTable, GUILayout.Width(100f)); if (useTableDic) { GUILayout.Label("curDicID :" + mLabel.curDicID); } GUILayout.EndHorizontal(); mLabel.useDicTable = useTableDic; GUILayout.BeginHorizontal(); { UILabel.Effect effect = (UILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f)); if (effect != mLabel.effectStyle) { RegisterUndo(); mLabel.effectStyle = effect; } if (effect != UILabel.Effect.None) { Color c = EditorGUILayout.ColorField(mLabel.effectColor); if (mLabel.effectColor != c) { RegisterUndo(); mLabel.effectColor = c; } } } GUILayout.EndHorizontal(); if (mLabel.effectStyle != UILabel.Effect.None) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 GUILayout.Label("Distance", GUILayout.Width(70f)); GUILayout.Space(-34f); GUILayout.BeginHorizontal(); GUILayout.Space(70f); Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance); GUILayout.Space(20f); GUILayout.EndHorizontal(); #else Vector2 offset = mLabel.effectDistance; GUILayout.BeginHorizontal(); GUILayout.Label("Distance", GUILayout.Width(76f)); offset.x = EditorGUILayout.FloatField(offset.x); offset.y = EditorGUILayout.FloatField(offset.y); GUILayout.Space(18f); GUILayout.EndHorizontal(); #endif if (offset != mLabel.effectDistance) { RegisterUndo(); mLabel.effectDistance = offset; } } int count = EditorGUILayout.IntField("Max Lines", mLabel.maxLineCount, GUILayout.Width(100f)); if (count != mLabel.maxLineCount) { RegisterUndo(); mLabel.maxLineCount = count; } return(true); } EditorGUILayout.Space(); return(false); }
/// <summary> /// Draw the UI for this tool. /// </summary> void OnGUI() { string prefabPath = ""; string matPath = ""; if (NGUISettings.font != null && NGUISettings.font.name == NGUISettings.fontName) { prefabPath = AssetDatabase.GetAssetPath(NGUISettings.font.gameObject.GetInstanceID()); if (NGUISettings.font.material != null) { matPath = AssetDatabase.GetAssetPath(NGUISettings.font.material.GetInstanceID()); } } // Assume default values if needed if (string.IsNullOrEmpty(NGUISettings.fontName)) { NGUISettings.fontName = "New Font"; } if (string.IsNullOrEmpty(prefabPath)) { prefabPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".prefab"; } if (string.IsNullOrEmpty(matPath)) { matPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".mat"; } EditorGUIUtility.LookLikeControls(80f); NGUIEditorTools.DrawHeader("Input"); NGUISettings.fontData = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(TextAsset), false) as TextAsset; NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false) as Texture2D; // Draw the atlas selection only if we have the font data and texture specified, just to make it easier if (NGUISettings.fontData != null && NGUISettings.fontTexture != null) { NGUIEditorTools.DrawHeader("Output"); GUILayout.BeginHorizontal(); GUILayout.Label("Font Name", GUILayout.Width(76f)); GUI.backgroundColor = Color.white; NGUISettings.fontName = GUILayout.TextField(NGUISettings.fontName); GUILayout.EndHorizontal(); ComponentSelector.Draw <UIFont>("...or select", NGUISettings.font, OnSelectFont); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas); } NGUIEditorTools.DrawSeparator(); // Helpful info if (NGUISettings.fontData == null) { GUILayout.Label( "The font creation mostly takes place outside\n" + "of Unity. You can use BMFont on Windows\n" + "or your choice of Glyph Designer or the\n" + "less expensive bmGlyph on the Mac.\n\n" + "Either of those tools will create a TXT for\n" + "you that you will drag & drop into the\n" + "field above."); } else if (NGUISettings.fontTexture == null) { GUILayout.Label( "When exporting your font, you should get\n" + "two files: the TXT, and the texture. Only\n" + "one texture can be used per font."); } else if (NGUISettings.atlas == null) { GUILayout.Label( "You can create a font that doesn't use a\n" + "texture atlas. This will mean that the text\n" + "labels using this font will generate an extra\n" + "draw call, and will need to be sorted by\n" + "adjusting the Z instead of the Depth.\n\n" + "If you do specify an atlas, the font's texture\n" + "will be added to it automatically."); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.backgroundColor = Color.red; bool create = GUILayout.Button("Create a Font without an Atlas", GUILayout.Width(200f)); GUI.backgroundColor = Color.white; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (create) { GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " + NGUISettings.fontName + " font with the currently selected values? This action can't be undone.", "Yes", "No")) { // Try to load the material 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(); // Load the material so it's usable mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; } mat.mainTexture = NGUISettings.fontTexture; if (go == null || go.GetComponent <UIFont>() == null) { // Create a new prefab for the atlas #if UNITY_3_4 Object prefab = EditorUtility.CreateEmptyPrefab(prefabPath); #else Object prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); #endif // Create a new game object for the font go = new GameObject(NGUISettings.fontName); NGUISettings.font = go.AddComponent <UIFont>(); NGUISettings.font.material = mat; BMFontReader.Load(NGUISettings.font.bmFont, NGUITools.GetHierarchy(NGUISettings.font.gameObject), NGUISettings.fontData.bytes); // Update the prefab #if UNITY_3_4 EditorUtility.ReplacePrefab(go, prefab); #else PrefabUtility.ReplacePrefab(go, prefab); #endif DestroyImmediate(go); AssetDatabase.Refresh(); // Select the atlas go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; } NGUISettings.font = go.GetComponent <UIFont>(); MarkAsChanged(); } } } else { GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; bool create = false; GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (go != null) { if (go.GetComponent <UIFont>() != null) { GUI.backgroundColor = Color.red; create = GUILayout.Button("Replace the Font", GUILayout.Width(140f)); } else { GUI.backgroundColor = Color.grey; GUILayout.Button("Rename Your Font", GUILayout.Width(140f)); } } else { GUI.backgroundColor = Color.green; create = GUILayout.Button("Create the Font", GUILayout.Width(140f)); } GUI.backgroundColor = Color.white; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (create) { if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " + NGUISettings.fontName + " font with the currently selected values? This action can't be undone.", "Yes", "No")) { UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, NGUISettings.fontTexture); if (go == null || go.GetComponent <UIFont>() == null) { // Create a new prefab for the atlas #if UNITY_3_4 Object prefab = EditorUtility.CreateEmptyPrefab(prefabPath); #else Object prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); #endif // Create a new game object for the font go = new GameObject(NGUISettings.fontName); NGUISettings.font = go.AddComponent <UIFont>(); NGUISettings.font.atlas = NGUISettings.atlas; NGUISettings.font.spriteName = NGUISettings.fontTexture.name; BMFontReader.Load(NGUISettings.font.bmFont, NGUITools.GetHierarchy(NGUISettings.font.gameObject), NGUISettings.fontData.bytes); // Update the prefab #if UNITY_3_4 EditorUtility.ReplacePrefab(go, prefab); #else PrefabUtility.ReplacePrefab(go, prefab); #endif DestroyImmediate(go); AssetDatabase.Refresh(); // Select the atlas go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; } else if (NGUISettings.fontData != null) { BMFontReader.Load(NGUISettings.font.bmFont, NGUITools.GetHierarchy(NGUISettings.font.gameObject), NGUISettings.fontData.bytes); NGUISettings.font.MarkAsDirty(); } NGUISettings.font = go.GetComponent <UIFont>(); NGUISettings.font.spriteName = NGUISettings.fontTexture.name; NGUISettings.font.atlas = NGUISettings.atlas; MarkAsChanged(); } } } }
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(); }
private static byte InterpolateComponent(SColor endPoint1, SColor endPoint2, double lambda, ComponentSelector selector) { return (byte)(selector(endPoint1.ToSFMLColor()) + (selector(endPoint2.ToSFMLColor()) - selector(endPoint1.ToSFMLColor())) * lambda); }
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)); NGUIEditorTools.DrawProperty("SpaceY", serializedObject, "mSpacingY", GUILayout.Width(110f)); // add by xuzheng } EditorGUI.EndDisabledGroup(); return(isValid); }
override protected bool DrawProperties() { mLabel = mWidget as UILabel; ComponentSelector.Draw <UIFont>(mLabel.font, OnSelectFont); if (mLabel.font == null) { return(false); } GUI.skin.textArea.wordWrap = true; string text = string.IsNullOrEmpty(mLabel.text) ? "" : mLabel.text; text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f)); if (!text.Equals(mLabel.text)) { RegisterUndo(); mLabel.text = text; } EditorGUILayout.LabelField("*Language Id代替text序列化"); EditorGUILayout.LabelField("*固定内容直接把中文表id填到Language Id"); GUILayout.BeginHorizontal(); int languageId = EditorGUILayout.IntField("Language Id", mLabel.LanguageId, GUILayout.Width(220f)); if (languageId != mLabel.LanguageId) { SystemSwitch.ReleaseMode = false; SystemSwitch.UseHmf = false; UILabel.GetContent = Mogo.GameData.LanguageData.GetContent; RegisterUndo(); mLabel.LanguageId = languageId; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { int len = EditorGUILayout.IntField("Line Width", mLabel.lineWidth, GUILayout.Width(120f)); if (len != mLabel.lineWidth) { RegisterUndo(); mLabel.lineWidth = len; } int count = EditorGUILayout.IntField("Line Count", mLabel.maxLineCount, GUILayout.Width(120f)); if (count != mLabel.maxLineCount) { RegisterUndo(); mLabel.maxLineCount = count; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { int len = EditorGUILayout.IntField("Spacing X", mLabel.spacingX, GUILayout.Width(120f)); if (len != mLabel.spacingX) { RegisterUndo(); mLabel.spacingX = len; } int count = EditorGUILayout.IntField("Spacing Y", mLabel.spacingY, GUILayout.Width(120f)); if (count != mLabel.spacingY) { RegisterUndo(); mLabel.spacingY = count; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(120f)); if (password != mLabel.password) { RegisterUndo(); mLabel.password = password; } bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f)); if (encoding != mLabel.supportEncoding) { RegisterUndo(); mLabel.supportEncoding = encoding; } bool tranlateReturn = EditorGUILayout.Toggle("TranslateReturn", mLabel.TranslateReturn, GUILayout.Width(120f)); if (tranlateReturn != mLabel.TranslateReturn) { RegisterUndo(); mLabel.TranslateReturn = tranlateReturn; } GUILayout.EndHorizontal(); if (encoding && mLabel.font.hasSymbols) { UIFont.SymbolStyle sym = (UIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f)); if (sym != mLabel.symbolStyle) { RegisterUndo(); mLabel.symbolStyle = sym; } } GUILayout.BeginHorizontal(); { UILabel.Effect effect = (UILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f)); if (effect != mLabel.effectStyle) { RegisterUndo(); mLabel.effectStyle = effect; } if (effect != UILabel.Effect.None) { Color c = EditorGUILayout.ColorField(mLabel.effectColor); if (mLabel.effectColor != c) { RegisterUndo(); mLabel.effectColor = c; } } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (mLabel.effectStyle != UILabel.Effect.None) { GUILayout.BeginHorizontal(); GUILayout.Label("Distance", GUILayout.Width(70f)); Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance); GUILayout.Space(20f); if (offset != mLabel.effectDistance) { RegisterUndo(); mLabel.effectDistance = offset; } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { int len = EditorGUILayout.IntField("TextChangeWidth", mLabel.ChangeTextWidth, GUILayout.Width(120f)); if (len != mLabel.ChangeTextWidth) { RegisterUndo(); mLabel.ChangeTextWidth = len; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("一秒变样式", GUILayout.Width(75f)); //if (GUILayout.Button("36标题", GUILayout.Width(50f))) // ExportScenesManager.SetUIHeadText(mLabel.gameObject); //if (GUILayout.Button("30标题", GUILayout.Width(50f))) // ExportScenesManager.SetUI30TitleText(mLabel.gameObject); //if (GUILayout.Button("28标题", GUILayout.Width(50f))) // ExportScenesManager.SetUI28TitleText(mLabel.gameObject); //GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //GUILayout.Label("", GUILayout.Width(75f)); //if (GUILayout.Button("26标题", GUILayout.Width(50f))) // ExportScenesManager.SetUI26TitleText(mLabel.gameObject); //if (GUILayout.Button("通用", GUILayout.Width(50f))) // ExportScenesManager.SetUICommonText(mLabel.gameObject); //if (GUILayout.Button("A标签", GUILayout.Width(50f))) // ExportScenesManager.SetUIAHorizontalUpButtonText(mLabel.gameObject); //GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //GUILayout.Label("", GUILayout.Width(75f)); //if (GUILayout.Button("绿色", GUILayout.Width(60f))) // ExportScenesManager.SetUIGreenText(mLabel.gameObject); //if (GUILayout.Button("红色", GUILayout.Width(60f))) // ExportScenesManager.SetUIRedText(mLabel.gameObject); //if (GUILayout.Button("icon", GUILayout.Width(60f))) // ExportScenesManager.SetUIIconNumText(mLabel.gameObject); //GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //GUILayout.Label("", GUILayout.Width(75f)); //if (GUILayout.Button("底纹按钮", GUILayout.Width(60f))) // ExportScenesManager.SetUINormalButtonText(mLabel.gameObject); //if (GUILayout.Button("主右上", GUILayout.Width(60f))) // ExportScenesManager.SetUIMainRightUpText(mLabel.gameObject); //if (GUILayout.Button("主右", GUILayout.Width(60f))) // ExportScenesManager.SetUIMainRightText(mLabel.gameObject); //GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //GUILayout.Label("", GUILayout.Width(75f)); //if (GUILayout.Button("底纹按钮", GUILayout.Width(60f))) // ExportScenesManager.SetUINormalButtonText(mLabel.gameObject); //if (GUILayout.Button("双字加空格", GUILayout.Width(75f))) //{ // RegisterUndo(); // mLabel.ChangeTextWidth = 100; // mLabel.text = mLabel.text; //} GUILayout.EndHorizontal(); return(true); }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(80f); mAtlas = target as NGUIAtlas; NGUIEditorTools.DrawSeparator(); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); if (mType != after) { if (after == AtlasType.Normal) { OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <NGUIAtlas>(mAtlas.replacement, OnSelectAtlas); NGUIEditorTools.DrawSeparator(); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mAtlas); } return; } if (!mConfirmDelete) { NGUIEditorTools.DrawSeparator(); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false); } mAtlas.MarkAsDirty(); mConfirmDelete = false; } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (mSprite != null) { mSprite = mAtlas.GetSprite(mSprite.name); } mAtlas.MarkAsDirty(); } NGUIAtlas.Coordinates coords = (NGUIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates); if (coords != mAtlas.coordinates) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.coordinates = coords; mConfirmDelete = false; } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; mConfirmDelete = false; } } } if (mAtlas.spriteMaterial != null) { Color blue = new Color(0f, 0.7f, 1f, 1f); Color green = new Color(0.4f, 1f, 0f, 1f); if (mConfirmDelete) { if (mSprite != null) { // Show the confirmation dialog NGUIEditorTools.DrawSeparator(); GUILayout.Label("Are you sure you want to delete '" + mSprite.name + "'?"); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); { GUI.backgroundColor = Color.green; if (GUILayout.Button("Cancel")) { mConfirmDelete = false; } GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete")) { NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas); mAtlas.spriteList.Remove(mSprite); mConfirmDelete = false; } GUI.backgroundColor = Color.white; } GUILayout.EndHorizontal(); } else { mConfirmDelete = false; } } else { if (mSprite == null && mAtlas.spriteList.Count > 0) { string spriteName = EditorPrefs.GetString("NGUI Selected Sprite"); if (!string.IsNullOrEmpty(spriteName)) { mSprite = mAtlas.GetSprite(spriteName); } if (mSprite == null) { mSprite = mAtlas.spriteList[0]; } } if (!mConfirmDelete && mSprite != null) { NGUIEditorTools.DrawSeparator(); NGUIEditorTools.AdvancedSpriteField(mAtlas, mSprite.name, SelectSprite, true); if (mSprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { Rect inner = mSprite.inner; Rect outer = mSprite.outer; if (mAtlas.coordinates == NGUIAtlas.Coordinates.Pixels) { GUI.backgroundColor = green; outer = NGUIEditorTools.IntRect("Dimensions", mSprite.outer); Vector4 border = new Vector4( mSprite.inner.xMin - mSprite.outer.xMin, mSprite.inner.yMin - mSprite.outer.yMin, mSprite.outer.xMax - mSprite.inner.xMax, mSprite.outer.yMax - mSprite.inner.yMax); GUI.backgroundColor = blue; border = NGUIEditorTools.IntPadding("Border", border); GUI.backgroundColor = Color.white; inner.xMin = mSprite.outer.xMin + border.x; inner.yMin = mSprite.outer.yMin + border.y; inner.xMax = mSprite.outer.xMax - border.z; inner.yMax = mSprite.outer.yMax - border.w; } else { // Draw the inner and outer rectangle dimensions GUI.backgroundColor = green; outer = EditorGUILayout.RectField("Outer Rect", mSprite.outer); GUI.backgroundColor = blue; inner = EditorGUILayout.RectField("Inner Rect", mSprite.inner); GUI.backgroundColor = Color.white; } if (outer.xMax < outer.xMin) { outer.xMax = outer.xMin; } if (outer.yMax < outer.yMin) { outer.yMax = outer.yMin; } if (outer != mSprite.outer) { float x = outer.xMin - mSprite.outer.xMin; float y = outer.yMin - mSprite.outer.yMin; inner.x += x; inner.y += y; } // Sanity checks to ensure that the inner rect is always inside the outer inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax); inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax); inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax); inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax); bool changed = false; if (mSprite.inner != inner || mSprite.outer != outer) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mSprite.inner = inner; mSprite.outer = outer; MarkSpriteAsDirty(); changed = true; } EditorGUILayout.Separator(); if (mAtlas.coordinates == NGUIAtlas.Coordinates.Pixels) { int left = Mathf.RoundToInt(mSprite.paddingLeft * mSprite.outer.width); int right = Mathf.RoundToInt(mSprite.paddingRight * mSprite.outer.width); int top = Mathf.RoundToInt(mSprite.paddingTop * mSprite.outer.height); int bottom = Mathf.RoundToInt(mSprite.paddingBottom * mSprite.outer.height); NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top); NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom); if (changed || a.x != left || a.y != top || b.x != right || b.y != bottom) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mSprite.paddingLeft = a.x / mSprite.outer.width; mSprite.paddingTop = a.y / mSprite.outer.height; mSprite.paddingRight = b.x / mSprite.outer.width; mSprite.paddingBottom = b.y / mSprite.outer.height; MarkSpriteAsDirty(); } } else { // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { GUILayout.Label("Correction", GUILayout.Width(75f)); Rect corrected0 = outer; Rect corrected1 = inner; if (mAtlas.coordinates == NGUIAtlas.Coordinates.Pixels) { corrected0 = NGUIMath.MakePixelPerfect(corrected0); corrected1 = NGUIMath.MakePixelPerfect(corrected1); } else { corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height); corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height); } if (corrected0 == mSprite.outer && corrected1 == mSprite.inner) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { outer = corrected0; inner = corrected1; GUI.changed = true; } } GUILayout.EndHorizontal(); } } // This functionality is no longer used. It became obsolete when the Atlas Maker was added. /*NGUIEditorTools.DrawSeparator(); * * GUILayout.BeginHorizontal(); * { * EditorGUILayout.PrefixLabel("Add/Delete"); * * if (GUILayout.Button("Clone Sprite")) * { * NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas); * NGUIAtlas.Sprite newSprite = new NGUIAtlas.Sprite(); * * if (mSprite != null) * { * newSprite.name = "Copy of " + mSprite.name; * newSprite.outer = mSprite.outer; * newSprite.inner = mSprite.inner; * } * else * { * newSprite.name = "New Sprite"; * } * * mAtlas.spriteList.Add(newSprite); * mSprite = newSprite; * } * * // Show the delete button * GUI.backgroundColor = Color.red; * * if (mSprite != null && GUILayout.Button("Delete", GUILayout.Width(55f))) * { * mConfirmDelete = true; * } * GUI.backgroundColor = Color.white; * } * GUILayout.EndHorizontal();*/ if (NGUIEditorTools.previousSelection != null) { NGUIEditorTools.DrawSeparator(); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } } }
/// <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(); GUILayout.BeginHorizontal(); mType = (FontType)EditorGUILayout.EnumPopup("Type", mType, GUILayout.MinWidth(200f)); GUILayout.Space(18f); 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(); 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); GUILayout.Space(18f); } } 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, "Assets", (Application.platform == RuntimePlatform.WindowsEditor) ? "dll" : "dylib"); if (!string.IsNullOrEmpty(path)) { if (System.IO.Path.GetFileName(path) == filename) { NGUISettings.pathToFreeType = path; } else { LogSystem.LogWarning("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 = string.Empty; 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(ResolutionConstrain.Instance.width - 100f)); } else { GUILayout.Label(text, GUI.skin.textArea, GUILayout.Height(80f), GUILayout.Width(ResolutionConstrain.Instance.width - 100f)); } if (GUI.changed) { string final = string.Empty; 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 = string.Empty; } 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(); 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 string prefabPath = EditorUtility.SaveFilePanelInProject("Save As", "New Font.prefab", "prefab", "Save font as..."); if (string.IsNullOrEmpty(prefabPath)) { return; } // 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", string.Empty); 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; }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsDirty(); } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsDirty(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } } if (mAtlas.spriteMaterial != null) { Color blue = new Color(0f, 0.7f, 1f, 1f); Color green = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.AdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = green; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blue; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(80f); mList = target as UIPopupList; ComponentSelector.Draw <UIAtlas>(mList.atlas, OnSelectAtlas); ComponentSelector.Draw <UIFont>(mList.font, OnSelectFont); GUILayout.BeginHorizontal(); UILabel lbl = EditorGUILayout.ObjectField("Text Label", mList.textLabel, typeof(UILabel), true) as UILabel; if (mList.textLabel != lbl) { RegisterUndo(); mList.textLabel = lbl; if (lbl != null) { lbl.text = mList.selection; } } GUILayout.Space(44f); GUILayout.EndHorizontal(); if (mList.atlas != null) { NGUIEditorTools.SpriteField("Background", mList.atlas, mList.backgroundSprite, OnBackground); NGUIEditorTools.SpriteField("Highlight", mList.atlas, mList.highlightSprite, OnHighlight); GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUILayout.Label("Options"); GUILayout.EndHorizontal(); string text = ""; foreach (string s in mList.items) { text += s + "\n"; } GUILayout.Space(-14f); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string modified = EditorGUILayout.TextArea(text, GUILayout.Height(100f)); GUILayout.EndHorizontal(); if (modified != text) { RegisterUndo(); string[] split = modified.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries); mList.items.Clear(); foreach (string s in split) { mList.items.Add(s); } if (string.IsNullOrEmpty(mList.selection) || !mList.items.Contains(mList.selection)) { mList.selection = mList.items.Count > 0 ? mList.items[0] : ""; } } string sel = NGUIEditorTools.DrawList("Selection", mList.items.ToArray(), mList.selection); if (mList.selection != sel) { RegisterUndo(); mList.selection = sel; } UIPopupList.Position pos = (UIPopupList.Position)EditorGUILayout.EnumPopup("Position", mList.position); if (mList.position != pos) { RegisterUndo(); mList.position = pos; } float ts = EditorGUILayout.FloatField("Text Scale", mList.textScale); Color tc = EditorGUILayout.ColorField("Text Color", mList.textColor); Color bc = EditorGUILayout.ColorField("Background", mList.backgroundColor); Color hc = EditorGUILayout.ColorField("Highlight", mList.highlightColor); GUILayout.BeginHorizontal(); bool isLocalized = EditorGUILayout.Toggle("Localized", mList.isLocalized, GUILayout.Width(100f)); bool isAnimated = EditorGUILayout.Toggle("Animated", mList.isAnimated); GUILayout.EndHorizontal(); if (mList.textScale != ts || mList.textColor != tc || mList.highlightColor != hc || mList.backgroundColor != bc || mList.isLocalized != isLocalized || mList.isAnimated != isAnimated) { RegisterUndo(); mList.textScale = ts; mList.textColor = tc; mList.backgroundColor = bc; mList.highlightColor = hc; mList.isLocalized = isLocalized; mList.isAnimated = isAnimated; } NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUILayout.Label("Padding", GUILayout.Width(76f)); GUILayout.BeginVertical(); GUILayout.Space(-12f); Vector2 padding = EditorGUILayout.Vector2Field("", mList.padding); GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (mList.padding != padding) { RegisterUndo(); mList.padding = padding; } EditorGUIUtility.LookLikeControls(100f); GameObject go = EditorGUILayout.ObjectField("Event Receiver", mList.eventReceiver, typeof(GameObject), true) as GameObject; string fn = EditorGUILayout.TextField("Function Name", mList.functionName); if (mList.eventReceiver != go || mList.functionName != fn) { RegisterUndo(); mList.eventReceiver = go; mList.functionName = fn; } } }
/// <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); } } }
private void OnGUI() { GUILayout.Space(10F); if (!m_atlas) { m_atlas = NGUISettings.atlas; } ComponentSelector.Draw <UIAtlas>("Atlas", m_atlas, obj => { if (m_atlas != obj) { m_atlas = obj as UIAtlas; } }, true, GUILayout.MinWidth(80f)); if (m_atlas != null) { GUILayout.BeginHorizontal(); GUILayout.Space(10f); if (GUILayout.Button("Search")) { m_spriteNames.Clear(); Object[] uiSprites = Selection.GetFiltered(typeof(UISprite), SelectionMode.Deep); Object[] uiLabels = Selection.GetFiltered(typeof(UILabel), SelectionMode.Deep); foreach (UISpriteData spriteData in m_atlas.spriteList) { bool found = false; foreach (UISprite uiSprite in uiSprites) { if (uiSprite.atlas == m_atlas && string.Equals(uiSprite.spriteName, spriteData.name)) { found = true; break; } } if (!found) { foreach (UILabel uiLabel in uiLabels) { if (uiLabel.bitmapFont) { foreach (BMSymbol symbol in uiLabel.bitmapFont.symbols) { if (string.Equals(symbol.spriteName, spriteData.name)) { found = true; break; } } if (found) { break; } } } } if (!found) { m_spriteNames.Add(spriteData.name); } } } GUILayout.Space(10f); GUILayout.EndHorizontal(); GUILayout.Space(10f); GUILayout.BeginHorizontal(); GUILayout.Space(5F); EditorGUILayout.BeginVertical(); if (NGUIEditorTools.DrawMinimalisticHeader("Sprites")) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(15f); EditorGUILayout.BeginVertical(); mScroll = EditorGUILayout.BeginScrollView(mScroll); GUILayout.Space(2f); int oldLength = m_spriteNames.Count; int newLength = EditorGUILayout.IntField("Size", oldLength); if (newLength != oldLength) { int minLength = Mathf.Min(newLength, oldLength); string[] sprites = new string[newLength]; for (int i = 0; i < minLength; i++) { sprites[i] = m_spriteNames[i]; } m_spriteNames = new List <string>(sprites); } for (int i = 0; i < newLength; i++) { int index = i; NGUIEditorTools.DrawAdvancedSpriteField(m_atlas, m_spriteNames[index], spriteName => { m_spriteNames[index] = spriteName; Repaint(); }, false); } GUILayout.Space(2f); GUILayout.EndScrollView(); EditorGUILayout.EndVertical(); GUILayout.Space(3f); EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(10f); } }
private void OnGUI() { if (!mAtlas) { mAtlas = NGUISettings.atlas; } ComponentSelector.Draw <UIAtlas>("Atlas", mAtlas, obj => { if (mAtlas != obj) { mAtlas = obj as UIAtlas; } }, true, GUILayout.MinWidth(80f)); if (!mAtlas) { mSprites = new string[0]; } else { GUILayout.BeginHorizontal(); GUILayout.Space(5F); EditorGUILayout.BeginVertical(); if (NGUIEditorTools.DrawMinimalisticHeader("Sprites")) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(15F); EditorGUILayout.BeginVertical(); GUILayout.Space(2F); int newLength = EditorGUILayout.IntField("Size", mSprites.Length); int oldLength = mSprites.Length; if (newLength != oldLength) { int minLength = Mathf.Min(newLength, oldLength); string[] sprites = new string[newLength]; for (int i = 0; i < minLength; i++) { sprites[i] = mSprites[i]; } mSprites = sprites; } for (int i = 0; i < mSprites.Length; i++) { int index = i; NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, mSprites[index], spriteName => { mSprites[index] = spriteName; Repaint(); }, false); } GUILayout.Space(2F); EditorGUILayout.EndVertical(); GUILayout.Space(3F); EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(10F); } GUILayout.BeginHorizontal(); GUILayout.Space(10F); bool start = GUILayout.Button("Create/Update Materials"); GUILayout.Space(10F); GUILayout.EndHorizontal(); if (start && mAtlas && mSprites.Length > 0) { string atlasPath = AssetDatabase.GetAssetPath(mAtlas); string dirPath = atlasPath.Replace("/UIAtlas/", "/Materials/").Replace(".prefab", "/"); DirectoryInfo dir = new DirectoryInfo(dirPath); if (!dir.Exists) { dir.Create(); } bool anyAssetsChanged = false; UISpriteData[] spriteDatas = new UISpriteData[mSprites.Length]; for (int index = 0; index < mSprites.Length; index++) { string spriteName = mSprites[index]; if (!string.IsNullOrEmpty(spriteName)) { UISpriteData spriteData = mAtlas.GetSprite(spriteName); if (spriteData != null) { string path = dirPath + spriteName + ".mat"; bool exist = File.Exists(path); Material mat = exist ? AssetDatabase.LoadAssetAtPath <Material>(path) : new Material(mAtlas.spriteMaterial); float scaleX = (float)spriteData.width / mAtlas.width; float scaleY = (float)spriteData.height / mAtlas.height; float offsetX = (float)spriteData.x / mAtlas.width; float offsetY = (float)(mAtlas.height - spriteData.y - spriteData.height) / mAtlas.height; mat.SetTextureScale("_MainTex", new Vector2(scaleX, scaleY)); mat.SetTextureOffset("_MainTex", new Vector2(offsetX, offsetY)); if (exist) { anyAssetsChanged = true; } else { AssetDatabase.CreateAsset(mat, path); } } } } if (anyAssetsChanged) { AssetDatabase.SaveAssets(); } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; NGUITools.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsChanged(); } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsChanged(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } if (NGUIEditorTools.DrawHeader("Scale Factor")) { NGUIEditorTools.BeginContents(); { EditorGUILayout.HelpBox( "If the image size(pixel size in photoshop) is not equal to texture size(pixel size in unity), you should set the scale factor to help NGUI to adjust uv.", MessageType.Info, true ); EditorGUILayout.HelpBox( "You should click the the button below to recalculate scale factor for atlas when the atlas' texture is changed. For example, when you add sprite, remove sprite, set compressed format or change maxsize etc.", MessageType.Warning, true ); if (GUILayout.Button("Calculate Scale Factor Automatically")) { if (mAtlas.texture != null) { string path = AssetDatabase.GetAssetPath(mAtlas.texture); string fullPath = Application.dataPath + path.Substring("Assets".Length); if (File.Exists(fullPath)) { MemoryStream memoryStream = null; BinaryReader binaryReader = null; try { byte[] bytes = File.ReadAllBytes(fullPath); memoryStream = new MemoryStream(bytes); binaryReader = new BinaryReader(memoryStream); // Is PNG if (binaryReader.ReadByte() == 0x89 && binaryReader.ReadByte() == 0x50 && binaryReader.ReadByte() == 0x4E && binaryReader.ReadByte() == 0x47 && binaryReader.ReadByte() == 0x0D && binaryReader.ReadByte() == 0x0A && binaryReader.ReadByte() == 0x1A && binaryReader.ReadByte() == 0x0A) { binaryReader.ReadUInt32(); binaryReader.ReadUInt32(); uint width = LittleEndianToBigEndian(binaryReader.ReadUInt32()); uint height = LittleEndianToBigEndian(binaryReader.ReadUInt32()); TextureImporter textureImporter = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(mAtlas.texture)); System.Action <string, UIAtlas.SCALE_PLATFORM, BuildTarget> processScale = delegate(string platformName, UIAtlas.SCALE_PLATFORM platformAtlasEnum, BuildTarget platformEnum) { if (mAtlas.scales == null || mAtlas.scales.Length != (int)UIAtlas.SCALE_PLATFORM.SIZE * 2) { mAtlas.scales = new float[(int)UIAtlas.SCALE_PLATFORM.SIZE * 2] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; } // TextureImportInstructions info = new TextureImportInstructions(); // textureImporter.ReadTextureImportInstructions(info, platformEnum); int maxSize; TextureImporterFormat format; if (textureImporter.GetPlatformTextureSettings(platformName, out maxSize, out format)) { float len = width > height ? width : height; mAtlas.scales[(int)platformAtlasEnum * 2] = len / (float)width; mAtlas.scales[(int)platformAtlasEnum * 2 + 1] = len / (float)height; } else { mAtlas.scales[(int)platformAtlasEnum * 2] = 1; mAtlas.scales[(int)platformAtlasEnum * 2 + 1] = 1; } }; processScale("Web", UIAtlas.SCALE_PLATFORM.WEB, BuildTarget.WebPlayer); processScale("Standalone", UIAtlas.SCALE_PLATFORM.STANDALONE, BuildTarget.StandaloneWindows); processScale("iPhone", UIAtlas.SCALE_PLATFORM.IPHONE, BuildTarget.iOS); processScale("Android", UIAtlas.SCALE_PLATFORM.ANDROID, BuildTarget.Android); NGUITools.SetDirty(mAtlas); } } catch (System.Exception exception) { Debug.LogError(exception.StackTrace); UnityEditor.EditorUtility.DisplayDialog("Error", "Error:Set the scale factor mamually.", "ok"); } finally { if (memoryStream != null) { memoryStream.Close(); memoryStream.Dispose(); memoryStream = null; } if (binaryReader != null) { binaryReader.Close(); binaryReader = null; } } } else { UnityEditor.EditorUtility.DisplayDialog("Alert", "File is not exists\n" + fullPath, "ok"); } } else { UnityEditor.EditorUtility.DisplayDialog("Alert", "Null Texture", "ok"); } } } NGUIEditorTools.EndContents(); } } if (mAtlas.spriteMaterial != null) { Color blueColor = new Color(0f, 0.7f, 1f, 1f); Color greenColor = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } GUILayout.Space(3f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Duplicate")) { UIAtlasMaker.SpriteEntry se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); if (se != null) { NGUISettings.selectedSprite = se.name; } } if (GUILayout.Button("Save As...")) { string path = EditorUtility.SaveFilePanelInProject("Save As", sprite.name + ".png", "png", "Extract sprite into which file?"); if (!string.IsNullOrEmpty(path)) { UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name); if (se != null) { byte[] bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); if (GUILayout.Button("Add a Shadow")) { AddShadow(sprite); } if (GUILayout.Button("Add a Soft Outline")) { AddOutline(sprite); } if (GUILayout.Button("Add a Transparent Border")) { AddTransparentBorder(sprite); } if (GUILayout.Button("Add a Clamped Border")) { AddClampedBorder(sprite); } if (GUILayout.Button("Add a Tiled Border")) { AddTiledBorder(sprite); } EditorGUI.BeginDisabledGroup(!sprite.hasBorder); if (GUILayout.Button("Crop Border")) { CropBorder(sprite); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
/// <summary> /// Draw the UI for this tool. /// </summary> void OnGUI() { string prefabPath = ""; string matPath = ""; if (NGUISettings.font != null && NGUISettings.font.name == NGUISettings.fontName) { prefabPath = AssetDatabase.GetAssetPath(NGUISettings.font.gameObject.GetInstanceID()); if (NGUISettings.font.material != null) { matPath = AssetDatabase.GetAssetPath(NGUISettings.font.material.GetInstanceID()); } } // Assume default values if needed if (string.IsNullOrEmpty(NGUISettings.fontName)) { NGUISettings.fontName = "New Font"; } if (string.IsNullOrEmpty(prefabPath)) { prefabPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".prefab"; } if (string.IsNullOrEmpty(matPath)) { matPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".mat"; } NGUIEditorTools.SetLabelWidth(80f); NGUIEditorTools.DrawHeader("Input", true); NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); mType = (FontType)EditorGUILayout.EnumPopup("Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); int create = 0; if (mType == FontType.Dynamic) { NGUISettings.dynamicFont = EditorGUILayout.ObjectField("Font TTF", NGUISettings.dynamicFont, typeof(Font), false) as Font; GUILayout.BeginHorizontal(); NGUISettings.dynamicFontSize = EditorGUILayout.IntField("Font Size", NGUISettings.dynamicFontSize, GUILayout.Width(120f)); NGUISettings.dynamicFontStyle = (FontStyle)EditorGUILayout.EnumPopup(NGUISettings.dynamicFontStyle); GUILayout.Space(18f); GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); if (NGUISettings.dynamicFont != null) { NGUIEditorTools.DrawHeader("Output", true); NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); GUILayout.Label("Font Name", GUILayout.Width(76f)); GUI.backgroundColor = Color.white; NGUISettings.fontName = GUILayout.TextField(NGUISettings.fontName); #if !UNITY_3_5 if (NGUISettings.dynamicFont != null) { GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (go != null) { if (go.GetComponent <UIFont>() != null) { GUI.backgroundColor = Color.red; if (GUILayout.Button("Replace", GUILayout.Width(70f))) { create = 1; } } else { GUI.backgroundColor = Color.grey; GUILayout.Button("Rename", GUILayout.Width(70f)); } } else { GUI.backgroundColor = Color.green; if (GUILayout.Button("Create", GUILayout.Width(70f))) { create = 1; } } GUI.backgroundColor = Color.white; } #endif GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else // Helpful info if (NGUISettings.dynamicFont == null) { EditorGUILayout.HelpBox("Dynamic font creation happens right in Unity. Simply specify the TrueType font to be used as source.", 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 { NGUISettings.fontData = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(TextAsset), false) as TextAsset; NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false) as Texture2D; NGUIEditorTools.EndContents(); // Draw the atlas selection only if we have the font data and texture specified, just to make it easier if (NGUISettings.fontData != null && NGUISettings.fontTexture != null) { NGUIEditorTools.DrawHeader("Output", true); NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); GUILayout.Label("Font Name", GUILayout.Width(76f)); GUI.backgroundColor = Color.white; NGUISettings.fontName = GUILayout.TextField(NGUISettings.fontName); GUILayout.EndHorizontal(); ComponentSelector.Draw <UIFont>("Select", NGUISettings.font, OnSelectFont); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas); NGUIEditorTools.EndContents(); } // Helpful info if (NGUISettings.fontData == null) { EditorGUILayout.HelpBox("The bitmap font creation mostly takes place outside of Unity. You can 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 TXT, 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, and will need to be sorted by " + "adjusting the Z instead of the Depth.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.backgroundColor = Color.red; if (GUILayout.Button("Create a Font without an Atlas", GUILayout.Width(200f))) { create = 2; } GUI.backgroundColor = Color.white; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (go != null) { if (go.GetComponent <UIFont>() != null) { GUI.backgroundColor = Color.red; if (GUILayout.Button("Replace the Font", GUILayout.Width(140f))) { create = 3; } } else { GUI.backgroundColor = Color.grey; GUILayout.Button("Rename Your Font", GUILayout.Width(140f)); } } else { GUI.backgroundColor = Color.green; if (GUILayout.Button("Create the Font", GUILayout.Width(140f))) { create = 3; } } GUI.backgroundColor = Color.white; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } } if (create != 0) { GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " + NGUISettings.fontName + " font with the currently selected values? This action can't be undone.", "Yes", "No")) { // Try to load the material Material mat = null; // Non-atlased font if (create == 2) { 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(); // Load the material so it's usable mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; } mat.mainTexture = NGUISettings.fontTexture; } else if (create != 1) { UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, NGUISettings.fontTexture); } // Font doesn't exist yet if (go == null || go.GetComponent <UIFont>() == null) { // Create a new prefab for the atlas Object prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); // Create a new game object for the font go = new GameObject(NGUISettings.fontName); NGUISettings.font = go.AddComponent <UIFont>(); CreateFont(NGUISettings.font, create, mat); // Update the prefab PrefabUtility.ReplacePrefab(go, prefab); DestroyImmediate(go); AssetDatabase.Refresh(); // Select the atlas go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; NGUISettings.font = go.GetComponent <UIFont>(); } else { NGUISettings.font = go.GetComponent <UIFont>(); CreateFont(NGUISettings.font, create, mat); } MarkAsChanged(); } } }
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); } } #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)); GUILayout.Space(18f); 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)); GUILayout.Space(18f); 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); } }
static byte InterpolateComponent( System.Windows.Media.Color endPoint1, System.Windows.Media.Color endPoint2, double lambda, ComponentSelector selector) { return (byte)(selector(endPoint1) + (selector(endPoint2) - selector(endPoint1)) * lambda); }
public void Register(ComponentSelector selector, TokenType type) { selectors[type] = selector; }
static byte InterpolateComponent(Color endPoint1_, Color endPoint2_, double lambda_, ComponentSelector selector) { return (byte)(selector(endPoint1_) + (selector(endPoint2_) - selector(endPoint1_)) * lambda_); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { // Load the saved preferences if (!mLoaded) { mLoaded = true; Load(); } RebasedEditorGUIUtility.LookLikeControls(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, GUILayout.Width(140f)); GUILayout.Label("Texture atlas used by widgets", GUILayout.MinWidth(10000f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); ComponentSelector.Draw <UIFont>(NGUISettings.font, OnSelectFont, GUILayout.Width(140f)); GUILayout.Label("Font used by labels", GUILayout.MinWidth(10000f)); GUILayout.EndHorizontal(); GUILayout.Space(-2f); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); WidgetType wt = (WidgetType)EditorGUILayout.EnumPopup("Template", mType, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Select a widget template to use"); GUILayout.EndHorizontal(); if (mType != wt) { mType = wt; Save(); } switch (mType) { 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.Checkbox: CreateCheckbox(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; } } }
static byte InterpolateComponent( System.Windows.Media.Color endPoint1, System.Windows.Media.Color endPoint2, double lambda, ComponentSelector selector) { // redComponent(endPoint1) + lambda*difference between endPoints return (byte)(selector(endPoint1) + (selector(endPoint2) - selector(endPoint1)) * lambda); }
/// <summary> /// Draw the UI for this tool. /// </summary> void OnGUI() { bool create = false; bool update = false; bool replace = false; string prefabPath = ""; string matPath = ""; // If we have an atlas to work with, see if we can figure out the path for it and its material if (UISettings.atlas != null && UISettings.atlas.name == UISettings.atlasName) { prefabPath = AssetDatabase.GetAssetPath(UISettings.atlas.gameObject.GetInstanceID()); if (UISettings.atlas.spriteMaterial != null) { matPath = AssetDatabase.GetAssetPath(UISettings.atlas.spriteMaterial.GetInstanceID()); } } // Assume default values if needed if (string.IsNullOrEmpty(UISettings.atlasName)) { UISettings.atlasName = "New Atlas"; } if (string.IsNullOrEmpty(prefabPath)) { prefabPath = NGUIEditorTools.GetSelectionFolder() + UISettings.atlasName + ".prefab"; } if (string.IsNullOrEmpty(matPath)) { matPath = NGUIEditorTools.GetSelectionFolder() + UISettings.atlasName + ".mat"; } // Try to load the prefab GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (UISettings.atlas == null && go != null) { UISettings.atlas = go.GetComponent <UIAtlas>(); } EditorGUIUtility.LookLikeControls(80f); GUILayout.Space(6f); GUILayout.BeginHorizontal(); if (go == null) { GUI.backgroundColor = Color.green; create = GUILayout.Button("Create", GUILayout.Width(76f)); } else { GUI.backgroundColor = Color.red; create = GUILayout.Button("Replace", GUILayout.Width(76f)); } GUI.backgroundColor = Color.white; UISettings.atlasName = GUILayout.TextField(UISettings.atlasName); GUILayout.EndHorizontal(); if (create) { // If the prefab already exists, confirm that we want to overwrite it if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " + UISettings.atlasName + " atlas with the textures currently selected in the Project View? All other sprites will be deleted.", "Yes", "No")) { replace = true; // Try to load the material 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(); // Load the material so it's usable mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; } if (UISettings.atlas == null || UISettings.atlas.name != UISettings.atlasName) { // Create a new prefab for the atlas #if UNITY_3_4 Object prefab = (go != null) ? go : EditorUtility.CreateEmptyPrefab(prefabPath); #else Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(prefabPath); #endif // Create a new game object for the atlas go = new GameObject(UISettings.atlasName); go.AddComponent <UIAtlas>().spriteMaterial = mat; // Update the prefab #if UNITY_3_4 EditorUtility.ReplacePrefab(go, prefab); #else PrefabUtility.ReplacePrefab(go, prefab); #endif DestroyImmediate(go); AssetDatabase.Refresh(); // Select the atlas go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; UISettings.atlas = go.GetComponent <UIAtlas>(); } } } ComponentSelector.Draw <UIAtlas>("...or select", UISettings.atlas, OnSelectAtlas); List <Texture> textures = GetSelectedTextures(); if (UISettings.atlas != null && UISettings.atlas.name == UISettings.atlasName) { Material mat = UISettings.atlas.spriteMaterial; Texture tex = UISettings.atlas.texture; // Material information GUILayout.BeginHorizontal(); { if (mat != null) { if (GUILayout.Button("Material", GUILayout.Width(76f))) { Selection.activeObject = mat; } GUILayout.Label(" " + mat.name); } else { GUI.color = Color.grey; GUILayout.Button("Material", GUILayout.Width(76f)); GUI.color = Color.white; GUILayout.Label(" N/A"); } } GUILayout.EndHorizontal(); // Texture atlas information GUILayout.BeginHorizontal(); { if (tex != null) { if (GUILayout.Button("Texture", GUILayout.Width(76f))) { Selection.activeObject = tex; } GUILayout.Label(" " + tex.width + "x" + tex.height); } else { GUI.color = Color.grey; GUILayout.Button("Texture", GUILayout.Width(76f)); GUI.color = Color.white; GUILayout.Label(" N/A"); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); UISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", UISettings.atlasPadding, GUILayout.Width(100f)), 0, 8); GUILayout.Label("in pixels in-between of sprites"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); UISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", UISettings.atlasTrimming, GUILayout.Width(100f)); GUILayout.Label("Remove empty space"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); UISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", UISettings.unityPacking, GUILayout.MinWidth(100f)); GUILayout.Label("if off, use a custom packer"); GUILayout.EndHorizontal(); if (textures.Count > 0) { GUI.backgroundColor = Color.green; update = GUILayout.Button("Add/Update All"); GUI.backgroundColor = Color.white; } else { NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can reveal more options by selecting\none or more textures in the Project View\nwindow."); } } else { NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can create a new atlas by selecting\none or more textures in the Project View\nwindow, then clicking \"Create\"."); } Dictionary <string, int> spriteList = GetSpriteList(textures); if (spriteList.Count > 0) { NGUIEditorTools.DrawHeader("Sprites"); GUILayout.Space(-7f); mScroll = GUILayout.BeginScrollView(mScroll); string delSprite = null; int index = 0; foreach (KeyValuePair <string, int> iter in spriteList) { ++index; NGUIEditorTools.HighlightLine(new Color(0.6f, 0.6f, 0.6f)); GUILayout.BeginHorizontal(); GUILayout.Label(index.ToString(), GUILayout.Width(24f)); GUILayout.Label(iter.Key); if (iter.Value == 2) { GUI.color = Color.green; GUILayout.Label("Add", GUILayout.Width(27f)); GUI.color = Color.white; } else if (iter.Value == 1) { GUI.color = Color.cyan; GUILayout.Label("Update", GUILayout.Width(45f)); GUI.color = Color.white; } else { if (string.IsNullOrEmpty(mDelName) || mDelName != iter.Key) { // If we have not yet selected a sprite for deletion, show a small "X" button if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelName = iter.Key; } } else { GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete", GUILayout.Width(60f))) { // Confirmation button clicked on -- delete this sprite delSprite = iter.Key; mDelName = null; } GUI.backgroundColor = Color.white; } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); // If this sprite was marked for deletion, remove it from the atlas if (!string.IsNullOrEmpty(delSprite)) { List <UIAtlas.Sprite> list = UISettings.atlas.spriteList; foreach (UIAtlas.Sprite sp in list) { if (sp.name == delSprite) { list.Remove(sp); List <SpriteEntry> sprites = new List <SpriteEntry>(); ExtractSprites(UISettings.atlas, sprites); UpdateAtlas(UISettings.atlas, sprites); mDelName = null; return; } } } else if (update) { UpdateAtlas(textures, true); } else if (replace) { UpdateAtlas(textures, false); } return; } }