/// <summary> /// Draw the inspector widget. /// </summary> protected override bool ShouldDrawProperties() { float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f); if (alpha != mPanel.alpha) { NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel); mPanel.alpha = alpha; } GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Depth"); int depth = mPanel.depth; if (GUILayout.Button("Back", GUILayout.Width(60f))) { --depth; } depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f)); if (GUILayout.Button("Forward", GUILayout.Width(68f))) { ++depth; } if (mPanel.depth != depth) { NGUIEditorTools.RegisterUndo("Panel Depth", mPanel); mPanel.depth = depth; if (UIPanelTool.instance != null) { UIPanelTool.instance.Repaint(); } if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); int matchingDepths = 0; for (int i = 0, imax = UIPanel.list.Count; i < imax; ++i) { UIPanel p = UIPanel.list[i]; if (p != null && mPanel.depth == p.depth) { ++matchingDepths; } } if (matchingDepths > 1) { EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning); } UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping); if (mPanel.clipping != clipping) { mPanel.clipping = clipping; EditorUtility.SetDirty(mPanel); } if (mPanel.clipping != UIDrawCall.Clipping.None) { Vector4 range = mPanel.baseClipRegion; // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null); GUI.changed = false; GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipOffset = off; EditorUtility.SetDirty(mPanel); } //EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (size.x < 0f) { size.x = 0f; } if (size.y < 0f) { size.y = 0f; } range.x = pos.x; range.y = pos.y; range.z = size.x; range.w = size.y; if (mPanel.baseClipRegion != range) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.baseClipRegion = range; EditorUtility.SetDirty(mPanel); } if (mPanel.clipping == UIDrawCall.Clipping.SoftClip) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (soft.x < 0f) { soft.x = 0f; } if (soft.y < 0f) { soft.y = 0f; } if (mPanel.clipSoftness != soft) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipSoftness = soft; EditorUtility.SetDirty(mPanel); } } } if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale)) { EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error); if (GUILayout.Button("Auto-fix")) { NGUIEditorTools.FixUniform(mPanel.gameObject); } } if (NGUIEditorTools.DrawHeader("Advanced Options")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue); if (mPanel.renderQueue != rq) { mPanel.renderQueue = rq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } if (rq != UIPanel.RenderQueue.Automatic) { int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f)); if (mPanel.startingRenderQueue != sq) { mPanel.startingRenderQueue = sq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); GUI.changed = false; int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f)); if (GUI.changed) { mPanel.sortingOrder = so; } GUILayout.BeginHorizontal(); bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f)); GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.generateNormals != norms) { mPanel.generateNormals = norms; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f)); GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.cullWhileDragging != cull) { mPanel.cullWhileDragging = cull; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f)); GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.alwaysOnScreen != alw) { mPanel.alwaysOnScreen = alw; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Padding", serializedObject, "softBorderPadding", GUILayout.Width(100f)); GUILayout.Label("Soft border pads content", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset, GUILayout.Width(100f)); GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.anchorOffset != off) { mPanel.anchorOffset = off; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f)); GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.widgetsAreStatic != stat) { mPanel.widgetsAreStatic = stat; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } if (stat) { EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning); } GUILayout.BeginHorizontal(); bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f)); GUILayout.Label("Show in panel tool"); GUILayout.EndHorizontal(); if (mPanel.showInPanelTool != tool) { mPanel.showInPanelTool = !mPanel.showInPanelTool; EditorUtility.SetDirty(mPanel); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } NGUIEditorTools.EndContents(); } return(true); }
public override void OnInspectorGUI() { serializedObject.Update(); GUILayout.Space(6f); NGUIEditorTools.SetLabelWidth(80); GUILayout.BeginHorizontal(); // Key not found in the localization file -- draw it as a text field SerializedProperty sp = NGUIEditorTools.DrawProperty("Key", serializedObject, "key"); string myKey = sp.stringValue; bool isPresent = (mKeys != null) && mKeys.Contains(myKey); GUI.color = isPresent ? Color.green : Color.red; GUILayout.BeginVertical(GUILayout.Width(22f)); GUILayout.Space(2f); GUILayout.Label(isPresent? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f)); GUILayout.EndVertical(); GUI.color = Color.white; GUILayout.EndHorizontal(); if (isPresent) { if (NGUIEditorTools.DrawHeader("Preview")) { NGUIEditorTools.BeginContents(); string[] keys = Localization.knownLanguages; string[] values; if (Localization.dictionary.TryGetValue(myKey, out values)) { if (keys.Length != values.Length) { EditorGUILayout.HelpBox("Number of keys doesn't match the number of values! Did you modify the dictionaries by hand at some point?", MessageType.Error); } else { for (int i = 0; i < keys.Length; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label(keys[i], GUILayout.Width(66f)); if (GUILayout.Button(values[i], GUIStyle.none, GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f))) { (target as UILocalize).value = values[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); } } } else { GUILayout.Label("No preview available"); } NGUIEditorTools.EndContents(); } } else if (mKeys != null && !string.IsNullOrEmpty(myKey)) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); GUILayout.BeginVertical(); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f); int matches = 0; for (int i = 0, imax = mKeys.Count; i < imax; ++i) { if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey)) { if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge")) { sp.stringValue = mKeys[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } if (++matches == 8) { GUILayout.Label("...and more"); break; } } } GUI.backgroundColor = Color.white; GUILayout.EndVertical(); GUILayout.Space(22f); GUILayout.EndHorizontal(); } serializedObject.ApplyModifiedProperties(); }
public void DrawAnchorTransform() { if (NGUIEditorTools.DrawHeader("Anchors")) { NGUIEditorTools.BeginContents(); NGUIEditorTools.SetLabelWidth(NGUISettings.minimalisticLook ? 69f : 62f); EditorGUI.BeginDisabledGroup(!((target as UIRect).canBeAnchored)); GUILayout.BeginHorizontal(); var type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); var tg = new SerializedProperty[4]; for (var i = 0; i < 4; ++i) { tg[i] = serializedObject.FindProperty(FieldName[i] + ".target"); } if (mAnchorType == AnchorType.None && type != AnchorType.None) { if (type == AnchorType.Unified) { if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null) { var rect = target as UIRect; var parent = NGUITools.FindInParents <UIRect>(rect.cachedTransform.parent); if (parent != null) { for (var i = 0; i < 4; ++i) { mTarget[i] = parent.cachedTransform; } } } } for (var i = 0; i < 4; ++i) { tg[i].objectReferenceValue = mTarget[i]; mTarget[i] = null; } UpdateAnchors(true); } if (type != AnchorType.None) { NGUIEditorTools.DrawPaddedProperty("Execute", serializedObject, "updateAnchors"); } if (type == AnchorType.Advanced) { DrawAnchor(0, true); DrawAnchor(1, true); DrawAnchor(2, true); DrawAnchor(3, true); } else if (type == AnchorType.Unified) { DrawSingleAnchorSelection(); DrawAnchor(0, false); DrawAnchor(1, false); DrawAnchor(2, false); DrawAnchor(3, false); } else if (type == AnchorType.None && mAnchorType != type) { // Save values to make it easy to "go back" for (var i = 0; i < 4; ++i) { mTarget[i] = tg[i].objectReferenceValue as Transform; tg[i].objectReferenceValue = null; } serializedObject.FindProperty("leftAnchor.relative").floatValue = 0f; serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f; serializedObject.FindProperty("rightAnchor.relative").floatValue = 1f; serializedObject.FindProperty("topAnchor.relative").floatValue = 1f; } mAnchorType = type; OnDrawFinalProperties(); EditorGUI.EndDisabledGroup(); NGUIEditorTools.EndContents(); } }
public void drawOverviewGUI() { NGUIEditorTools.DrawHeader("文件详情"); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label("筛选:"); selectAssetType = EditorGUILayout.Popup(selectAssetType, AssetAllTypes); GUILayout.FlexibleSpace(); if (GUILayout.Button("关闭MipMaps", GUILayout.Width(100F))) { List <TextureBean> _textures = new List <TextureBean>(); for (int i = 0; i < assetList.Count; i++) { if (selectAssetType != 0 && !assetList[i].AssetDesc.Equals(AssetAllTypes[selectAssetType])) { continue; } if (!assetList[i].MipMaps) { continue; } _textures.Add(assetList[i]); } for (int i = 0; i < _textures.Count; i++) { EditorUtility.DisplayProgressBar("Hold On", "正在自动处理...", i / (float)_textures.Count); TextureImporter texImp = AssetImporter.GetAtPath(_textures[i].FilePath) as TextureImporter; texImp.mipmapEnabled = false; _textures[i].MipMaps = false; } EditorUtility.ClearProgressBar(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } if (GUILayout.Button("刷新", GUILayout.Width(80))) { findAllTextures(); } GUILayout.Space(10); } GUILayout.Space(5); GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f)); if (GUILayout.Toggle(false, "名称", "ButtonLeft", GUILayout.MaxWidth(200f))) { sortName *= -1; assetList.Sort((x, y) => x.Name.CompareTo(y.Name) * sortName); } GUILayout.Toggle(false, "资源类型", "ButtonMid", GUILayout.MinWidth(100F)); if (GUILayout.Toggle(false, "宽度", "ButtonMid", GUILayout.MinWidth(80f))) { sortWidth *= -1; assetList.Sort((x, y) => x.Width.CompareTo(y.Width) * sortWidth); } if (GUILayout.Toggle(false, "高度", "ButtonMid", GUILayout.MinWidth(80f))) { sortHeight *= -1; assetList.Sort((x, y) => x.Height.CompareTo(y.Height) * sortHeight); } GUILayout.Toggle(false, "MipMaps", "ButtonMid", GUILayout.MinWidth(100f)); if (GUILayout.Toggle(false, "MaxSize", "ButtonMid", GUILayout.MinWidth(80F))) { sortMaxSize *= -1; assetList.Sort((x, y) => x.MaxSize.CompareTo(y.MaxSize) * sortMaxSize); } GUILayout.Toggle(false, "压缩格式", "ButtonMid", GUILayout.MinWidth(100F)); if (GUILayout.Toggle(false, "内存消耗", "ButtonRight", GUILayout.MinWidth(100F))) { sortMemorySize *= -1; assetList.Sort((x, y) => x.MemorySize.CompareTo(y.MemorySize) * sortMemorySize); } GUILayout.Space(10); GUILayout.EndHorizontal(); scrollPos = GUILayout.BeginScrollView(scrollPos); int index = 0; for (int i = 0; i < assetList.Count; i++) { if (selectAssetType != 0 && !assetList[i].AssetDesc.Equals(AssetAllTypes[selectAssetType])) { continue; } GUI.backgroundColor = index % 2 == 1 ? Color.white : new Color(0.8f, 0.8f, 0.8f); GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f)); GUI.backgroundColor = Color.white; drawRow(index, assetList[i]); GUILayout.EndHorizontal(); index++; } GUILayout.EndScrollView(); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { mScroll = GUILayout.BeginScrollView(mScroll); GameObject tempPanel = null; bool bBegin = false; bool bOpen = false; EAtlasLayers tempLayer = EAtlasLayers.Common_1; ItemDepthConfig tempConfig; for (int i = 0; i < _allItemsConfig.Count; i++) { tempConfig = _allItemsConfig[i]; if ((tempPanel != null && tempPanel != tempConfig.panel) || (tempPanel != null && tempLayer != tempConfig.belongTo)) { if (bBegin) { NGUIEditorTools.EndContents(); } bBegin = false; } if (tempPanel == null || tempPanel != tempConfig.panel) { DrawOnePanelName(tempConfig.panel); } if (tempPanel == null || tempLayer != tempConfig.belongTo) { //DrawOneTitle(tempConfig); string sTitle = GetLayerName(tempConfig.belongTo); string sKey = tempConfig.panel.name + tempConfig.belongTo.ToString(); bOpen = NGUIEditorTools.DrawHeader(sTitle, sKey); if (bOpen) { NGUIEditorTools.BeginContents(); bBegin = true; // GUILayout.BeginHorizontal(); // GUILayout.FlexibleSpace(); // bool bClick = GUILayout.Button("重置选中项depth", "LargeButton", GUILayout.Width(160f), GUILayout.Height(25f)); // if (bClick) // { // int layers = 1 << (int)tempConfig.belongTo; // // count_common1 = 0; // count_common2 = 0; // count_common3 = 0; // count_uiatlas = 0; // EachChildrenDepth(tempConfig.panel, tempConfig.panel, layers, true, true); // SortAllItems(); // } // GUILayout.FlexibleSpace(); // GUILayout.EndHorizontal(); } else { bBegin = false; } } if (bBegin) { DrawOneItem(ref tempConfig); } tempPanel = tempConfig.panel; tempLayer = tempConfig.belongTo; } if (bBegin) { NGUIEditorTools.EndContents(); } GUILayout.EndScrollView(); GUILayout.Space(6f); GUILayout.BeginHorizontal(); GUILayout.Space(6f); bool bSelect = EditorGUILayout.ToggleLeft("选中所有", bSelectAll, GUILayout.Width(60f)); if (bSelectAll != bSelect) { if (bSelect) { SelectAllItem(); } else { UnSelectAllItem(); } bSelectAll = bSelect; } GUILayout.FlexibleSpace(); bool change = GUILayout.Button("自动适配所有选中项", "LargeButton", GUILayout.Width(160f)); if (change) { SetChildrenDepth(); ReadAllChildrenDepth(); } GUILayout.FlexibleSpace(); GUILayout.Space(-90f); bool bClickInstruction = GUILayout.Button("分段说明", "LargeButton", GUILayout.Width(90f)); if (bClickInstruction) { NGUIDepthInstruction.ShowDialog(); } GUILayout.EndHorizontal(); GUILayout.Space(10f); }
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); } } } }
public override void OnInspectorGUI() { serializedObject.Update(); GUILayout.Space(6f); NGUIEditorTools.SetLabelWidth(80f); GUILayout.BeginHorizontal(); // Key not found in the localization file -- draw it as a text field SerializedProperty sp = NGUIEditorTools.DrawProperty("Key", serializedObject, "key"); string myKey = sp.stringValue; bool isPresent = (mKeys != null) && mKeys.Contains(myKey); GUI.color = isPresent ? Color.green : Color.red; GUILayout.BeginVertical(GUILayout.Width(22f)); GUILayout.Space(2f); #if UNITY_3_5 GUILayout.Label(isPresent? "ok" : "!!", GUILayout.Height(20f)); #else GUILayout.Label(isPresent? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f)); #endif GUILayout.EndVertical(); GUI.color = Color.white; GUILayout.EndHorizontal(); if (isPresent) { if (NGUIEditorTools.DrawHeader("Preview")) { NGUIEditorTools.BeginContents(); string[] keys; string[] values; if (Localization.dictionary.TryGetValue("KEY", out keys) && Localization.dictionary.TryGetValue(myKey, out values)) { for (int i = 0; i < keys.Length; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label(keys[i], GUILayout.Width(70f)); if (GUILayout.Button(values[i], "AS TextArea", GUILayout.MinWidth(80f), GUILayout.MaxWidth(ResolutionConstrain.Instance.width - 110f))) { (target as UILocalize).value = values[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); } } else { GUILayout.Label("No preview available"); } NGUIEditorTools.EndContents(); } } else if (mKeys != null && !string.IsNullOrEmpty(myKey)) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); GUILayout.BeginVertical(); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f); int matches = 0; for (int i = 0; i < mKeys.size; ++i) { if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey)) { #if UNITY_3_5 if (GUILayout.Button(mKeys[i] + " \u25B2")) #else if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge")) #endif { sp.stringValue = mKeys[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } if (++matches == 8) { GUILayout.Label("...and more"); break; } } } GUI.backgroundColor = Color.white; GUILayout.EndVertical(); GUILayout.Space(22f); GUILayout.EndHorizontal(); } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Draw the 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"; } RebasedEditorGUIUtility.LookLikeControls(80f); NGUIEditorTools.DrawHeader("Input"); 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(); if (NGUISettings.dynamicFont != 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(); } NGUIEditorTools.DrawSeparator(); #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 they will always be drawn in a separate draw call. You WILL need to adjust transform position's Z rather than depth!", MessageType.Warning); if (NGUISettings.dynamicFont != null) { NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.backgroundColor = Color.green; 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 = 1; } } 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 = 1; } } GUI.backgroundColor = Color.white; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } #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; // 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>("Select", NGUISettings.font, OnSelectFont); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas); } NGUIEditorTools.DrawSeparator(); // 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); NGUIEditorTools.DrawSeparator(); 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(); } } }
protected override void DrawProperties() { SerializedProperty sp = serializedObject.FindProperty("dragHighlight"); Highlight ht = sp.boolValue ? Highlight.Press : Highlight.DoNothing; GUILayout.BeginHorizontal(); bool highlight = (Highlight)EditorGUILayout.EnumPopup("Drag Over", ht) == Highlight.Press; NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (sp.boolValue != highlight) { sp.boolValue = highlight; } DrawTransition(); DrawColors(); UIButton btn = target as UIButton; if (btn.tweenTarget != null) { UISprite sprite = btn.tweenTarget.GetComponent <UISprite>(); UI2DSprite s2d = btn.tweenTarget.GetComponent <UI2DSprite>(); if (sprite != null) { if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true)) { NGUIEditorTools.BeginContents(true); EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects); { SerializedObject obj = new SerializedObject(sprite); obj.Update(); SerializedProperty atlas = obj.FindProperty("mAtlas"); NGUIEditorTools.DrawSpriteField("Normal", obj, atlas, obj.FindProperty("mSpriteName")); obj.ApplyModifiedProperties(); NGUIEditorTools.DrawSpriteField("Hover", serializedObject, atlas, serializedObject.FindProperty("hoverSprite"), true); NGUIEditorTools.DrawSpriteField("Pressed", serializedObject, atlas, serializedObject.FindProperty("pressedSprite"), true); NGUIEditorTools.DrawSpriteField("Disabled", serializedObject, atlas, serializedObject.FindProperty("disabledSprite"), true); } EditorGUI.EndDisabledGroup(); NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap"); NGUIEditorTools.EndContents(); } } else if (s2d != null) { if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true)) { NGUIEditorTools.BeginContents(true); EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects); { SerializedObject obj = new SerializedObject(s2d); obj.Update(); NGUIEditorTools.DrawProperty("Normal", obj, "mSprite"); obj.ApplyModifiedProperties(); NGUIEditorTools.DrawProperty("Hover", serializedObject, "hoverSprite2D"); NGUIEditorTools.DrawProperty("Pressed", serializedObject, "pressedSprite2D"); NGUIEditorTools.DrawProperty("Disabled", serializedObject, "disabledSprite2D"); } EditorGUI.EndDisabledGroup(); NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap"); NGUIEditorTools.EndContents(); } } } UIButton button = target as UIButton; NGUIEditorTools.DrawEvents("On Click", button, button.onClick, false); }
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); } } } }
/// <summary> /// Draw the "Anchors" property block. /// </summary> protected virtual void DrawFinalProperties() { if (NGUIEditorTools.DrawHeader("Anchors")) { NGUIEditorTools.BeginContents(); NGUIEditorTools.SetLabelWidth(62f); GUILayout.BeginHorizontal(); AnchorType type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType); GUILayout.Space(18f); GUILayout.EndHorizontal(); SerializedProperty[] tg = new SerializedProperty[4]; for (int i = 0; i < 4; ++i) { tg[i] = serializedObject.FindProperty(FieldName[i] + ".target"); } if (mAnchorType == AnchorType.None && type != AnchorType.None) { if (type == AnchorType.Unified) { if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null) { UIRect rect = target as UIRect; UIRect parent = NGUITools.FindInParents <UIRect>(rect.cachedTransform.parent); if (parent != null) { for (int i = 0; i < 4; ++i) { mTarget[i] = parent.cachedTransform; } } } } for (int i = 0; i < 4; ++i) { tg[i].objectReferenceValue = mTarget[i]; mTarget[i] = null; } UpdateAnchors(); } if (type == AnchorType.Advanced) { DrawAnchor(0, true); DrawAnchor(1, true); DrawAnchor(2, true); DrawAnchor(3, true); } else if (type == AnchorType.Unified) { DrawSingleAnchorSelection(); DrawAnchor(0, false); DrawAnchor(1, false); DrawAnchor(2, false); DrawAnchor(3, false); } else if (type == AnchorType.None && mAnchorType != type) { // Save values to make it easy to "go back" for (int i = 0; i < 4; ++i) { mTarget[i] = tg[i].objectReferenceValue as Transform; tg[i].objectReferenceValue = null; } serializedObject.FindProperty("leftAnchor.relative").floatValue = 0f; serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f; serializedObject.FindProperty("rightAnchor.relative").floatValue = 1f; serializedObject.FindProperty("topAnchor.relative").floatValue = 1f; } mAnchorType = type; OnDrawFinalProperties(); NGUIEditorTools.EndContents(); } }
/// <summary> /// Draw common widget properties. /// 此方法被重写了 刘洋 2016年66月30日15:12:30 /// </summary> static public void DrawInspectorProperties(SerializedObject so, UIWidget w, bool drawColor) { float brightnessAmount = EditorGUILayout.Slider("亮度", w.brightnessAmount, 0f, 2f); float saturationAmount = EditorGUILayout.Slider("饱和度", w.saturationAmount, 0f, 2f); float contrastAmount = EditorGUILayout.Slider("对比度", w.contrastAmount, 0f, 2f); if (brightnessAmount != w.brightnessAmount) { NGUIEditorTools.RegisterUndo("BrightnessAmount Change", w); w.brightnessAmount = brightnessAmount; } if (saturationAmount != w.saturationAmount) { NGUIEditorTools.RegisterUndo("saturationAmount Change", w); w.saturationAmount = saturationAmount; } if (contrastAmount != w.contrastAmount) { NGUIEditorTools.RegisterUndo("contrastAmount Change", w); w.contrastAmount = contrastAmount; } if (drawColor) { DrawColor(so, w); GUILayout.Space(3f); } PrefabType type = PrefabUtility.GetPrefabType(w.gameObject); if (NGUIEditorTools.DrawHeader("Widget")) { NGUIEditorTools.BeginContents(); if (NGUISettings.minimalisticLook) { NGUIEditorTools.SetLabelWidth(70f); } DrawPivot(so, w); DrawDepth(so, w, type == PrefabType.Prefab); DrawDimensions(so, w, type == PrefabType.Prefab); if (NGUISettings.minimalisticLook) { NGUIEditorTools.SetLabelWidth(70f); } SerializedProperty ratio = so.FindProperty("aspectRatio"); SerializedProperty aspect = so.FindProperty("keepAspectRatio"); GUILayout.BeginHorizontal(); { if (!aspect.hasMultipleDifferentValues && aspect.intValue == 0) { EditorGUI.BeginDisabledGroup(true); NGUIEditorTools.DrawProperty("Aspect", ratio, false, GUILayout.Width(130f)); EditorGUI.EndDisabledGroup(); } else { NGUIEditorTools.DrawProperty("Aspect", ratio, false, GUILayout.Width(130f)); } NGUIEditorTools.DrawProperty("", aspect, false, GUILayout.MinWidth(20f)); } GUILayout.EndHorizontal(); if (so.isEditingMultipleObjects || w.hasBoxCollider) { GUILayout.BeginHorizontal(); { NGUIEditorTools.DrawProperty("Collider", so, "autoResizeBoxCollider", GUILayout.Width(100f)); GUILayout.Label("auto-adjust to match"); } GUILayout.EndHorizontal(); } NGUIEditorTools.EndContents(); } }
/// <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(); } } } }
void DrawFont() { if (NGUIEditorTools.DrawHeader("Font")) { NGUIEditorTools.BeginContents(); SerializedProperty ttf = null; GUILayout.BeginHorizontal(); { if (NGUIEditorTools.DrawPrefixButton("Font")) { if (mType == FontType.Bitmap) { ComponentSelector.Show <UIFont>(OnBitmapFont); } else { ComponentSelector.Show <Font>(OnDynamicFont, new string[] { ".ttf", ".otf" }); } } #if DYNAMIC_FONT GUI.changed = false; mType = (FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f)); if (GUI.changed) { GUI.changed = false; if (mType == FontType.Bitmap) { serializedObject.FindProperty("trueTypeFont").objectReferenceValue = null; } else { serializedObject.FindProperty("bitmapFont").objectReferenceValue = null; } } #else mType = FontType.Bitmap; #endif if (mType == FontType.Bitmap) { NGUIEditorTools.DrawProperty("", serializedObject, "bitmapFont", GUILayout.MinWidth(40f)); } else { ttf = NGUIEditorTools.DrawProperty("", serializedObject, "trueTypeFont", GUILayout.MinWidth(40f)); } } GUILayout.EndHorizontal(); if (ttf != null && ttf.objectReferenceValue != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup(ttf.hasMultipleDifferentValues); NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f)); NGUIEditorTools.DrawProperty("", serializedObject, "fontStyle", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); } else { NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f)); } NGUIEditorTools.DrawProperty("Text Color", serializedObject, "textColor"); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(66f); EditorGUILayout.PrefixLabel("Padding"); NGUIEditorTools.SetLabelWidth(14f); NGUIEditorTools.DrawProperty("X", serializedObject, "padding.x", GUILayout.MinWidth(30f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "padding.y", GUILayout.MinWidth(30f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } }
void DrawNpc() { if (NGUIEditorTools.DrawHeader("NPC配置")) { EditorGUILayout.BeginHorizontal(); { m_iSelectedNpcId = EditorGUILayout.Popup(m_iSelectedNpcId, m_NpcTypeList, GUILayout.Width(100f)); if (GUILayout.Button("添加一个NPC", GUILayout.Width(120f))) { AddNpc(int.Parse(m_NpcTypeList[m_iSelectedNpcId]), Vector3.zero, Vector3.zero, Vector3.one); } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < m_NpcList.Count; ++i) { NpcEditorData data = m_NpcList[i]; GUIStyle textColor = new GUIStyle(); textColor.normal.textColor = data.m_bIsSelected ? Color.red : Color.white; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.TextField("NPCID: " + data.m_NpcData.Id, GUILayout.Width(300f)); if (GUILayout.Button("调整NPC位置", textColor, GUILayout.Width(120f))) { m_nCurrentSettingPosNpcIndex = i; TerrainEditorRuntime.Instance.SetRaycastCallBack(SetNpcPos); } if (GUILayout.Button("NPC高亮", textColor, GUILayout.Width(120f))) { if (null != m_CurrentSelectedNpc) { ((CharTransformData)(m_CurrentSelectedNpc.GetTransformData())).SetSelectedStatus(false); } m_CurrentSelectedNpc = data.m_Instance; ((CharTransformData)(m_CurrentSelectedNpc.GetTransformData())).SetSelectedStatus(true); } if (GUILayout.Button("删除NPC", textColor, GUILayout.Width(120f))) { m_RemovingNpcList.Add(data); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { Vector3 tmpPos = data.m_Instance.GetTransformData().GetPosition(); GUILayout.TextArea("NPC位置", textColor, GUILayout.Width(120f)); GUILayout.Label(tmpPos.ToString(), GUILayout.Width(100f)); GUILayout.Label("x", GUILayout.Width(20f)); tmpPos.x = EditorGUILayout.FloatField(tmpPos.x); GUILayout.Label("y", GUILayout.Width(20f)); tmpPos.y = EditorGUILayout.FloatField(tmpPos.y); GUILayout.Label("z", GUILayout.Width(20f)); tmpPos.z = EditorGUILayout.FloatField(tmpPos.z); if (m_LastTimePos != tmpPos) { data.m_Instance.GetTransformData().SetPosition(tmpPos); data.m_NpcData.Pos.SetVector3(tmpPos); } m_LastTimePos = tmpPos; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { Vector3 tmpRot = data.m_Instance.GetTransformData().GetRotation(); GUILayout.TextArea("NPC朝向", GUILayout.Width(120f)); GUILayout.Label(tmpRot.y.ToString(), GUILayout.Width(100f)); GUILayout.Label("y", GUILayout.Width(20f)); tmpRot.y = EditorGUILayout.Slider(tmpRot.y, 0f, 359.9f); if (data.m_Instance.GetTransformData().GetRotation() != tmpRot) { data.m_Instance.GetTransformData().SetRotation(tmpRot); data.m_NpcData.Rot.SetVector3(tmpRot); } } EditorGUILayout.EndHorizontal(); } CheckRemovingNpc(); } }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { var dcs = UIDrawCall.activeList; dcs.Sort(delegate(UIDrawCall a, UIDrawCall b) { return(a.finalRenderQueue.CompareTo(b.finalRenderQueue)); }); if (dcs.size == 0) { EditorGUILayout.HelpBox("No NGUI draw calls present in the scene", MessageType.Info); return; } UIPanel selectedPanel = NGUITools.FindInParents <UIPanel>(Selection.activeGameObject); if (selectedPanel != null) { if (GUILayout.Button("Auto adjust depth 1")) { AutoAdjustDepth1(selectedPanel); } if (GUILayout.Button("Auto adjust depth 2")) { AutoAdjustDepth2(dcs); } if (GUILayout.Button("Auto adjust depth 3")) { AutoAdjustDepth3(dcs); } if (GUILayout.Button("Auto adjust depth 4")) { AutoAdjustDepth4(selectedPanel); } } GUILayout.Space(12f); NGUIEditorTools.SetLabelWidth(100f); ShowFilter show = (NGUISettings.showAllDCs ? ShowFilter.AllPanels : ShowFilter.SelectedPanel); if ((ShowFilter)EditorGUILayout.EnumPopup("Draw Call Filter", show) != show) { NGUISettings.showAllDCs = !NGUISettings.showAllDCs; } GUILayout.Space(6f); if (selectedPanel == null && !NGUISettings.showAllDCs) { EditorGUILayout.HelpBox("No panel selected", MessageType.Info); return; } NGUIEditorTools.SetLabelWidth(80f); mScroll = GUILayout.BeginScrollView(mScroll); int dcCount = 0; for (int i = 0; i < dcs.size; ++i) { UIDrawCall dc = dcs[i]; string key = "Draw Call " + (i + 1); bool highlight = (selectedPanel == null || selectedPanel == dc.manager); if (!highlight) { if (!NGUISettings.showAllDCs) { continue; } if (UnityEditor.EditorPrefs.GetBool(key, true)) { GUI.color = new Color(0.85f, 0.85f, 0.85f); } else { GUI.contentColor = new Color(0.85f, 0.85f, 0.85f); } } else { GUI.contentColor = Color.white; } ++dcCount; string name = key + " of " + dcs.size; if (!dc.isActive) { name = name + " (HIDDEN)"; } else if (!highlight) { name = name + " (" + dc.manager.name + ")"; } if (NGUIEditorTools.DrawHeader(name, key)) { GUI.color = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f); NGUIEditorTools.BeginContents(); EditorGUILayout.ObjectField("Material", dc.dynamicMaterial, typeof(Material), false); int count = 0; for (int a = 0; a < UIPanel.list.Count; ++a) { UIPanel p = UIPanel.list[a]; for (int b = 0; b < p.widgets.Count; ++b) { UIWidget w = p.widgets[b]; if (w.drawCall == dc) { ++count; } } } string myPath = NGUITools.GetHierarchy(dc.manager.cachedGameObject); string remove = myPath + "\\"; string[] list = new string[count + 1]; list[0] = count.ToString(); count = 0; for (int a = 0; a < UIPanel.list.Count; ++a) { UIPanel p = UIPanel.list[a]; for (int b = 0; b < p.widgets.Count; ++b) { UIWidget w = p.widgets[b]; if (w.drawCall != dc) { continue; } string path = NGUITools.GetHierarchy(w.cachedGameObject); list[++count] = count + ". " + (string.Equals(path, myPath) ? w.name : path.Replace(remove, "")); } } GUILayout.BeginHorizontal(); int sel = EditorGUILayout.Popup("Widgets", 0, list); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (sel != 0) { count = 0; for (int a = 0; a < UIPanel.list.Count; ++a) { UIPanel p = UIPanel.list[a]; for (int b = 0; b < p.widgets.Count; ++b) { UIWidget w = p.widgets[b]; if (w.drawCall == dc && ++count == sel) { Selection.activeGameObject = w.gameObject; break; } } } } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Render Q", dc.finalRenderQueue.ToString(), GUILayout.Width(120f)); bool draw = (Visibility)EditorGUILayout.EnumPopup(dc.isActive ? Visibility.Visible : Visibility.Hidden) == Visibility.Visible; NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (dc.isActive != draw) { dc.isActive = draw; NGUITools.SetDirty(dc.manager); } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Triangles", dc.triangles.ToString(), GUILayout.Width(120f)); if (dc.manager != selectedPanel) { if (GUILayout.Button("Select the Panel")) { Selection.activeGameObject = dc.manager.gameObject; } NGUIEditorTools.DrawPadding(); } GUILayout.EndHorizontal(); if (dc.manager.clipping != UIDrawCall.Clipping.None && !dc.isClipped) { EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.", MessageType.Warning); } NGUIEditorTools.EndContents(); GUI.color = Color.white; } } if (dcCount == 0) { EditorGUILayout.HelpBox("No draw calls found", MessageType.Info); } GUILayout.EndScrollView(); }
void DrawCreatePlayerPos() { GUILayout.Space(5f); if (NGUIEditorTools.DrawHeader("角色出生点配置")) { GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(5f); m_iSelectedPlayerId = EditorGUILayout.Popup(m_iSelectedPlayerId, m_PlayerTypeList, GUILayout.Width(100f)); if (GUILayout.Button("生成角色", GUILayout.Width(100f))) { CreatePlayerCharactor(int.Parse(m_PlayerTypeList[m_iSelectedPlayerId]), Vector3.zero, Vector3.zero); } } EditorGUILayout.EndHorizontal(); if (null != m_PlayerChar) { GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("调整玩家位置", GUILayout.Width(120f))) { TerrainEditorRuntime.Instance.SetRaycastCallBack(SetPlayerPos); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(5f); Vector3 tmpPos = m_PlayerChar.GetTransformData().GetPosition(); EditorGUILayout.LabelField("玩家位置:", GUILayout.Width(80f)); GUILayout.Label("x", GUILayout.Width(20f)); tmpPos.x = EditorGUILayout.FloatField(tmpPos.x); GUILayout.Label("y", GUILayout.Width(20f)); tmpPos.y = EditorGUILayout.FloatField(tmpPos.y); GUILayout.Label("z", GUILayout.Width(20f)); tmpPos.z = EditorGUILayout.FloatField(tmpPos.z); if (m_PlayerChar.GetTransformData().GetPosition() != tmpPos) { m_PlayerChar.GetTransformData().SetPosition(tmpPos); } } EditorGUILayout.EndHorizontal(); GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(5f); Vector3 tmpRot = m_PlayerChar.GetTransformData().GetRotation(); EditorGUILayout.LabelField("玩家朝向:", GUILayout.Width(80f)); GUILayout.Label("y", GUILayout.Width(20f)); tmpRot.y = EditorGUILayout.Slider(tmpRot.y, 0f, 359.9f); if (m_PlayerChar.GetTransformData().GetRotation() != tmpRot) { m_PlayerChar.GetTransformData().SetRotation(tmpRot); } } EditorGUILayout.EndHorizontal(); } } }
void DrawLinkedPartitionList() { CharacterPartitionLink link = target as CharacterPartitionLink; if (NGUIEditorTools.DrawHeader(string.Format("Linked Partition List ({0})", link.LinkedPartitions.Count), "CharacterPartitionLink_Partitions")) { NGUIEditorTools.BeginContents(); { bool delete = false; for (int i = 0; i < link.LinkedPartitions.Count; i++) { if (i > 0) { GUILayout.Space(5); } NGUIEditorTools.BeginContents(); { DrawPartition(i, ref delete); } NGUIEditorTools.EndContents(); if (delete) { link.LinkedPartitions.RemoveAt(i); break; } } if (GUILayout.Button("Add New Partition")) { PartitionInfo newPartition = new PartitionInfo(); int count = 1; string name = string.Format("Partition_{0}", count); while (true) { bool nameExisted = false; foreach (PartitionInfo partition in link.LinkedPartitions) { if (partition.Name == name) { nameExisted = true; break; } } if (nameExisted) { count++; name = string.Format("Partition_{0}", count); } else { break; } } newPartition.Name = name; link.LinkedPartitions.Add(newPartition); } } NGUIEditorTools.EndContents(); } }
/// <summary> /// Draw the inspector widget. /// </summary> protected override bool ShouldDrawProperties() { float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f); if (alpha != mPanel.alpha) { NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel); mPanel.alpha = alpha; } GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Depth"); int depth = mPanel.depth; if (GUILayout.Button("Back", GUILayout.Width(60f))) { --depth; } depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f)); if (GUILayout.Button("Forward", GUILayout.Width(68f))) { ++depth; } if (mPanel.depth != depth) { NGUIEditorTools.RegisterUndo("Panel Depth", mPanel); mPanel.depth = depth; if (UIPanelTool.instance != null) { UIPanelTool.instance.Repaint(); } if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); int matchingDepths = 0; for (int i = 0, imax = UIPanel.list.Count; i < imax; ++i) { UIPanel p = UIPanel.list[i]; if (p != null && mPanel.depth == p.depth) { ++matchingDepths; } } if (matchingDepths > 1) { EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning); } UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping); if (mPanel.clipping != clipping) { mPanel.clipping = clipping; EditorUtility.SetDirty(mPanel); } // Contributed by Benzino07: http://www.tasharen.com/forum/index.php?topic=6956.15 GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Sorting Layer"); // Get the names of the Sorting layers System.Type internalEditorUtilityType = typeof(InternalEditorUtility); PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); string[] names = (string[])sortingLayersProperty.GetValue(null, new object[0]); int index = 0; if (!string.IsNullOrEmpty(mPanel.sortingLayerName)) { for (int i = 0; i < names.Length; i++) { if (mPanel.sortingLayerName == names[i]) { index = i; break; } } } // Get the selected index and update the panel sorting layer if it has changed int selectedIndex = EditorGUILayout.Popup(index, names); if (index != selectedIndex) { mPanel.sortingLayerName = names[selectedIndex]; EditorUtility.SetDirty(mPanel); } } GUILayout.EndHorizontal(); if (mPanel.clipping != UIDrawCall.Clipping.None) { Vector4 range = mPanel.baseClipRegion; // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null); GUI.changed = false; GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipOffset = off; EditorUtility.SetDirty(mPanel); } //EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w), GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (size.x < 0f) { size.x = 0f; } if (size.y < 0f) { size.y = 0f; } range.x = pos.x; range.y = pos.y; range.z = size.x; range.w = size.y; if (mPanel.baseClipRegion != range) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.baseClipRegion = range; EditorUtility.SetDirty(mPanel); } if (mPanel.clipping == UIDrawCall.Clipping.SoftClip) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness, GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (soft.x < 0f) { soft.x = 0f; } if (soft.y < 0f) { soft.y = 0f; } if (mPanel.clipSoftness != soft) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipSoftness = soft; EditorUtility.SetDirty(mPanel); } } else if (mPanel.clipping == UIDrawCall.Clipping.TextureMask) { NGUIEditorTools.SetLabelWidth(0f); GUILayout.Space(-90f); Texture2D tex = (Texture2D)EditorGUILayout.ObjectField(mPanel.clipTexture, typeof(Texture2D), false, GUILayout.Width(70f), GUILayout.Height(70f)); GUILayout.Space(20f); if (mPanel.clipTexture != tex) { NGUIEditorTools.RegisterUndo("Clipping Change", mPanel); mPanel.clipTexture = tex; EditorUtility.SetDirty(mPanel); } NGUIEditorTools.SetLabelWidth(80f); } } if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale)) { EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error); if (GUILayout.Button("Auto-fix")) { NGUIEditorTools.FixUniform(mPanel.gameObject); } } if (NGUIEditorTools.DrawHeader("Advanced Options")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue); if (mPanel.renderQueue != rq) { mPanel.renderQueue = rq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } if (rq != UIPanel.RenderQueue.Automatic) { int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f)); if (mPanel.startingRenderQueue != sq) { mPanel.startingRenderQueue = sq; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); if (UIDrawCallViewer.instance != null) { UIDrawCallViewer.instance.Repaint(); } } } GUILayout.EndHorizontal(); GUI.changed = false; GUILayout.BeginHorizontal(); int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f)); if (so == 0) { GUILayout.Label("Automatic", GUILayout.MinWidth(20f)); } GUILayout.EndHorizontal(); if (GUI.changed) { mPanel.sortingOrder = so; } GUILayout.BeginHorizontal(); bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f)); GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.generateNormals != norms) { mPanel.generateNormals = norms; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool uv2 = EditorGUILayout.Toggle("UV2", mPanel.generateUV2, GUILayout.Width(100f)); GUILayout.Label("For custom shader effects", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.generateUV2 != uv2) { mPanel.generateUV2 = uv2; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } serializedObject.DrawProperty("shadowMode"); GUILayout.BeginHorizontal(); bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f)); GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.cullWhileDragging != cull) { mPanel.cullWhileDragging = cull; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f)); GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.alwaysOnScreen != alw) { mPanel.alwaysOnScreen = alw; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Padding", serializedObject, "softBorderPadding", GUILayout.Width(100f)); GUILayout.Label("Soft border pads content", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(mPanel.GetComponent <UIRoot>() != null); bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset && mPanel.GetComponent <UIRoot>() == null, GUILayout.Width(100f)); GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f)); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); if (mPanel.anchorOffset != off) { mPanel.anchorOffset = off; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } GUILayout.BeginHorizontal(); bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f)); GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mPanel.widgetsAreStatic != stat) { mPanel.widgetsAreStatic = stat; mPanel.RebuildAllDrawCalls(); EditorUtility.SetDirty(mPanel); } if (stat) { EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning); } GUILayout.BeginHorizontal(); bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f)); GUILayout.Label("Show in panel tool"); GUILayout.EndHorizontal(); if (mPanel.showInPanelTool != tool) { mPanel.showInPanelTool = !mPanel.showInPanelTool; EditorUtility.SetDirty(mPanel); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } NGUIEditorTools.EndContents(); } return(true); }
/// <summary> /// Draw the UI for this tool. /// </summary> void OnGUI() { Object fnt = (Object)NGUISettings.FMFont ?? (Object)NGUISettings.BMFont; UIFont uiFont = (fnt as UIFont); NGUIEditorTools.SetLabelWidth(80f); GUILayout.Space(3f); NGUIEditorTools.DrawHeader("Input", true); NGUIEditorTools.BeginContents(false); GUILayout.BeginHorizontal(); mType = (FontType)EditorGUILayout.EnumPopup("Type", mType, GUILayout.MinWidth(200f)); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); Create create = Create.None; if (mType == FontType.ImportedBitmap) { NGUISettings.fontData = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(TextAsset), false) as TextAsset; NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false, GUILayout.Width(140f)) as Texture2D; NGUIEditorTools.EndContents(); // Draw the atlas selection only if we have the font data and texture specified, just to make it easier EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null); { NGUIEditorTools.DrawHeader("Output", true); NGUIEditorTools.BeginContents(false); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false); NGUIEditorTools.EndContents(); } EditorGUI.EndDisabledGroup(); if (NGUISettings.fontData == null) { EditorGUILayout.HelpBox("To create a font from a previously exported FNT file, you need to use BMFont on " + "Windows or your choice of Glyph Designer or the less expensive bmGlyph on the Mac.\n\n" + "Either of these tools will create a FNT file for you that you will drag & drop into the field above.", MessageType.Info); } else if (NGUISettings.fontTexture == null) { EditorGUILayout.HelpBox("When exporting your font, you should get two files: the FNT, and the texture. Only one texture can be used per font.", MessageType.Info); } else if (NGUISettings.atlas == null) { EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " + "labels using this font will generate an extra draw call.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info); } EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null); { GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Create the Font")) { create = Create.Import; } GUILayout.Space(20f); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); } else { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Source")) { ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } Font ttf = EditorGUILayout.ObjectField(NGUISettings.FMFont, typeof(Font), false) as Font; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { NGUISettings.FMSize = EditorGUILayout.IntField("Size", NGUISettings.FMSize, GUILayout.Width(120f)); if (mType == FontType.Dynamic) { NGUISettings.fontStyle = (FontStyle)EditorGUILayout.EnumPopup(NGUISettings.fontStyle); NGUIEditorTools.DrawPadding(); } } GUILayout.EndHorizontal(); // Choose the font style if there are multiple faces present if (mType == FontType.GeneratedBitmap) { if (!FreeType.isPresent) { #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 string filename = (Application.platform == RuntimePlatform.WindowsEditor) ? "FreeType.dll" : "FreeType.dylib"; #else string filename = (Application.platform == RuntimePlatform.WindowsEditor) ? "FreeType64.dll" : "FreeType64.dylib"; #endif EditorGUILayout.HelpBox("Assets/NGUI/Editor/" + filename + " is missing", MessageType.Error); GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Find " + filename)) { string path = EditorUtility.OpenFilePanel("Find " + filename, NGUISettings.currentPath, (Application.platform == RuntimePlatform.WindowsEditor) ? "dll" : "dylib"); if (!string.IsNullOrEmpty(path)) { if (System.IO.Path.GetFileName(path) == filename) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); NGUISettings.pathToFreeType = path; } else { Debug.LogError("The library must be named '" + filename + "'"); } } } GUILayout.Space(20f); GUILayout.EndHorizontal(); } else if (ttf != null) { string[] faces = FreeType.GetFaces(ttf); if (faces != null) { if (mFaceIndex >= faces.Length) { mFaceIndex = 0; } if (faces.Length > 1) { GUILayout.Label("Style", EditorStyles.boldLabel); for (int i = 0; i < faces.Length; ++i) { GUILayout.BeginHorizontal(); GUILayout.Space(10f); if (DrawOption(i == mFaceIndex, " " + faces[i])) { mFaceIndex = i; } GUILayout.EndHorizontal(); } } } NGUISettings.fontKerning = EditorGUILayout.Toggle("Kerning", NGUISettings.fontKerning); GUILayout.Label("Characters", EditorStyles.boldLabel); CharacterMap cm = characterMap; GUILayout.BeginHorizontal(GUILayout.Width(100f)); GUILayout.BeginVertical(); GUI.changed = false; if (DrawOption(cm == CharacterMap.Numeric, " Numeric")) { cm = CharacterMap.Numeric; } if (DrawOption(cm == CharacterMap.Ascii, " ASCII")) { cm = CharacterMap.Ascii; } if (DrawOption(cm == CharacterMap.Latin, " Latin")) { cm = CharacterMap.Latin; } if (DrawOption(cm == CharacterMap.Custom, " Custom")) { cm = CharacterMap.Custom; } if (GUI.changed) { characterMap = cm; } GUILayout.EndVertical(); EditorGUI.BeginDisabledGroup(cm != CharacterMap.Custom); { if (cm != CharacterMap.Custom) { string chars = ""; if (cm == CharacterMap.Ascii) { for (int i = 33; i < 127; ++i) { chars += System.Convert.ToChar(i); } } else if (cm == CharacterMap.Numeric) { chars = "0123456789"; } else if (cm == CharacterMap.Latin) { for (int i = 33; i < 127; ++i) { chars += System.Convert.ToChar(i); } for (int i = 161; i < 256; ++i) { chars += System.Convert.ToChar(i); } } NGUISettings.charsToInclude = chars; } GUI.changed = false; string text = NGUISettings.charsToInclude; if (cm == CharacterMap.Custom) { text = EditorGUILayout.TextArea(text, GUI.skin.textArea, GUILayout.Height(80f), GUILayout.Width(Screen.width - 100f)); } else { GUILayout.Label(text, GUI.skin.textArea, GUILayout.Height(80f), GUILayout.Width(Screen.width - 100f)); } if (GUI.changed) { string final = ""; for (int i = 0; i < text.Length; ++i) { char c = text[i]; if (c < 33) { continue; } string s = c.ToString(); if (!final.Contains(s)) { final += s; } } if (final.Length > 0) { char[] chars = final.ToCharArray(); System.Array.Sort(chars); final = new string(chars); } else { final = ""; } NGUISettings.charsToInclude = final; } } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } } NGUIEditorTools.EndContents(); if (mType == FontType.Dynamic) { EditorGUI.BeginDisabledGroup(ttf == null); GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Create the Font")) { create = Create.Dynamic; } GUILayout.Space(20f); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else // Helpful info if (ttf == null) { EditorGUILayout.HelpBox("You don't have to create a UIFont to use dynamic fonts. You can just reference the Unity Font directly on the label.", MessageType.Info); } EditorGUILayout.HelpBox("Please note that dynamic fonts can't be made a part of an atlas, and using dynamic fonts will result in at least one extra draw call.", MessageType.Warning); #endif } else { bool isBuiltIn = (ttf != null) && string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(ttf)); // Draw the atlas selection only if we have the font data and texture specified, just to make it easier EditorGUI.BeginDisabledGroup(ttf == null || isBuiltIn || !FreeType.isPresent); { NGUIEditorTools.DrawHeader("Output", true); NGUIEditorTools.BeginContents(false); ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false); NGUIEditorTools.EndContents(); if (ttf == null) { EditorGUILayout.HelpBox("You can create a bitmap font by specifying a dynamic font to use as the source.", MessageType.Info); } else if (isBuiltIn) { EditorGUILayout.HelpBox("You chose an embedded font. You can't create a bitmap font from an embedded resource.", MessageType.Warning); } else if (NGUISettings.atlas == null) { EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " + "labels using this font will generate an extra draw call.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info); } GUILayout.BeginHorizontal(); GUILayout.Space(20f); if (GUILayout.Button("Create the Font")) { create = Create.Bitmap; } GUILayout.Space(20f); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); } } if (create == Create.None) { return; } // Open the "Save As" file dialog #if UNITY_3_5 string prefabPath = EditorUtility.SaveFilePanel("Save As", NGUISettings.currentPath, "New Font.prefab", "prefab"); #else string prefabPath = EditorUtility.SaveFilePanelInProject("Save As", "New Font.prefab", "prefab", "Save font as...", NGUISettings.currentPath); #endif if (string.IsNullOrEmpty(prefabPath)) { return; } NGUISettings.currentPath = System.IO.Path.GetDirectoryName(prefabPath); // Load the font's prefab GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; Object prefab = null; string fontName; // Font doesn't exist yet if (go == null || go.GetComponent <UIFont>() == null) { // Create a new prefab for the atlas prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); fontName = prefabPath.Replace(".prefab", ""); fontName = fontName.Substring(prefabPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1); // Create a new game object for the font go = new GameObject(fontName); uiFont = go.AddComponent <UIFont>(); } else { uiFont = go.GetComponent <UIFont>(); fontName = go.name; } if (create == Create.Dynamic) { uiFont.atlas = null; uiFont.dynamicFont = NGUISettings.FMFont; uiFont.dynamicFontStyle = NGUISettings.fontStyle; uiFont.defaultSize = NGUISettings.FMSize; } 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.FMSize = uiFont.defaultSize; } else if (create == Create.Bitmap) { // Create the bitmap font BMFont bmFont; Texture2D tex; if (FreeType.CreateFont( NGUISettings.FMFont, NGUISettings.FMSize, mFaceIndex, NGUISettings.fontKerning, NGUISettings.charsToInclude, 1, 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.FMFont = null; NGUISettings.BMFont = uiFont; } MarkAsChanged(); Selection.activeGameObject = go; }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { UIPanel panel = target as UIPanel; NGUIEditorTools.SetLabelWidth(80f); EditorGUILayout.Space(); float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f); if (alpha != panel.alpha) { NGUIEditorTools.RegisterUndo("Panel Alpha", panel); panel.alpha = alpha; } GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Depth"); int depth = panel.depth; if (GUILayout.Button("Back", GUILayout.Width(60f))) { --depth; } depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f)); if (GUILayout.Button("Forward", GUILayout.Width(68f))) { ++depth; } if (panel.depth != depth) { NGUIEditorTools.RegisterUndo("Panel Depth", panel); panel.depth = depth; if (UIPanelTool.instance != null) { UIPanelTool.instance.Repaint(); } } } GUILayout.EndHorizontal(); int matchingDepths = 0; for (int i = 0; i < UIPanel.list.size; ++i) { UIPanel p = UIPanel.list[i]; if (p != null && panel.depth == p.depth) { ++matchingDepths; } } if (matchingDepths > 1) { EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + panel.depth, MessageType.Info); } GUILayout.BeginHorizontal(); bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f)); GUILayout.Label("Needed for lit shaders"); GUILayout.EndHorizontal(); if (panel.generateNormals != norms) { panel.generateNormals = norms; UIPanel.SetDirty(); EditorUtility.SetDirty(panel); } GUILayout.BeginHorizontal(); bool cull = EditorGUILayout.Toggle("Cull", panel.cullWhileDragging, GUILayout.Width(100f)); GUILayout.Label("Cull widgets while dragging them"); GUILayout.EndHorizontal(); if (panel.cullWhileDragging != cull) { panel.cullWhileDragging = cull; UIPanel.SetDirty(); EditorUtility.SetDirty(panel); } GUILayout.BeginHorizontal(); bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f)); GUILayout.Label("Check if widgets won't move"); GUILayout.EndHorizontal(); if (panel.widgetsAreStatic != stat) { panel.widgetsAreStatic = stat; UIPanel.SetDirty(); EditorUtility.SetDirty(panel); } if (stat) { EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning); } GUILayout.BeginHorizontal(); if (NGUISettings.showAllDCs != EditorGUILayout.Toggle("Show All", NGUISettings.showAllDCs, GUILayout.Width(100f))) { NGUISettings.showAllDCs = !NGUISettings.showAllDCs; } GUILayout.Label("Show all draw calls"); GUILayout.EndHorizontal(); if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool)) { panel.showInPanelTool = !panel.showInPanelTool; EditorUtility.SetDirty(panel); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping); if (panel.clipping != clipping) { panel.clipping = clipping; EditorUtility.SetDirty(panel); } if (panel.clipping != UIDrawCall.Clipping.None) { Vector4 range = panel.clipRange; GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w)); GUILayout.EndHorizontal(); if (size.x < 0f) { size.x = 0f; } if (size.y < 0f) { size.y = 0f; } range.x = pos.x; range.y = pos.y; range.z = size.x; range.w = size.y; if (panel.clipRange != range) { NGUIEditorTools.RegisterUndo("Clipping Change", panel); panel.clipRange = range; EditorUtility.SetDirty(panel); } if (panel.clipping == UIDrawCall.Clipping.SoftClip) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness); GUILayout.EndHorizontal(); if (soft.x < 1f) { soft.x = 1f; } if (soft.y < 1f) { soft.y = 1f; } if (panel.clipSoftness != soft) { NGUIEditorTools.RegisterUndo("Clipping Change", panel); panel.clipSoftness = soft; EditorUtility.SetDirty(panel); } } #if !UNITY_3_5 && !UNITY_4_0 && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY) if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_1_x) { EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error); } #endif } if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale)) { EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error); if (GUILayout.Button("Auto-fix")) { NGUIEditorTools.FixUniform(panel.gameObject); } } for (int i = 0; i < UIDrawCall.list.size; ++i) { UIDrawCall dc = UIDrawCall.list[i]; if (dc.panel != panel) { if (!NGUISettings.showAllDCs) { continue; } if (dc.showDetails) { GUI.color = new Color(0.85f, 0.85f, 0.85f); } else { GUI.contentColor = new Color(0.85f, 0.85f, 0.85f); } } else { GUI.contentColor = Color.white; } string key = dc.keyName; string name = key + " of " + UIDrawCall.list.size; if (!dc.isActive) { name = name + " (HIDDEN)"; } else if (dc.panel != panel) { name = name + " (" + dc.panel.name + ")"; } if (NGUIEditorTools.DrawHeader(name, key)) { GUI.color = (dc.panel == panel) ? Color.white : new Color(0.8f, 0.8f, 0.8f); NGUIEditorTools.BeginContents(); EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false); int count = 0; for (int b = 0; b < UIWidget.list.size; ++b) { UIWidget w = UIWidget.list[b]; if (w.drawCall == dc) { ++count; } } string myPath = NGUITools.GetHierarchy(dc.panel.cachedGameObject); string remove = myPath + "\\"; string[] list = new string[count + 1]; list[0] = count.ToString(); count = 0; for (int b = 0; b < UIWidget.list.size; ++b) { UIWidget w = UIWidget.list[b]; if (w.drawCall == dc) { string path = NGUITools.GetHierarchy(w.cachedGameObject); list[++count] = count + ". " + (string.Equals(path, myPath) ? w.name : path.Replace(remove, "")); } } GUILayout.BeginHorizontal(); int sel = EditorGUILayout.Popup("Widgets", 0, list); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (sel != 0) { count = 0; for (int b = 0; b < UIWidget.list.size; ++b) { UIWidget w = UIWidget.list[b]; if (w.drawCall == dc && ++count == sel) { Selection.activeGameObject = w.gameObject; break; } } } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Triangles", dc.triangles.ToString(), GUILayout.Width(120f)); if (dc.panel != panel) { if (GUILayout.Button("Select the Panel")) { Selection.activeGameObject = dc.panel.gameObject; } GUILayout.Space(18f); } GUILayout.EndHorizontal(); bool draw = !EditorGUILayout.Toggle("Hide", !dc.isActive); if (dc.isActive != draw) { dc.isActive = draw; UnityEditor.EditorUtility.SetDirty(dc.panel); } if (dc.panel.clipping != UIDrawCall.Clipping.None && !dc.isClipped) { EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.", MessageType.Warning); } NGUIEditorTools.EndContents(); GUI.color = Color.white; } } }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { BetterList <UIDrawCall> dcs = UIDrawCall.activeList; if (dcs.size == 0) { EditorGUILayout.HelpBox("No NGUI draw calls present in the scene", MessageType.Info); return; } GUILayout.Space(12f); NGUIEditorTools.SetLabelWidth(100f); ShowFilter show = (NGUISettings.showAllDCs ? ShowFilter.AllPanels : ShowFilter.SelectedPanel); if ((ShowFilter)EditorGUILayout.EnumPopup("Draw Call Filter", show) != show) { NGUISettings.showAllDCs = !NGUISettings.showAllDCs; } GUILayout.Space(6f); UIPanel selectedPanel = NGUITools.FindInParents <UIPanel>(Selection.activeGameObject); if (selectedPanel == null) { EditorGUILayout.HelpBox("Select any object within the UI hierarchy", MessageType.Info); return; } NGUIEditorTools.SetLabelWidth(80f); mScroll = GUILayout.BeginScrollView(mScroll); int dcCount = 0; for (int i = 0; i < dcs.size; ++i) { UIDrawCall dc = dcs[i]; if (dc.manager != selectedPanel) { if (!NGUISettings.showAllDCs) { continue; } if (dc.showDetails) { GUI.color = new Color(0.85f, 0.85f, 0.85f); } else { GUI.contentColor = new Color(0.85f, 0.85f, 0.85f); } } else { GUI.contentColor = Color.white; } ++dcCount; string key = dc.keyName; string name = key + " of " + dcs.size; if (!dc.isActive) { name = name + " (HIDDEN)"; } else if (dc.manager != selectedPanel) { name = name + " (" + dc.manager.name + ")"; } if (NGUIEditorTools.DrawHeader(name, key)) { GUI.color = (dc.manager == selectedPanel) ? Color.white : new Color(0.8f, 0.8f, 0.8f); NGUIEditorTools.BeginContents(); EditorGUILayout.ObjectField("Material", dc.baseMaterial, typeof(Material), false); int count = 0; for (int b = 0; b < UIWidget.list.size; ++b) { UIWidget w = UIWidget.list[b]; if (w.drawCall == dc) { ++count; } } string myPath = NGUITools.GetHierarchy(dc.manager.cachedGameObject); string remove = myPath + "\\"; string[] list = new string[count + 1]; list[0] = count.ToString(); count = 0; for (int b = 0; b < UIWidget.list.size; ++b) { UIWidget w = UIWidget.list[b]; if (w.drawCall == dc) { string path = NGUITools.GetHierarchy(w.cachedGameObject); list[++count] = count + ". " + (string.Equals(path, myPath) ? w.name : path.Replace(remove, "")); } } GUILayout.BeginHorizontal(); int sel = EditorGUILayout.Popup("Widgets", 0, list); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (sel != 0) { count = 0; for (int b = 0; b < UIWidget.list.size; ++b) { UIWidget w = UIWidget.list[b]; if (w.drawCall == dc && ++count == sel) { Selection.activeGameObject = w.gameObject; break; } } } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Render Q", dc.finalRenderQueue.ToString(), GUILayout.Width(120f)); bool draw = (Visibility)EditorGUILayout.EnumPopup(dc.isActive ? Visibility.Visible : Visibility.Hidden) == Visibility.Visible; GUILayout.Space(18f); GUILayout.EndHorizontal(); if (dc.isActive != draw) { dc.isActive = draw; UnityEditor.EditorUtility.SetDirty(dc.manager); } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Triangles", dc.triangles.ToString(), GUILayout.Width(120f)); if (dc.manager != selectedPanel) { if (GUILayout.Button("Select the Panel")) { Selection.activeGameObject = dc.manager.gameObject; } GUILayout.Space(18f); } GUILayout.EndHorizontal(); if (dc.manager.clipping != UIDrawCall.Clipping.None && !dc.isClipped) { EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.", MessageType.Warning); } NGUIEditorTools.EndContents(); GUI.color = Color.white; } } if (dcCount == 0) { EditorGUILayout.HelpBox("No draw calls found", MessageType.Info); } GUILayout.EndScrollView(); }
public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(130f); GUILayout.Space(3f); serializedObject.Update(); SerializedProperty sppv = serializedObject.FindProperty("contentPivot"); UIWidget.Pivot before = (UIWidget.Pivot)sppv.intValue; NGUIEditorTools.DrawProperty("Content Origin", sppv, false); SerializedProperty sp = NGUIEditorTools.DrawProperty("Movement", serializedObject, "movement"); if (((UIScrollView.Movement)sp.intValue) == UIScrollView.Movement.Custom) { NGUIEditorTools.SetLabelWidth(20f); GUILayout.BeginHorizontal(); GUILayout.Space(114f); NGUIEditorTools.DrawProperty("X", serializedObject, "customMovement.x", GUILayout.MinWidth(20f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "customMovement.y", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); } NGUIEditorTools.SetLabelWidth(130f); NGUIEditorTools.DrawProperty("Drag Effect", serializedObject, "dragEffect"); NGUIEditorTools.DrawProperty("Scroll Wheel Factor", serializedObject, "scrollWheelFactor"); NGUIEditorTools.DrawProperty("Momentum Amount", serializedObject, "momentumAmount"); NGUIEditorTools.DrawProperty("Restrict Within Panel", serializedObject, "restrictWithinPanel"); NGUIEditorTools.DrawProperty("Cancel Drag If Fits", serializedObject, "disableDragIfFits"); NGUIEditorTools.DrawProperty("Smooth Drag Start", serializedObject, "smoothDragStart"); NGUIEditorTools.DrawProperty("IOS Drag Emulation", serializedObject, "iOSDragEmulation"); NGUIEditorTools.DrawProperty("Reset Offset OnEnable", serializedObject, "resetOffsetOnEnable"); NGUIEditorTools.SetLabelWidth(100f); if (NGUIEditorTools.DrawHeader("Scroll Bars")) { NGUIEditorTools.BeginContents(); NGUIEditorTools.DrawProperty("Horizontal", serializedObject, "horizontalScrollBar"); NGUIEditorTools.DrawProperty("Vertical", serializedObject, "verticalScrollBar"); NGUIEditorTools.DrawProperty("Show Condition", serializedObject, "showScrollBars"); NGUIEditorTools.DrawProperty("Darg Begin", serializedObject, "DargBegin"); NGUIEditorTools.DrawProperty("Darg End", serializedObject, "DargEnd"); NGUIEditorTools.DrawProperty("Undarg Begin", serializedObject, "UndargBegin"); NGUIEditorTools.DrawProperty("UndargEnd", serializedObject, "UndargEnd"); NGUIEditorTools.EndContents(); } serializedObject.ApplyModifiedProperties(); if (before != (UIWidget.Pivot)sppv.intValue) { (target as UIScrollView).ResetPosition(); } }
/// <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 inspector widget. /// </summary> public override void OnInspectorGUI() { UIPanel panel = target as UIPanel; BetterList <UIDrawCall> drawcalls = panel.drawCalls; drawcalls.Sort(delegate(UIDrawCall w1, UIDrawCall w2) { return(w1.depth.CompareTo(w2.depth)); }); EditorGUIUtility.fieldWidth = 0f; EditorGUIUtility.labelWidth = 80f; //NGUIEditorTools.DrawSeparator(); EditorGUILayout.Space(); float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f); if (alpha != panel.alpha) { NGUIEditorTools.RegisterUndo("Panel Alpha", panel); panel.alpha = alpha; } GUILayout.BeginHorizontal(); bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f)); GUILayout.Label("Needed for lit shaders"); GUILayout.EndHorizontal(); if (panel.generateNormals != norms) { panel.generateNormals = norms; panel.UpdateDrawcalls(); EditorUtility.SetDirty(panel); } // No one seems to know how to use this properly correctly. Solution? Removing it. // If you know wtf you're doing, you're welcome to uncomment it. //GUILayout.BeginHorizontal(); //bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f)); //GUILayout.Label("Doubles draw calls, saves fillrate"); //GUILayout.EndHorizontal(); //if (panel.depthPass != depth) //{ // panel.depthPass = depth; // panel.UpdateDrawcalls(); // EditorUtility.SetDirty(panel); //} //if (depth) //{ // UICamera cam = UICamera.FindCameraForLayer(panel.gameObject.layer); // if (cam == null || cam.camera.isOrthoGraphic) // { // EditorGUILayout.HelpBox("Please note that depth pass will only save fillrate when used with 3D UIs, and only UIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning); // } //} GUILayout.BeginHorizontal(); bool sort = EditorGUILayout.Toggle("Depth Sort", panel.sortByDepth, GUILayout.Width(100f)); GUILayout.Label("Sort widgets by depth (ignore Z)"); GUILayout.EndHorizontal(); if (panel.sortByDepth != sort) { panel.sortByDepth = sort; panel.UpdateDrawcalls(); EditorUtility.SetDirty(panel); } if (!sort) { EditorGUILayout.HelpBox("Keep the 'Depth Sort' flag turned on, unless you are working with a UI created prior to NGUI 2.7.0 and want to sort by Z in addition to Depth.", MessageType.Warning); } GUILayout.BeginHorizontal(); bool cull = EditorGUILayout.Toggle("Cull", panel.cullWhileDragging, GUILayout.Width(100f)); GUILayout.Label("Cull widgets while dragging them"); GUILayout.EndHorizontal(); if (panel.cullWhileDragging != cull) { panel.cullWhileDragging = cull; panel.UpdateDrawcalls(); EditorUtility.SetDirty(panel); } GUILayout.BeginHorizontal(); bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f)); GUILayout.Label("Check if widgets won't move"); GUILayout.EndHorizontal(); if (panel.widgetsAreStatic != stat) { panel.widgetsAreStatic = stat; panel.UpdateDrawcalls(); EditorUtility.SetDirty(panel); } if (stat) { EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning); } if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool)) { panel.showInPanelTool = !panel.showInPanelTool; EditorUtility.SetDirty(panel); EditorWindow.FocusWindowIfItsOpen <UIPanelTool>(); } UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo); if (panel.debugInfo != di) { panel.debugInfo = di; EditorUtility.SetDirty(panel); } UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping); if (panel.clipping != clipping) { panel.clipping = clipping; EditorUtility.SetDirty(panel); } if (panel.clipping != UIDrawCall.Clipping.None) { Vector4 range = panel.clipRange; GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w)); GUILayout.EndHorizontal(); if (size.x < 0f) { size.x = 0f; } if (size.y < 0f) { size.y = 0f; } range.x = pos.x; range.y = pos.y; range.z = size.x; range.w = size.y; if (panel.clipRange != range) { NGUIEditorTools.RegisterUndo("Clipping Change", panel); panel.clipRange = range; EditorUtility.SetDirty(panel); } if (panel.clipping == UIDrawCall.Clipping.SoftClip) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness); GUILayout.EndHorizontal(); if (soft.x < 1f) { soft.x = 1f; } if (soft.y < 1f) { soft.y = 1f; } if (panel.clipSoftness != soft) { NGUIEditorTools.RegisterUndo("Clipping Change", panel); panel.clipSoftness = soft; EditorUtility.SetDirty(panel); } } #if !UNITY_3_5 && !UNITY_4_0 && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY) if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_2_0) { EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error); } #endif } if (clipping == UIDrawCall.Clipping.HardClip) { EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning); } if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale)) { EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error); if (GUILayout.Button("Auto-fix")) { NGUIEditorTools.FixUniform(panel.gameObject); } } if (panel.drawCalls.size > 0 && NGUIEditorTools.DrawHeader(panel.drawCalls.size + " draw calls from " + panel.widgets.size + " widgets", "DrawCalls")) { NGUIEditorTools.BeginContents(); foreach (UIDrawCall dc in drawcalls) { EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false); EditorGUILayout.LabelField("Triangles", dc.triangles.ToString()); if (clipping != UIDrawCall.Clipping.None && !dc.isClipped) { EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.", MessageType.Warning); } } NGUIEditorTools.EndContents(); } }
public override void OnInspectorGUI() { mFont = target as UIFont; 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 <UIFont>(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); mFont.replacement = mReplacement; NGUITools.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 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; } Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); 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); mFont.defaultSize = size; } if (style != mFont.dynamicFontStyle) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFontStyle = style; } #endif } else { ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas, true); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.DrawAdvancedSpriteField(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.MarkAsChanged(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } 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); 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.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.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); 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(); } }
public override void OnInspectorGUI() { UICamera cam = target as UICamera; GUILayout.Space(3f); serializedObject.Update(); SerializedProperty et = serializedObject.FindProperty("eventType"); if (et.hasMultipleDifferentValues) { EditorGUILayout.PropertyField(et); } else { string[] options = new string[] { "3D World", "3D UI", "2D World", "2D UI" }; int val = EditorGUILayout.Popup("Event Type", et.intValue, options); if (val != et.intValue) { et.intValue = val; } } if (UICamera.eventHandler != cam) { EditorGUILayout.PropertyField(serializedObject.FindProperty("eventReceiverMask"), new GUIContent("Event Mask")); serializedObject.ApplyModifiedProperties(); EditorGUILayout.HelpBox("All other settings are inherited from the First Camera.", MessageType.Info); if (GUILayout.Button("Select the First Camera")) { Selection.activeGameObject = UICamera.eventHandler.gameObject; } } else { SerializedProperty mouse = serializedObject.FindProperty("useMouse"); SerializedProperty touch = serializedObject.FindProperty("useTouch"); SerializedProperty keyboard = serializedObject.FindProperty("useKeyboard"); SerializedProperty controller = serializedObject.FindProperty("useController"); EditorGUILayout.PropertyField(serializedObject.FindProperty("eventReceiverMask"), new GUIContent("Event Mask")); SerializedProperty ev = serializedObject.FindProperty("eventsGoToColliders"); if (ev != null) { bool val = ev.boolValue; bool newVal = EventsGo.Colliders == (EventsGo)EditorGUILayout.EnumPopup("Events go to...", ev.boolValue ? EventsGo.Colliders : EventsGo.Rigidbodies); if (val != newVal) { ev.boolValue = newVal; } } EditorGUILayout.PropertyField(serializedObject.FindProperty("debug")); EditorGUI.BeginDisabledGroup(!mouse.boolValue && !touch.boolValue); { EditorGUILayout.PropertyField(serializedObject.FindProperty("allowMultiTouch")); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!mouse.boolValue); { EditorGUILayout.PropertyField(serializedObject.FindProperty("stickyTooltip")); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(serializedObject.FindProperty("tooltipDelay")); GUILayout.Label("seconds", GUILayout.MinWidth(60f)); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal(); SerializedProperty rd = serializedObject.FindProperty("rangeDistance"); EditorGUILayout.PropertyField(rd, new GUIContent("Raycast Range")); GUILayout.Label(rd.floatValue < 0f ? "unlimited" : "units", GUILayout.MinWidth(60f)); GUILayout.EndHorizontal(); NGUIEditorTools.SetLabelWidth(80f); if (NGUIEditorTools.DrawHeader("Event Sources")) { NGUIEditorTools.BeginContents(); { GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(mouse, new GUIContent("Mouse"), GUILayout.MinWidth(100f)); EditorGUILayout.PropertyField(touch, new GUIContent("Touch"), GUILayout.MinWidth(100f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(keyboard, new GUIContent("Keyboard"), GUILayout.MinWidth(100f)); EditorGUILayout.PropertyField(controller, new GUIContent("Controller"), GUILayout.MinWidth(100f)); GUILayout.EndHorizontal(); } NGUIEditorTools.EndContents(); } if ((mouse.boolValue || touch.boolValue) && NGUIEditorTools.DrawHeader("Thresholds")) { NGUIEditorTools.BeginContents(); { EditorGUI.BeginDisabledGroup(!mouse.boolValue); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(serializedObject.FindProperty("mouseDragThreshold"), new GUIContent("Mouse Drag"), GUILayout.Width(120f)); GUILayout.Label("pixels"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(serializedObject.FindProperty("mouseClickThreshold"), new GUIContent("Mouse Click"), GUILayout.Width(120f)); GUILayout.Label("pixels"); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!touch.boolValue); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(serializedObject.FindProperty("touchDragThreshold"), new GUIContent("Touch Drag"), GUILayout.Width(120f)); GUILayout.Label("pixels"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(serializedObject.FindProperty("touchClickThreshold"), new GUIContent("Touch Tap"), GUILayout.Width(120f)); GUILayout.Label("pixels"); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); } NGUIEditorTools.EndContents(); } if ((mouse.boolValue || keyboard.boolValue || controller.boolValue) && NGUIEditorTools.DrawHeader("Axes and Keys")) { NGUIEditorTools.BeginContents(); { EditorGUILayout.PropertyField(serializedObject.FindProperty("horizontalAxisName"), new GUIContent("Horizontal")); EditorGUILayout.PropertyField(serializedObject.FindProperty("verticalAxisName"), new GUIContent("Vertical")); EditorGUILayout.PropertyField(serializedObject.FindProperty("scrollAxisName"), new GUIContent("Scroll")); EditorGUILayout.PropertyField(serializedObject.FindProperty("submitKey0"), new GUIContent("Submit 1")); EditorGUILayout.PropertyField(serializedObject.FindProperty("submitKey1"), new GUIContent("Submit 2")); EditorGUILayout.PropertyField(serializedObject.FindProperty("cancelKey0"), new GUIContent("Cancel 1")); EditorGUILayout.PropertyField(serializedObject.FindProperty("cancelKey1"), new GUIContent("Cancel 2")); } NGUIEditorTools.EndContents(); } serializedObject.ApplyModifiedProperties(); } }
void DrawTrigger() { if (NGUIEditorTools.DrawHeader("触发器配置")) { EditorGUILayout.BeginHorizontal(); { m_ETriggerAreaType = (ETriggerAreaType)EditorGUILayout.Popup((int)m_ETriggerAreaType, m_TriggerTypeList, GUILayout.Width(100f)); if (GUILayout.Button("添加一个触发器", GUILayout.Width(120f))) { AddTrigger(m_ETriggerAreaType, Vector3.zero, Vector3.zero, Vector3.one); } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < m_TriggerList.Count; ++i) { TriggerEditorData data = m_TriggerList[i]; GUIStyle textColor = new GUIStyle(); textColor.normal.textColor = data.m_bIsSelected ? Color.red:Color.white; if (NGUIEditorTools.DrawHeader(m_TriggerList[i].TriggerData.AreaType.ToString())) { EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("调整触发器位置", textColor, GUILayout.Width(120f))) { m_nCurrentSettingPosTriggerIndex = i; TerrainEditorRuntime.Instance.SetRaycastCallBack(SetTriggerPos); } if (GUILayout.Button("删除触发器", textColor, GUILayout.Width(120f))) { m_RemovingTriggerList.Add(m_TriggerList[i]); } if (GUILayout.Button("编辑触发器事件", textColor, GUILayout.Width(120f))) { TerrainTriggerNodeEditorWindow.Instance.OpenWindow(data.TriggerData); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { Vector3 tmpPos = data.m_SourceObj.transform.position; GUILayout.TextArea("触发器位置", textColor, GUILayout.Width(120f)); GUILayout.Label(tmpPos.ToString(), GUILayout.Width(100f)); GUILayout.Label("x", GUILayout.Width(20f)); tmpPos.x = EditorGUILayout.FloatField(tmpPos.x); GUILayout.Label("y", GUILayout.Width(20f)); tmpPos.y = EditorGUILayout.FloatField(tmpPos.y); GUILayout.Label("z", GUILayout.Width(20f)); tmpPos.z = EditorGUILayout.FloatField(tmpPos.z); data.m_SourceObj.transform.position = tmpPos; data.TriggerData.Pos.SetVector3(data.m_SourceObj.transform.position); } EditorGUILayout.EndHorizontal(); switch (data.TriggerData.AreaType) { case ETriggerAreaType.Cube: DrawCubeTrigger(data); break; case ETriggerAreaType.Sphere: DrawCircleTrigger(data); break; default: break; } } } CheckRemovingTrigger(); } }
/// <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.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.trueColorAtlas, GUILayout.Width(100f)); GUILayout.Label("replace textures with sprites", GUILayout.MinWidth(70f)); 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 ? "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(NGUIEditorTools.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(); }
/// <summary> /// All widgets have depth, color and make pixel-perfect options /// </summary> protected override void DrawCustomProperties() { PrefabType type = PrefabUtility.GetPrefabType(mWidget.gameObject); if (NGUIEditorTools.DrawHeader("Widget")) { NGUIEditorTools.BeginContents(); if (drawColor) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 // Color tint GUILayout.BeginHorizontal(); SerializedProperty sp = NGUIEditorTools.DrawProperty("Color", serializedObject, "mColor", GUILayout.MinWidth(20f)); if (GUILayout.Button("Copy", GUILayout.Width(50f))) { NGUISettings.color = sp.colorValue; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.color = EditorGUILayout.ColorField("Clipboard", NGUISettings.color); if (GUILayout.Button("Paste", GUILayout.Width(50f))) { sp.colorValue = NGUISettings.color; } GUILayout.EndHorizontal(); GUILayout.Space(6f); #else NGUIEditorTools.DrawProperty("Color", serializedObject, "mColor", GUILayout.MinWidth(20f)); #endif } else if (serializedObject.isEditingMultipleObjects) { NGUIEditorTools.DrawProperty("Alpha", serializedObject, "mColor.a", GUILayout.Width(120f)); } else { GUI.changed = false; float alpha = EditorGUILayout.Slider("Alpha", mWidget.alpha, 0f, 1f); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Alpha change", mWidget); mWidget.alpha = alpha; } } DrawPivot(); DrawDepth(type == PrefabType.Prefab); DrawDimensions(type == PrefabType.Prefab); SerializedProperty ratio = serializedObject.FindProperty("aspectRatio"); SerializedProperty aspect = serializedObject.FindProperty("keepAspectRatio"); GUILayout.BeginHorizontal(); { if (!aspect.hasMultipleDifferentValues && aspect.intValue == 0) { EditorGUI.BeginDisabledGroup(true); NGUIEditorTools.DrawProperty("Aspect Ratio", ratio, false, GUILayout.Width(130f)); EditorGUI.EndDisabledGroup(); } else { NGUIEditorTools.DrawProperty("Aspect Ratio", ratio, false, GUILayout.Width(130f)); } NGUIEditorTools.DrawProperty("", aspect, false, GUILayout.MinWidth(20f)); } GUILayout.EndHorizontal(); if (serializedObject.isEditingMultipleObjects || mWidget.hasBoxCollider) { GUILayout.BeginHorizontal(); { NGUIEditorTools.DrawProperty("Box Collider", serializedObject, "autoResizeBoxCollider", GUILayout.Width(100f)); GUILayout.Label("auto-adjust to match"); } GUILayout.EndHorizontal(); } NGUIEditorTools.EndContents(); } }