static public void AddTexture() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Texture"); #endif Selection.activeGameObject = NGUISettings.AddTexture(go).gameObject; } else { Debug.Log("You must select a game object first."); } }
/// <summary> /// Label creation function. /// </summary> void CreateLabel(GameObject go) { GUILayout.BeginHorizontal(); Color c = EditorGUILayout.ColorField("Color", mColor, GUILayout.Width(220f)); GUILayout.Label("Color tint the label will start with"); GUILayout.EndHorizontal(); if (mColor != c) { mColor = c; Save(); } if (ShouldCreate(go, NGUISettings.ambigiousFont != null)) { Selection.activeGameObject = NGUISettings.AddLabel(go).gameObject; } }
/// <summary> /// Sprite creation function. /// </summary> void CreateSprite(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.DrawSpriteField("Sprite", "Sprite that will be created", NGUISettings.atlas, NGUISettings.selectedSprite, OnSprite, GUILayout.Width(120f)); if (!string.IsNullOrEmpty(NGUISettings.selectedSprite)) { GUILayout.BeginHorizontal(); NGUISettings.pivot = (UIWidget.Pivot)EditorGUILayout.EnumPopup("Pivot", NGUISettings.pivot, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Initial pivot point used by the sprite"); GUILayout.EndHorizontal(); } } if (ShouldCreate(go, NGUISettings.atlas != null)) { Selection.activeGameObject = NGUISettings.AddSprite(go).gameObject; } }
/// <summary> /// Load all items from Editor Prefs. /// </summary> void Load() { mTab = NGUISettings.GetInt("NGUI Prefab Tab", 0); mMode = NGUISettings.GetEnum <Mode>("NGUI Prefab Mode", mMode); { // foreach(var item in mItems) var __enumerator5 = (mItems).GetEnumerator(); while (__enumerator5.MoveNext()) { var item = (Item)__enumerator5.Current; DestroyTexture(item); } } mItems.Clear(); string data = NGUISettings.GetString(saveKey, ""); if (string.IsNullOrEmpty(data)) { Reset(); } else { if (string.IsNullOrEmpty(data)) { return; } string[] guids = data.Split('|'); { var __array6 = guids; var __arrayLength6 = __array6.Length; for (int __i6 = 0; __i6 < __arrayLength6; ++__i6) { var s = (string)__array6[__i6]; AddGUID(s, -1); } } RectivateLights(); } }
static void AddCustomScrollView() { GameObject go = NGUIEditorTools.SelectedRoot(true); GameObject svParent = new GameObject("Scroll View Parent"); svParent.transform.SetParent(go.transform); UIPanel panel = NGUISettings.AddPanel(SelectedRoot()); if (panel == null) { panel = NGUIEditorTools.SelectedRoot(true).GetComponent <UIPanel>(); } panel.clipping = UIDrawCall.Clipping.SoftClip; panel.name = "Scroll View"; panel.gameObject.AddComponent <UIScrollView>(); Selection.activeGameObject = panel.gameObject; //panel.gameObject.AddComponent<Air2000.ScrollViewScale>(); panel.transform.SetParent(svParent.transform); }
/// <summary> /// Load all items from Editor Prefs. /// </summary> void Load() { mTab = NGUISettings.GetInt("NGUI Prefab Tab", 0); mMode = NGUISettings.GetEnum <Mode>("NGUI Prefab Mode", mMode); foreach (Item item in mItems) { DestroyTexture(item); } mItems.Clear(); string data = NGUISettings.GetString(saveKey, ""); if (mTab == 0 && !string.IsNullOrEmpty(data)) { mTabLoaded[mTab] = true; } if (!mTabLoaded[mTab]) { mTabLoaded[mTab] = true; Reset(); } else { if (string.IsNullOrEmpty(data)) { return; } string[] guids = data.Split('|'); foreach (string s in guids) { AddGUID(s, -1); } RectivateLights(); } }
static public void AddLabel() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Label"); #endif TextFxNGUI w = NGUITools.AddWidget <TextFxNGUI>(go); w.name = NEW_INSTANCE_NAME; w.ambigiousFont = NGUISettings.ambigiousFont; w.text = "New Label"; w.pivot = NGUISettings.pivot; w.width = 120; w.height = Mathf.Max(20, NGUISettings.GetInt("NGUI Font Height", 16)); w.fontStyle = NGUISettings.fontStyle; w.fontSize = NGUISettings.fontSize; w.applyGradient = true; w.gradientBottom = new Color(0.7f, 0.7f, 0.7f); w.AssumeNaturalSize(); // return w; if (w.bitmapFont == null && w.trueTypeFont == null) { w.trueTypeFont = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; } Selection.activeGameObject = w.gameObject; } else { Debug.Log("You must select a game object first."); } }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { Event currentEvent = Event.current; EventType type = currentEvent.type; int x = cellPadding, y = cellPadding; int width = Screen.width - cellPadding; int spacingX = cellSize + cellPadding; int spacingY = spacingX; if (mMode == Mode.DetailedMode) { spacingY += 32; } GameObject dragged = draggedObject; bool isDragging = (dragged != null); int indexUnderMouse = GetCellUnderMouse(spacingX, spacingY); Item selection = isDragging ? FindItem(dragged) : null; string searchFilter = NGUISettings.searchField; int newTab = mTab; GUILayout.BeginHorizontal(); if (GUILayout.Toggle(newTab == 0, "1", "ButtonLeft")) { newTab = 0; } if (GUILayout.Toggle(newTab == 1, "2", "ButtonMid")) { newTab = 1; } if (GUILayout.Toggle(newTab == 2, "3", "ButtonMid")) { newTab = 2; } if (GUILayout.Toggle(newTab == 3, "4", "ButtonMid")) { newTab = 3; } if (GUILayout.Toggle(newTab == 4, "5", "ButtonRight")) { newTab = 4; } GUILayout.EndHorizontal(); if (mTab != newTab) { Save(); mTab = newTab; mReset = true; NGUISettings.SetInt("NGUI Prefab Tab", mTab); Load(); } if (mReset && type == EventType.Repaint) { mReset = false; foreach (Item item in mItems) { GeneratePreview(item, null); } RectivateLights(); } // Search field GUILayout.BeginHorizontal(); { string after = EditorGUILayout.TextField("", searchFilter, "SearchTextField", GUILayout.Width(Screen.width - 20f)); if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f))) { after = ""; GUIUtility.keyboardControl = 0; } if (searchFilter != after) { NGUISettings.searchField = after; searchFilter = after; } } GUILayout.EndHorizontal(); bool eligibleToDrag = (currentEvent.mousePosition.y < Screen.height - 40); if (type == EventType.MouseDown) { mMouseIsInside = true; } else if (type == EventType.MouseDrag) { mMouseIsInside = true; if (indexUnderMouse != -1 && eligibleToDrag) { // Drag operation begins if (draggedObjectIsOurs) { DragAndDrop.StartDrag("Prefab Tool"); } currentEvent.Use(); } } else if (type == EventType.MouseUp) { DragAndDrop.PrepareStartDrag(); mMouseIsInside = false; Repaint(); } else if (type == EventType.DragUpdated) { // Something dragged into the window mMouseIsInside = true; UpdateVisual(); currentEvent.Use(); } else if (type == EventType.DragPerform) { // We've dropped a new object into the window if (dragged != null) { if (selection != null) { DestroyTexture(selection); mItems.Remove(selection); } AddItem(dragged, indexUnderMouse); draggedObject = null; } mMouseIsInside = false; currentEvent.Use(); } else if (type == EventType.DragExited || type == EventType.Ignore) { mMouseIsInside = false; } // If the mouse is not inside the window, clear the selection and dragged object if (!mMouseIsInside) { selection = null; dragged = null; } // Create a list of indices, inserting an entry of '-1' underneath the dragged object BetterList <int> indices = new BetterList <int>(); for (int i = 0; i < mItems.size;) { if (dragged != null && indices.size == indexUnderMouse) { indices.Add(-1); } if (mItems[i] != selection) { if (string.IsNullOrEmpty(searchFilter) || mItems[i].prefab.name.IndexOf(searchFilter, System.StringComparison.CurrentCultureIgnoreCase) != -1) { indices.Add(i); } } ++i; } // There must always be '-1' (Add/Move slot) present if (!indices.Contains(-1)) { indices.Add(-1); } // We want to start dragging something from within the window if (eligibleToDrag && type == EventType.MouseDown && indexUnderMouse > -1) { GUIUtility.keyboardControl = 0; if (currentEvent.button == 0 && indexUnderMouse < indices.size) { int index = indices[indexUnderMouse]; if (index != -1 && index < mItems.size) { selection = mItems[index]; draggedObject = selection.prefab; dragged = selection.prefab; currentEvent.Use(); } } } //else if (type == EventType.MouseUp && currentEvent.button == 1 && indexUnderMouse > mItems.size) //{ // NGUIContextMenu.AddItem("Reset", false, RemoveItem, index); // NGUIContextMenu.Show(); //} // Draw the scroll view with prefabs mPos = GUILayout.BeginScrollView(mPos); { Color normal = new Color(1f, 1f, 1f, 0.5f); for (int i = 0; i < indices.size; ++i) { int index = indices[i]; Item ent = (index != -1) ? mItems[index] : selection; if (ent != null && ent.prefab == null) { mItems.RemoveAt(index); continue; } Rect rect = new Rect(x, y, cellSize, cellSize); Rect inner = rect; inner.xMin += 2f; inner.xMax -= 2f; inner.yMin += 2f; inner.yMax -= 2f; rect.yMax -= 1f; // Button seems to be mis-shaped. It's height is larger than its width by a single pixel. if (!isDragging && (mMode == Mode.CompactMode || (ent == null || ent.tex != null))) { mContent.tooltip = (ent != null) ? ent.prefab.name : "Click to add"; } else { mContent.tooltip = ""; } //if (ent == selection) { GUI.color = normal; NGUIEditorTools.DrawTiledTexture(inner, NGUIEditorTools.backdropTexture); } GUI.color = Color.white; GUI.backgroundColor = normal; if (GUI.Button(rect, mContent, "Button")) { if (ent == null || currentEvent.button == 0) { string path = EditorUtility.OpenFilePanel("Add a prefab", NGUISettings.currentPath, "prefab"); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); Item newEnt = CreateItemByPath(path); if (newEnt != null) { mItems.Add(newEnt); Save(); } } } else if (currentEvent.button == 1) { NGUIContextMenu.AddItem("Delete", false, RemoveItem, index); NGUIContextMenu.Show(); } } string caption = (ent == null) ? "" : ent.prefab.name.Replace("Control - ", ""); if (ent != null) { if (ent.tex != null) { GUI.DrawTexture(inner, ent.tex); } else if (mMode != Mode.DetailedMode) { GUI.Label(inner, caption, mStyle); caption = ""; } } else { GUI.Label(inner, "Add", mStyle); } if (mMode == Mode.DetailedMode) { GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); GUI.contentColor = new Color(1f, 1f, 1f, 0.7f); GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), caption, "ProgressBarBack"); GUI.contentColor = Color.white; GUI.backgroundColor = Color.white; } x += spacingX; if (x + spacingX > width) { y += spacingY; x = cellPadding; } } GUILayout.Space(y); } GUILayout.EndScrollView(); // Mode Mode modeAfter = (Mode)EditorGUILayout.EnumPopup(mMode); if (modeAfter != mMode) { mMode = modeAfter; mReset = true; NGUISettings.SetEnum("NGUI Prefab Mode", mMode); } }
static void PasteStyle2(MenuCommand command) { NGUISettings.PasteWidget(command.context as UIWidget, false); }
static void CopyStyle(MenuCommand command) { NGUISettings.CopyWidget(command.context as UIWidget); }
static void AddPanel() { UIPanel panel = NGUISettings.AddPanel(SelectedRoot()); Selection.activeGameObject = (panel == null) ? NGUIEditorTools.SelectedRoot(true) : panel.gameObject; }
/// <summary> /// Create a popup list or a menu. /// </summary> void CreatePopup(GameObject go, bool isDropDown) { if (NGUISettings.atlas != null) { NGUIEditorTools.DrawSpriteField("Foreground", "Foreground sprite (shown on the button)", NGUISettings.atlas, mListFG, OnListFG, GUILayout.Width(120f)); NGUIEditorTools.DrawSpriteField("Background", "Background sprite (envelops the options)", NGUISettings.atlas, mListBG, OnListBG, GUILayout.Width(120f)); NGUIEditorTools.DrawSpriteField("Highlight", "Sprite used to highlight the selected option", NGUISettings.atlas, mListHL, OnListHL, GUILayout.Width(120f)); } if (ShouldCreate(go, NGUISettings.atlas != null && NGUISettings.ambigiousFont != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = isDropDown ? "Popup List" : "Popup Menu"; UISpriteData sphl = NGUISettings.GetSprite(mListHL); UISpriteData spfg = NGUISettings.GetSprite(mListFG); Vector2 hlPadding = new Vector2(Mathf.Max(4f, sphl.paddingLeft), Mathf.Max(4f, sphl.paddingTop)); Vector2 fgPadding = new Vector2(Mathf.Max(4f, spfg.paddingLeft), Mathf.Max(4f, spfg.paddingTop)); // Background sprite UISprite sprite = NGUITools.AddSprite(go, NGUISettings.atlas as INGUIAtlas, mListFG); sprite.depth = depth; sprite.atlas = NGUISettings.atlas; sprite.pivot = UIWidget.Pivot.Left; sprite.width = Mathf.RoundToInt(150f + fgPadding.x * 2f); sprite.height = Mathf.RoundToInt(NGUISettings.fontSize + fgPadding.y * 2f); sprite.transform.localPosition = Vector3.zero; sprite.MakePixelPerfect(); // Text label UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.ambigiousFont = NGUISettings.ambigiousFont; lbl.fontSize = NGUISettings.fontSize; lbl.fontStyle = NGUISettings.fontStyle; lbl.text = go.name; lbl.pivot = UIWidget.Pivot.Left; lbl.cachedTransform.localPosition = new Vector3(fgPadding.x, 0f, 0f); lbl.AssumeNaturalSize(); // Add a collider NGUITools.AddWidgetCollider(go); // Add the popup list UIPopupList list = go.AddComponent <UIPopupList>(); list.atlas = NGUISettings.atlas as Object; list.ambigiousFont = NGUISettings.ambigiousFont; list.fontSize = NGUISettings.fontSize; list.fontStyle = NGUISettings.fontStyle; list.backgroundSprite = mListBG; list.highlightSprite = mListHL; list.padding = hlPadding; if (isDropDown) { EventDelegate.Add(list.onChange, lbl.SetCurrentSelection); } for (int i = 0; i < 5; ++i) { list.items.Add(isDropDown ? ("List Option " + i) : ("Menu Option " + i)); } // Add the scripts go.AddComponent <UIButton>().tweenTarget = sprite.gameObject; go.AddComponent <UIPlaySound>(); Selection.activeGameObject = go; } }
/// <summary> /// Progress bar creation function. /// </summary> void CreateSlider(GameObject go, bool slider) { if (NGUISettings.atlas != null) { NGUIEditorTools.DrawSpriteField("Empty", "Sprite for the background (empty bar)", NGUISettings.atlas, mSliderBG, OnSliderBG, GUILayout.Width(120f)); NGUIEditorTools.DrawSpriteField("Full", "Sprite for the foreground (full bar)", NGUISettings.atlas, mSliderFG, OnSliderFG, GUILayout.Width(120f)); if (slider) { NGUIEditorTools.DrawSpriteField("Thumb", "Sprite for the thumb indicator", NGUISettings.atlas, mSliderTB, OnSliderTB, GUILayout.Width(120f)); } } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = slider ? "Slider" : "Progress Bar"; // Background sprite var bgs = NGUISettings.GetSprite(mSliderBG); var back = NGUITools.AddWidget <UISprite>(go); back.type = bgs.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple; back.name = "Background"; back.depth = depth; back.pivot = UIWidget.Pivot.Left; back.atlas = NGUISettings.atlas; back.spriteName = mSliderBG; back.width = 200; back.height = 30; back.transform.localPosition = Vector3.zero; back.MakePixelPerfect(); // Foreground sprite UISpriteData fgs = NGUISettings.GetSprite(mSliderFG); UISprite front = NGUITools.AddWidget <UISprite>(go); front.type = fgs.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple; front.name = "Foreground"; front.pivot = UIWidget.Pivot.Left; front.atlas = NGUISettings.atlas; front.spriteName = mSliderFG; front.width = 200; front.height = 30; front.transform.localPosition = Vector3.zero; front.MakePixelPerfect(); // Add a collider if (slider) { NGUITools.AddWidgetCollider(go); } // Add the slider script UISlider uiSlider = go.AddComponent <UISlider>(); uiSlider.foregroundWidget = front; // Thumb sprite if (slider) { UISpriteData tbs = NGUISettings.GetSprite(mSliderTB); UISprite thb = NGUITools.AddWidget <UISprite>(go); thb.type = tbs.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple; thb.name = "Thumb"; thb.atlas = NGUISettings.atlas; thb.spriteName = mSliderTB; thb.width = 20; thb.height = 40; thb.transform.localPosition = new Vector3(200f, 0f, 0f); thb.MakePixelPerfect(); NGUITools.AddWidgetCollider(thb.gameObject); thb.gameObject.AddComponent <UIButtonColor>(); thb.gameObject.AddComponent <UIButtonScale>(); uiSlider.thumb = thb.transform; } uiSlider.value = 1f; // Select the slider Selection.activeGameObject = go; } }
static void PasteStyle(MenuCommand command) { NGUISettings.PasteStyle(command.context as UIWidget); }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties() { mLabel = mWidget as UILabel; GUILayout.BeginHorizontal(); #if DYNAMIC_FONT mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f)); if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f))) #else mFontType = FontType.NGUI; if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f))) #endif { if (mFontType == FontType.NGUI) { ComponentSelector.Show <UIFont>(OnNGUIFont); } else { ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } } bool isValid = false; SerializedProperty fnt = null; SerializedProperty ttf = null; if (mFontType == FontType.NGUI) { GUI.changed = false; fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f)); if (fnt.objectReferenceValue != null) { if (GUI.changed) { serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null; } NGUISettings.ambigiousFont = fnt.objectReferenceValue; isValid = true; } } else { GUI.changed = false; ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f)); if (ttf.objectReferenceValue != null) { if (GUI.changed) { serializedObject.FindProperty("mFont").objectReferenceValue = null; } NGUISettings.ambigiousFont = ttf.objectReferenceValue; isValid = true; } } GUILayout.EndHorizontal(); if (mFontType == FontType.Unity) { EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" + "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning); } if (GUILayout.Button("字 体 样 式")) { NGUISettings.SetInt("NGUI Prefab Tab", 1); EditorWindow.GetWindow <UIPrefabTool>(false, "Prefab Toolbar", true).Show(); } EditorGUI.BeginDisabledGroup(!isValid); { UIFont uiFont = (fnt != null) ? fnt.objectReferenceValue as UIFont : null; Font dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null; if (uiFont != null && uiFont.isDynamic) { dynFont = uiFont.dynamicFont; uiFont = null; } if (dynFont != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); NGUISettings.fontSize = prop.intValue; prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f)); NGUISettings.fontStyle = (FontStyle)prop.intValue; NGUIEditorTools.DrawPadding(); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial"); } else if (uiFont != null) { GUILayout.BeginHorizontal(); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); EditorGUI.BeginDisabledGroup(true); if (!serializedObject.isEditingMultipleObjects) { if (mLabel.overflowMethod == UILabel.Overflow.ShrinkContent) { GUILayout.Label(" Actual: " + mLabel.finalFontSize + "/" + mLabel.defaultFontSize); } else { GUILayout.Label(" Default: " + mLabel.defaultFontSize); } } EditorGUI.EndDisabledGroup(); NGUISettings.fontSize = prop.intValue; GUILayout.EndHorizontal(); } bool ww = GUI.skin.textField.wordWrap; GUI.skin.textField.wordWrap = true; SerializedProperty sp = serializedObject.FindProperty("mText"); if (sp.hasMultipleDifferentValues) { NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f)); } else { GUIStyle style = new GUIStyle(EditorStyles.textField); style.wordWrap = true; float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f); bool offset = true; if (height > 90f) { offset = false; height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(76f)); GUILayout.Space(3f); GUILayout.Label("Text"); GUILayout.EndVertical(); GUILayout.BeginVertical(); } Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height)); GUI.changed = false; string text = EditorGUI.TextArea(rect, sp.stringValue, style); if (GUI.changed) { sp.stringValue = text; } if (offset) { GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } GUI.skin.textField.wordWrap = ww; NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier"); SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow"); NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue; if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent) { NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f)); } if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely) { GUILayout.BeginHorizontal(); SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth"); if (s != null && s.intValue < 1) { GUILayout.Label("unlimited"); } GUILayout.EndHorizontal(); } NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment"); if (dynFont != null) { NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk"); } EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader); GUILayout.BeginHorizontal(); SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", GUILayout.Width(95f)); EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue); { NGUIEditorTools.SetLabelWidth(30f); NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(50f); GUILayout.Space(79f); NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f)); NGUIEditorTools.SetLabelWidth(80f); } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Effect", GUILayout.Width(76f)); sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f)); EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue); { NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(" ", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); } } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f)); if (!sp.boolValue) { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); GUILayout.BeginHorizontal(); sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f)); EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols); NGUIEditorTools.SetLabelWidth(60f); NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols"); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); return(isValid); }
// CheckSourceFolder #endregion #region CreateNewAtlas /// <summary> /// Create a new atlas /// </summary> /// <param name="psdAssetFolderPath"></param> /// <returns></returns> public static UIAtlas CreateNewAtlas(string psdAssetFolderPath) { CheckSourceFolder(psdAssetFolderPath); string prefabPath = string.Empty, matPath = string.Empty; string AtlasName = PsdImporter.NSettingsAtlasName; // 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 == NGUISettings.GetString(AtlasName, string.Empty)) { prefabPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.gameObject.GetInstanceID()); if (NGUISettings.atlas.spriteMaterial != null) { matPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.spriteMaterial.GetInstanceID()); } } // Assume default values if needed NGUISettings.SetString(AtlasName, PsdImporter.ObjPSDFolderToLoad.name); if (string.IsNullOrEmpty(prefabPath)) { prefabPath = string.Format("{0}{1}.prefab", PsdImporter.SourceFolder, AtlasName); } if (string.IsNullOrEmpty(matPath)) { matPath = string.Format("{0}{1}.mat", PsdImporter.SourceFolder, AtlasName); } // 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>(); } // 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) { mat = new Material(Shader.Find(STR_UnlitTransparentColored)); // Save the material AssetDatabase.CreateAsset(mat, matPath); AssetDatabase.Refresh(); // Load the material so it's usable mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; } // create atlas if one is not already loaded if (NGUISettings.atlas == null || NGUISettings.atlas.name != AtlasName) { // Create a new prefab for the atlas Object prefab = 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>(); } return(go.GetComponent <UIAtlas>()); }