public override void OnInspectorGUI() { effect = target as MeshEffect; EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; NGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false); }
override public void OnInspectorGUI() { this.DrawDefaultInspector(); var rotator = target as NGUISpriteRotator; if (rotator.Atlas != null) { GUILayout.BeginVertical(); NGUIEditorTools.DrawAdvancedSpriteField(rotator.Atlas, "", _SelectSprite, false); foreach (var spriteName in rotator.SpriteNames) { GUILayout.BeginHorizontal(); GUILayout.Label(spriteName); if (GUILayout.Button("x")) { rotator.Remove(spriteName); } GUILayout.EndHorizontal(); } if (GUILayout.Button("Test Next")) { rotator.Next(); } GUILayout.EndVertical(); } }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected override bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; NGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false); return(true); }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected override bool ShouldDrawProperties() { var atlasProp = serializedObject.FindProperty("mAtlas"); var obj = atlasProp.objectReferenceValue; var atlas = obj as INGUIAtlas; GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show(atlas, OnSelectAtlas); } atlasProp = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f)) && atlas != null) { NGUISettings.atlas = atlas; NGUIEditorTools.Select(atlas as Object); } // Legacy atlas support if (atlasProp.objectReferenceValue != null && atlasProp.objectReferenceValue is GameObject) { atlasProp.objectReferenceValue = (atlasProp.objectReferenceValue as GameObject).GetComponent <UIAtlas>(); } GUILayout.EndHorizontal(); var sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas, sp.stringValue, SelectSprite, false); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat"); return(true); }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected override bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; if (atl != null) { NGUIEditorTools.Select(atl.gameObject); } } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false); //change by zhehua //NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat"); if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; if (atl != null) { if (atl.spriteMaterial != null) { EditorGUILayout.LabelField("Sprite Material Name : " + atl.spriteMaterial.name, GUILayout.MinWidth(100f)); } int effectMatDicCount = (atl.effectMatDic == null) ? 0 : atl.effectMatDic.Count; EditorGUILayout.LabelField("Effect Material Count : " + effectMatDicCount, GUILayout.MinWidth(100f)); if (effectMatDicCount > 0) { foreach (string key in atl.effectMatDic.Keys) { if (atl.effectMatDic[key] == null) { atl.DestroyAllEffectMaterials(); break; } EditorGUILayout.LabelField(" " + atl.effectMatDic[key].name, GUILayout.MinWidth(100f)); } } } } return(true); }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected override bool ShouldDrawProperties() { var atlasProp = serializedObject.FindProperty("mAtlas"); var obj = atlasProp.objectReferenceValue; var atlas = obj as INGUIAtlas; GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show(atlas, OnSelectAtlas); } atlasProp = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f)) && atlas != null) { NGUISettings.atlas = atlas; NGUIEditorTools.Select(atlas as Object); } // Legacy atlas support if (atlasProp.objectReferenceValue != null && atlasProp.objectReferenceValue is GameObject) { atlasProp.objectReferenceValue = (atlasProp.objectReferenceValue as GameObject).GetComponent <UIAtlas>(); } GUILayout.EndHorizontal(); var sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas, sp.stringValue, SelectSprite, false); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat"); SerializedProperty fa = serializedObject.FindProperty("mFixedAspect"); bool before = fa.boolValue; NGUIEditorTools.DrawProperty("Fixed Aspect", fa); if (fa.boolValue != before) { (target as UIWidget).drawRegion = new Vector4(0f, 0f, 1f, 1f); } if (fa.boolValue) { EditorGUILayout.HelpBox("Note that Fixed Aspect mode is not compatible with Draw Region modifications done by sliders and progress bars.", MessageType.Info); } return(true); }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> override protected bool OnDrawProperties() { mSprite = mWidget as UISprite; mSprite.IsKeepOriSize = EditorGUILayout.Toggle("保持原图大小", mSprite.IsKeepOriSize, GUILayout.Width(100f)); ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas); if (mSprite.atlas == null) { return(false); } SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUISettings.atlas = mSprite.atlas; //NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false); NGUIEditorTools.DrawAdvancedSpriteField(NGUISettings.atlas, sp.stringValue, SelectSprite, false); return(true); }
protected bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <AtlasSheet>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Rand", GUILayout.Width(40f))) { if (atlas != null && Selection.objects.Length > 0) { AtlasSheet atl = atlas.objectReferenceValue as AtlasSheet; foreach (var sprite_obj in Selection.gameObjects) { AtlasSprite sprite = sprite_obj.GetComponent <AtlasSprite>(); sprite.spriteName = atl.Atlas.spriteList[UnityEngine.Random.Range(0, atl.Atlas.spriteList.Count - 1)].name; } } } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { AtlasSheet atl = atlas.objectReferenceValue as AtlasSheet; NGUISettings.atlas = atl.Atlas; NGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField((atlas.objectReferenceValue as AtlasSheet).Atlas, sp.stringValue, SelectSprite, false); return(true); }
// copy from UISpriteInspector void ShowParticleSprite() { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(obj => { serializedObject.Update(); SerializedProperty spNew = serializedObject.FindProperty("Atlas"); spNew.objectReferenceValue = obj; serializedObject.ApplyModifiedProperties(); NGUITools.SetDirty(serializedObject.targetObject); NGUISettings.atlas = obj as UIAtlas; }); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "Atlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; NGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("SpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, spriteName => { serializedObject.Update(); SerializedProperty spNew = serializedObject.FindProperty("SpriteName"); spNew.stringValue = spriteName; serializedObject.ApplyModifiedProperties(); NGUITools.SetDirty(serializedObject.targetObject); NGUISettings.selectedSprite = spriteName; }, false); }
// Start is called before the first frame update public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); EditorGUILayout.Space(); serializedObject.Update(); //Atlas GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; NGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false); if (GUILayout.Button("Refresh")) { var it = target as ParticleSystemExt; it.RefreshParticleSystem(); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { FXBillboard billboard = target as FXBillboard; //////////////////////////////////////////////////////////////////////////////// /// Atlas Settings GUILayout.BeginHorizontal(); GUILayout.Label("Atlas Type", GUILayout.Width(76f)); FXAtlasType atlas_type = (FXAtlasType)EditorGUILayout.EnumPopup("", billboard.AtlasType); GUILayout.EndHorizontal(); if (atlas_type != billboard.AtlasType) { billboard.AtlasType = atlas_type; } // if (atlas_type == FXAtlasType.Static) { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas_prop = NGUIEditorTools.DrawProperty("", serializedObject, "m_Atlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas_prop != null) { UIAtlas atlas = atlas_prop.objectReferenceValue as UIAtlas; NGUISettings.atlas = atlas; NGUIEditorTools.Select(atlas.gameObject); } } if (atlas_prop != null) { UIAtlas atlas = atlas_prop.objectReferenceValue as UIAtlas; if (billboard.atlas != atlas) { billboard.atlas = atlas; } } GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Sprite Settings SerializedProperty sprite_name_prop = serializedObject.FindProperty("m_SpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas_prop.objectReferenceValue as UIAtlas, sprite_name_prop.stringValue, SelectSprite, false); } else if (atlas_type == FXAtlasType.Dynamic) { GUILayout.BeginHorizontal(); GUILayout.Label("Atlas", GUILayout.Width(76f)); eDynamicAtlasType dynamic_atlas_type = (eDynamicAtlasType)EditorGUILayout.EnumPopup("", billboard.dynamicAtlasType); GUILayout.EndHorizontal(); if (dynamic_atlas_type != billboard.dynamicAtlasType) { billboard.dynamicAtlasType = dynamic_atlas_type; } GUILayout.BeginHorizontal(); GUILayout.Label("Sprite", GUILayout.Width(76f)); SerializedProperty sprite_name_prop = NGUIEditorTools.DrawProperty("", serializedObject, "m_SpriteName", GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); billboard.spriteName = sprite_name_prop.stringValue; } //////////////////////////////////////////////////////////////////////////////// /// From Color GUILayout.BeginHorizontal(); GUILayout.Label("From Color", GUILayout.Width(76f)); SerializedProperty from_color_prop = NGUIEditorTools.DrawProperty("", serializedObject, "FromColor", GUILayout.MinWidth(10f)); billboard.FromColor = from_color_prop.colorValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// To Color GUILayout.BeginHorizontal(); GUILayout.Label("To Color", GUILayout.Width(76f)); SerializedProperty to_color_prop = NGUIEditorTools.DrawProperty("", serializedObject, "ToColor", GUILayout.MinWidth(10f)); billboard.ToColor = to_color_prop.colorValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// From Size GUILayout.BeginHorizontal(); GUILayout.Label("From Size", GUILayout.Width(76f)); SerializedProperty from_size_prop = NGUIEditorTools.DrawProperty("", serializedObject, "FromSize", GUILayout.MinWidth(10f)); billboard.FromSize = from_size_prop.floatValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// To Size GUILayout.BeginHorizontal(); GUILayout.Label("To Size", GUILayout.Width(76f)); SerializedProperty to_size_prop = NGUIEditorTools.DrawProperty("", serializedObject, "ToSize", GUILayout.MinWidth(10f)); billboard.ToSize = to_size_prop.floatValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Tile X GUILayout.BeginHorizontal(); GUILayout.Label("Tile X", GUILayout.Width(76f)); SerializedProperty tilte_x_prop = NGUIEditorTools.DrawProperty("", serializedObject, "TileX", GUILayout.MinWidth(10f)); billboard.TileX = tilte_x_prop.intValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Tile Y GUILayout.BeginHorizontal(); GUILayout.Label("Tile Y", GUILayout.Width(76f)); SerializedProperty tilte_y_prop = NGUIEditorTools.DrawProperty("", serializedObject, "TileY", GUILayout.MinWidth(10f)); billboard.TileY = tilte_y_prop.intValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Max Frames GUILayout.BeginHorizontal(); GUILayout.Label("Max Frames", GUILayout.Width(76f)); SerializedProperty max_frames_prop = NGUIEditorTools.DrawProperty("", serializedObject, "MaxFrames", GUILayout.MinWidth(10f)); billboard.MaxFrames = max_frames_prop.intValue; GUILayout.EndHorizontal(); //////////////////////////////////////////////////////////////////////////////// /// Duration GUILayout.BeginHorizontal(); GUILayout.Label("Duration", GUILayout.Width(76f)); SerializedProperty duration_prop = NGUIEditorTools.DrawProperty("", serializedObject, "Duration", GUILayout.MinWidth(10f)); billboard.Duration = duration_prop.floatValue; GUILayout.EndHorizontal(); }
void DisplayCombatUnit() { _combatUnitFoldout = EditorGUILayout.Foldout(_combatUnitFoldout, new GUIContent("Combat unit", "Combat unit's image")); ++EditorGUI.indentLevel; if (_combatUnitFoldout) { int indexToRemoved = -1; //render each combat unit for (int i = 0; i < _target.combatUnitType.Count; i++) { EditorGUILayout.BeginHorizontal(); _combatUnitTypeFoldout[i] = EditorGUILayout.Foldout(_combatUnitTypeFoldout[i], _target.combatUnitType[i].ToString()); GUI.color = Color.red; if (GUILayout.Button(new GUIContent("X", "Delete combat unit type"), GUILayout.Width(30f))) { if (EditorUtility.DisplayDialogComplex("Delete this combat unit?", "Delete combat unit type " + _target.combatUnitType[i].ToString() + "?", "Ok", "Cancel", "") == 0) { indexToRemoved = i; } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (_combatUnitTypeFoldout[i]) { //set current working index combatUnitWorkingIndex = i; //only edit one at a time for (int j = 0; j < _combatUnitTypeFoldout.Count; j++) { if (i != j) { _combatUnitTypeFoldout[j] = false; } } ++EditorGUI.indentLevel; EditorGUILayout.Space(); //type EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Type:", "Combat unit type")); _target.combatUnitType[i] = (CombatUnitType)EditorGUILayout.EnumPopup(_target.combatUnitType[i]); EditorGUILayout.EndHorizontal(); //head image EditorGUILayout.LabelField(new GUIContent("Head image:", "Combat unit's head image")); EditorGUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlasForHead); } SerializedProperty headAtlas = serializedObject.FindProperty("combatUnitHeadAtlas").GetArrayElementAtIndex(i); NGUIEditorTools.DrawProperty("", headAtlas, GUILayout.MinWidth(20f)); EditorGUILayout.EndHorizontal(); NGUIEditorTools.DrawAdvancedSpriteField(headAtlas.objectReferenceValue as UIAtlas, _target.combatUnitHeadSpriteName[i], SelectSpriteForHead, false); if (string.IsNullOrEmpty(_target.combatUnitHeadSpriteName[i])) { EditorGUILayout.HelpBox("Please select a image for combat unit's head", MessageType.Error); } EditorGUILayout.Space(); //full body image EditorGUILayout.LabelField(new GUIContent("Full Body image:", "Combat unit's full body image")); EditorGUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlasForFullBody); } SerializedProperty fullBodyAtlas = serializedObject.FindProperty("combatunitFullBodyAtlas").GetArrayElementAtIndex(i); NGUIEditorTools.DrawProperty("", fullBodyAtlas, GUILayout.MinWidth(20f)); EditorGUILayout.EndHorizontal(); NGUIEditorTools.DrawAdvancedSpriteField(fullBodyAtlas.objectReferenceValue as UIAtlas, _target.combatUnitFullBodySpriteName[i], SelectSpriteForFullBody, false); if (string.IsNullOrEmpty(_target.combatUnitFullBodySpriteName[i])) { EditorGUILayout.HelpBox("Please select a image for combat unit's full body", MessageType.Error); } --EditorGUI.indentLevel; } } if (indexToRemoved >= 0) { _target.combatUnitType.RemoveAt(indexToRemoved); _target.combatUnitHeadSpriteName.RemoveAt(indexToRemoved); _target.combatUnitFullBodySpriteName.RemoveAt(indexToRemoved); _target.combatUnitHeadAtlas.RemoveAt(indexToRemoved); _target.combatunitFullBodyAtlas.RemoveAt(indexToRemoved); _combatUnitTypeFoldout.RemoveAt(indexToRemoved); serializedObject.Update(); } GUI.color = Color.green; if (GUILayout.Button(new GUIContent("+", "Add new combat unit's image"))) { _target.combatUnitType.Add(CombatUnitType.Unknow); _target.combatUnitHeadSpriteName.Add(""); _target.combatUnitFullBodySpriteName.Add(""); _target.combatUnitHeadAtlas.Add(NGUISettings.atlas); _target.combatunitFullBodyAtlas.Add(NGUISettings.atlas); _combatUnitTypeFoldout.Add(false); serializedObject.Update(); } GUI.color = Color.white; } --EditorGUI.indentLevel; }
void DisplayResource() { _resourceFoldout = EditorGUILayout.Foldout(_resourceFoldout, new GUIContent("Resource", "Resource type's image")); ++EditorGUI.indentLevel; if (_resourceFoldout) { int indexToRemoved = -1; //render each resource for (int i = 0; i < _target.resourceType.Count; i++) { EditorGUILayout.BeginHorizontal(); _resourceTypeFoldout[i] = EditorGUILayout.Foldout(_resourceTypeFoldout[i], new GUIContent(_target.resourceType[i].ToString(), "Resource type's image")); GUI.color = Color.red; if (GUILayout.Button(new GUIContent("X", "Delete resource type"), GUILayout.Width(30f))) { if (EditorUtility.DisplayDialogComplex("Delete this resource?", "Delete resource type " + _target.resourceType[i].ToString() + "?", "Ok", "Cancel", "") == 0) { indexToRemoved = i; } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (_resourceTypeFoldout[i]) { resourceWorkingIndex = i; for (int j = 0; j < _resourceTypeFoldout.Count; j++) { if (i != j) { _resourceTypeFoldout[j] = false; } } ++EditorGUI.indentLevel; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Type:")); _target.resourceType[i] = (ResourceType)EditorGUILayout.EnumPopup(_target.resourceType[i]); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //Resource image EditorGUILayout.LabelField(new GUIContent("Resource image:", "Resource type's image")); EditorGUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlasForResource); } SerializedProperty resourceAtlas = serializedObject.FindProperty("resourceAtlas").GetArrayElementAtIndex(i); NGUIEditorTools.DrawProperty("", resourceAtlas, GUILayout.MinWidth(20f)); EditorGUILayout.EndHorizontal(); NGUIEditorTools.DrawAdvancedSpriteField(resourceAtlas.objectReferenceValue as UIAtlas, _target.resourceSpriteName[i], SelectSpriteForResource, false); if (string.IsNullOrEmpty(_target.resourceSpriteName[i])) { EditorGUILayout.HelpBox("Please select a image for resource type", MessageType.Error); } --EditorGUI.indentLevel; } } if (indexToRemoved >= 0) { _target.resourceType.RemoveAt(indexToRemoved); _target.resourceSpriteName.RemoveAt(indexToRemoved); _target.resourceAtlas.RemoveAt(indexToRemoved); _resourceTypeFoldout.RemoveAt(indexToRemoved); serializedObject.Update(); } GUI.color = Color.green; if (GUILayout.Button(new GUIContent("+", "Add new resource image"))) { _target.resourceType.Add(ResourceType.Unknow); _target.resourceSpriteName.Add(""); _target.resourceAtlas.Add(NGUISettings.atlas); _resourceTypeFoldout.Add(false); serializedObject.Update(); } GUI.color = Color.white; } --EditorGUI.indentLevel; }
public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); GUILayout.Space(6f); var type = mFont.type; if (type == NGUIFontType.Reference) { mReplacement = mFont.replacement; } GUI.changed = false; GUILayout.BeginHorizontal(); type = (NGUIFontType)EditorGUILayout.EnumPopup("Font Type", type); GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Font Change", mFont as Object); mFont.type = type; NGUITools.SetDirty(mFont as Object); } if (type == NGUIFontType.Reference) { ComponentSelector.Draw(mFont.replacement, OnSelectFont, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("Reference fonts will have their font data come from another one. " + "This allows you to have your labels reference a font that has all the emoticons, that also points to a secondary font containing the actual glyph data " + "that can be easily swapped at run-time with a font containing glyphs of another language.", MessageType.Info); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont as Object); mFont.replacement = mReplacement; NGUITools.SetDirty(mFont as Object); } } if (type == NGUIFontType.Dynamic) { #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font; if (fnt != mFont.dynamicFont) { NGUIEditorTools.RegisterUndo("Font change", mFont as Object); mFont.dynamicFont = fnt; } var mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont as Object); mFont.material = mat; } #endif } if (type == NGUIFontType.Bitmap) { ComponentSelector.Draw(mFont.atlas, OnSelectAtlas, true); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } } else { // No atlas specified -- set the material and texture rectangle directly var mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont as Object); mFont.material = mat; } } } if (type != NGUIFontType.Reference) { GUI.changed = false; //EditorGUI.BeginDisabledGroup(mFont.isDynamic); var size = EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f)); //EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal(); int space = EditorGUILayout.IntField("Space Width", mFont.spaceWidth, GUILayout.Width(120f)); if (space == 0) { GUILayout.Label("(default)"); } GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Font change", mFont as Object); mFont.spaceWidth = space; mFont.defaultSize = size; var labels = NGUITools.FindActive <UILabel>(); foreach (UILabel lbl in labels) { if (lbl.font == null) { continue; } var font = lbl.font; if (NGUITools.CheckIfRelated(font, mFont)) { lbl.font = null; lbl.font = font; NGUITools.SetDirty(lbl); } } } EditorGUILayout.Space(); } if (type == NGUIFontType.Dynamic || type == NGUIFontType.Reference) { var font = mFont as NGUIFont; if (font != null) { if (NGUIEditorTools.DrawHeader("Symbol Atlas")) { NGUIEditorTools.BeginContents(); ComponentSelector.Draw(font.symbolAtlas, OnSelectSymbolAtlas, true); NGUIEditorTools.EndContents(); } EditorGUILayout.Space(); } } // For updating the font's data when importing from an external source, such as the texture packer bool resetWidthHeight = false; if (type == NGUIFontType.Bitmap && (mFont.atlas != null || mFont.material != null)) { if (NGUIEditorTools.DrawHeader("Import")) { NGUIEditorTools.BeginContents(); var data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont as Object); BMFontReader.Load(mFont.bmFont, (mFont as Object).name, data.bytes); mFont.MarkAsChanged(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } NGUIEditorTools.EndContents(); } EditorGUILayout.Space(); } if (mFont is UIFont && mFont.bmFont.isValid) { EditorGUILayout.HelpBox("Legacy font type should be upgraded in order to maintain compatibility with Unity 2018 and newer.", MessageType.Warning, true); if (GUILayout.Button("Upgrade")) { var path = EditorUtility.SaveFilePanelInProject("Save As", (mFont as Object).name + ".asset", "asset", "Save font as...", NGUISettings.currentPath); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); var asset = ScriptableObject.CreateInstance <NGUIFont>(); asset.bmFont = mFont.bmFont; asset.symbols = mFont.symbols; asset.atlas = mFont.atlas; asset.spriteName = mFont.spriteName; asset.uvRect = mFont.uvRect; asset.defaultSize = mFont.defaultSize; var fontName = path.Replace(".asset", ""); fontName = fontName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1); asset.name = fontName; var existing = AssetDatabase.LoadMainAssetAtPath(path); if (existing != null) { EditorUtility.CopySerialized(asset, existing); } else { AssetDatabase.CreateAsset(asset, path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); asset = AssetDatabase.LoadAssetAtPath <NGUIFont>(path); NGUISettings.ambigiousFont = asset; Selection.activeObject = asset; if (asset != null) { mFont.replacement = asset; mFont.MarkAsChanged(); } } } } if (type == NGUIFontType.Bitmap && mFont.bmFont.isValid) { Texture2D tex = mFont.texture; if (tex != null && mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle pixels = EditorGUILayout.RectField("Pixel Rect", pixels); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont as Object); mFont.uvRect = uvRect; } //NGUIEditorTools.DrawSeparator(); EditorGUILayout.Space(); } } var nguiFont = mFont as NGUIFont; var symbolAtlas = (nguiFont != null) ? nguiFont.symbolAtlas : null; if (symbolAtlas == null && type != NGUIFontType.Reference) { symbolAtlas = mFont.atlas; } if (symbolAtlas != null && NGUIEditorTools.DrawHeader("Symbols and Emoticons")) { NGUIEditorTools.BeginContents(); var symbols = mFont.symbols; for (int i = 0; i < symbols.Count;) { var sym = symbols[i]; GUILayout.BeginHorizontal(); GUILayout.Label(sym.sequence, GUILayout.Width(40f)); if (NGUIEditorTools.DrawSpriteField(symbolAtlas, sym.spriteName, ChangeSymbolSprite, GUILayout.MinWidth(100f))) { mSelectedSymbol = sym; } var col = GUILayout.Toggle(sym.colored, new GUIContent(""), GUILayout.Width(16f)); if (col != sym.colored) { sym.colored = col; mFont.MarkAsChanged(); } if (GUILayout.Button("Edit", GUILayout.Width(40f)) && symbolAtlas != null) { NGUISettings.atlas = symbolAtlas; NGUISettings.selectedSprite = sym.spriteName; NGUIEditorTools.Select(symbolAtlas as Object); } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove symbol", mFont as Object); mSymbolSequence = sym.sequence; mSymbolSprite = sym.spriteName; symbols.Remove(sym); mFont.MarkAsChanged(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); //GUILayout.Space(4f); ++i; } if (symbols.Count > 0) { if (Event.current.type == EventType.Repaint) { Texture2D tex = NGUIEditorTools.blankTexture; Rect rect = GUILayoutUtility.GetLastRect(); GUI.color = new Color(0f, 0f, 0f, 0.25f); GUI.DrawTexture(new Rect(20f, rect.yMin + 28f, Screen.width - 30f, 1f), tex); GUI.color = Color.white; } GUILayout.Space(10f); } GUILayout.BeginHorizontal(); mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f)); NGUIEditorTools.DrawSpriteField(symbolAtlas, mSymbolSprite, SelectSymbolSprite); bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add symbol", mFont as Object); var sym = mFont.AddSymbol(mSymbolSequence, mSymbolSprite); sym.colored = mSymbolColored; mFont.MarkAsChanged(); mSymbolSequence = ""; mSymbolSprite = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); NGUIEditorTools.SetLabelWidth(42f); GUILayout.BeginHorizontal(); mSymbolColored = EditorGUILayout.Toggle("Tinted", mSymbolColored, GUILayout.Width(60f)); GUILayout.Label("- affected by label's color by default"); GUILayout.EndHorizontal(); NGUIEditorTools.SetLabelWidth(80f); 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); } if (nguiFont != null) { if (Event.current.type == EventType.Repaint) { Texture2D tex = NGUIEditorTools.blankTexture; Rect rect = GUILayoutUtility.GetLastRect(); GUI.color = new Color(0f, 0f, 0f, 0.25f); GUI.DrawTexture(new Rect(20f, rect.yMin + 6f, Screen.width - 30f, 1f), tex); GUI.color = Color.white; } GUILayout.Space(6f); GUI.changed = false; GUILayout.BeginHorizontal(); GUILayout.Label("Scale", GUILayout.Width(40f)); var scale = EditorGUILayout.FloatField(nguiFont.symbolScale, GUILayout.Width(50f)); GUILayout.Label("- scaling multiplier"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Offset", GUILayout.Width(40f)); var offset = EditorGUILayout.IntField(nguiFont.symbolOffset, GUILayout.Width(50f)); GUILayout.Label("- vertical offset"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Height", GUILayout.Width(40f)); var height = EditorGUILayout.IntField(nguiFont.symbolMaxHeight, GUILayout.Width(50f)); GUILayout.Label("- maximum sprite height"); GUILayout.EndHorizontal(); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Change symbol values", mFont as Object); nguiFont.symbolScale = scale; nguiFont.symbolOffset = offset; nguiFont.symbolMaxHeight = height; nguiFont.MarkAsChanged(); } } NGUIEditorTools.EndContents(); } if (type == NGUIFontType.Bitmap && 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(); } } if (mFont.atlas == null) { mView = View.Font; mUseShader = false; } // Preview option if (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() { 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; } 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, 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; 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 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); GUILayout.Space(18f); 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 { NGUIEditorTools.DrawSeparator(); 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 GUI.backgroundColor = new Color(0.4f, 1f, 0f, 1f); 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(); { NGUIEditorTools.SetLabelWidth(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); NGUIEditorTools.SetLabelWidth(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) { 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)) { mSelectedSymbol = sym; } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (mFont.atlas != null) { 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(); } } } }
/// <summary> /// Draw a sprite selection field. /// </summary> static public void SpriteField(string fieldName, string caption, UIAtlas atlas, string spriteName, SpriteSelector.Callback callback) { NGUIEditorTools.DrawAdvancedSpriteField(atlas, spriteName, callback, false); }
protected override bool OnSearchGUI() { if (!mAtlas) { mAtlas = NGUISettings.atlas; } ComponentSelector.Draw <UIAtlas>("Atlas", mAtlas, obj => { if (mAtlas != obj) { mAtlas = obj as UIAtlas; } }, true, GUILayout.MinWidth(80f)); if (!mAtlas) { mSprites = new string[0]; return(false); } GUILayout.BeginHorizontal(); GUILayout.Space(5F); EditorGUILayout.BeginVertical(); if (NGUIEditorTools.DrawMinimalisticHeader("Sprites")) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(15F); EditorGUILayout.BeginVertical(); GUILayout.Space(2F); int newLength = EditorGUILayout.IntField("Size", mSprites.Length); int oldLength = mSprites.Length; if (newLength != oldLength) { int minLength = Mathf.Min(newLength, oldLength); string[] sprites = new string[newLength]; for (int i = 0; i < minLength; i++) { sprites[i] = mSprites[i]; } mSprites = sprites; } for (int i = 0; i < mSprites.Length; i++) { int index = i; NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, mSprites[index], spriteName => { mSprites[index] = spriteName; Repaint(); }, false); } GUILayout.Space(2F); EditorGUILayout.EndVertical(); GUILayout.Space(3F); EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(10F); GUILayout.BeginHorizontal(); GUILayout.Space(10F); bool search = GUILayout.Button("Search"); GUILayout.Space(10F); GUILayout.EndHorizontal(); return(search); }
private void OnGUI() { if (!mAtlas) { mAtlas = NGUISettings.atlas; } ComponentSelector.Draw <UIAtlas>("Atlas", mAtlas, obj => { if (mAtlas != obj) { mAtlas = obj as UIAtlas; } }, true, GUILayout.MinWidth(80f)); if (!mAtlas) { mSprites = new string[0]; } else { GUILayout.BeginHorizontal(); GUILayout.Space(5F); EditorGUILayout.BeginVertical(); if (NGUIEditorTools.DrawMinimalisticHeader("Sprites")) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(15F); EditorGUILayout.BeginVertical(); GUILayout.Space(2F); int newLength = EditorGUILayout.IntField("Size", mSprites.Length); int oldLength = mSprites.Length; if (newLength != oldLength) { int minLength = Mathf.Min(newLength, oldLength); string[] sprites = new string[newLength]; for (int i = 0; i < minLength; i++) { sprites[i] = mSprites[i]; } mSprites = sprites; } for (int i = 0; i < mSprites.Length; i++) { int index = i; NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, mSprites[index], spriteName => { mSprites[index] = spriteName; Repaint(); }, false); } GUILayout.Space(2F); EditorGUILayout.EndVertical(); GUILayout.Space(3F); EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(10F); } GUILayout.BeginHorizontal(); GUILayout.Space(10F); bool start = GUILayout.Button("Create/Update Materials"); GUILayout.Space(10F); GUILayout.EndHorizontal(); if (start && mAtlas && mSprites.Length > 0) { string atlasPath = AssetDatabase.GetAssetPath(mAtlas); string dirPath = atlasPath.Replace("/UIAtlas/", "/Materials/").Replace(".prefab", "/"); DirectoryInfo dir = new DirectoryInfo(dirPath); if (!dir.Exists) { dir.Create(); } bool anyAssetsChanged = false; UISpriteData[] spriteDatas = new UISpriteData[mSprites.Length]; for (int index = 0; index < mSprites.Length; index++) { string spriteName = mSprites[index]; if (!string.IsNullOrEmpty(spriteName)) { UISpriteData spriteData = mAtlas.GetSprite(spriteName); if (spriteData != null) { string path = dirPath + spriteName + ".mat"; bool exist = File.Exists(path); Material mat = exist ? AssetDatabase.LoadAssetAtPath <Material>(path) : new Material(mAtlas.spriteMaterial); float scaleX = (float)spriteData.width / mAtlas.width; float scaleY = (float)spriteData.height / mAtlas.height; float offsetX = (float)spriteData.x / mAtlas.width; float offsetY = (float)(mAtlas.height - spriteData.y - spriteData.height) / mAtlas.height; mat.SetTextureScale("_MainTex", new Vector2(scaleX, scaleY)); mat.SetTextureOffset("_MainTex", new Vector2(offsetX, offsetY)); if (exist) { anyAssetsChanged = true; } else { AssetDatabase.CreateAsset(mat, path); } } } } if (anyAssetsChanged) { AssetDatabase.SaveAssets(); } } }
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); GUILayout.Space(18f); 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); GUILayout.Space(18f); 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; ClientLog.Instance.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(); } }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties() { mRichTextLabel = mWidget as UIRichTextLabel; GUILayout.BeginHorizontal(); #if DYNAMIC_FONT mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f)); if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f))) #else mFontType = FontType.NGUI; if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f))) #endif { if (mFontType == FontType.NGUI) { ComponentSelector.Show <UIFont>(OnNGUIFont); } else { ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } } bool isValid = false; SerializedProperty fnt = null; SerializedProperty ttf = null; if (mFontType == FontType.NGUI) { GUI.changed = false; fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f)); if (fnt.objectReferenceValue != null) { if (GUI.changed) { serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null; } NGUISettings.ambigiousFont = fnt.objectReferenceValue; isValid = true; } } else { GUI.changed = false; ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f)); if (ttf.objectReferenceValue != null) { if (GUI.changed) { serializedObject.FindProperty("mFont").objectReferenceValue = null; } NGUISettings.ambigiousFont = ttf.objectReferenceValue; isValid = true; } } GUILayout.EndHorizontal(); if (mFontType == FontType.Unity) { EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" + "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning); } NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat"); EditorGUI.BeginDisabledGroup(!isValid); { UIFont uiFont = (fnt != null) ? fnt.objectReferenceValue as UIFont : null; Font dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null; if (uiFont != null && uiFont.isDynamic) { dynFont = uiFont.dynamicFont; uiFont = null; } if (dynFont != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); NGUISettings.fontSize = prop.intValue; prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f)); NGUISettings.fontStyle = (FontStyle)prop.intValue; NGUIEditorTools.DrawPadding(); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); } else if (uiFont != null) { GUILayout.BeginHorizontal(); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); EditorGUI.BeginDisabledGroup(true); if (!serializedObject.isEditingMultipleObjects) { if (mRichTextLabel.overflowMethod == UIRichTextLabel.Overflow.ShrinkContent) { GUILayout.Label(" Actual: " + mRichTextLabel.finalFontSize + "/" + mRichTextLabel.defaultFontSize); } else { GUILayout.Label(" Default: " + mRichTextLabel.defaultFontSize); } } EditorGUI.EndDisabledGroup(); NGUISettings.fontSize = prop.intValue; GUILayout.EndHorizontal(); } bool ww = GUI.skin.textField.wordWrap; GUI.skin.textField.wordWrap = true; SerializedProperty sp = serializedObject.FindProperty("mText"); if (sp.hasMultipleDifferentValues) { NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f)); } else { GUIStyle style = new GUIStyle(EditorStyles.textField); style.wordWrap = true; float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f); bool offset = true; if (height > 90f) { offset = false; height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(76f)); GUILayout.Space(3f); GUILayout.Label("Text"); GUILayout.EndVertical(); GUILayout.BeginVertical(); } Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height)); GUI.changed = false; string text = EditorGUI.TextArea(rect, sp.stringValue, style); if (GUI.changed) { sp.stringValue = text; } if (offset) { GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } GUI.skin.textField.wordWrap = ww; NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier"); SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow"); NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue; if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent) { NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f)); } if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely) { GUILayout.BeginHorizontal(); SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth"); if (s != null && s.intValue < 1) { GUILayout.Label("unlimited"); } GUILayout.EndHorizontal(); } NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment"); if (dynFont != null) { NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk"); } EditorGUI.BeginDisabledGroup(mRichTextLabel.bitmapFont != null && mRichTextLabel.bitmapFont.packedFontShader); GUILayout.BeginHorizontal(); SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", GUILayout.Width(95f)); EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue); { NGUIEditorTools.SetLabelWidth(30f); NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(50f); GUILayout.Space(79f); NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f)); NGUIEditorTools.SetLabelWidth(80f); } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Effect", GUILayout.Width(76f)); sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f)); EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue); { NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(" ", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); } } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f)); if (!sp.boolValue) { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); GUILayout.BeginHorizontal(); sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f)); EditorGUI.BeginDisabledGroup(!sp.boolValue || mRichTextLabel.bitmapFont == null || !mRichTextLabel.bitmapFont.hasSymbols); NGUIEditorTools.SetLabelWidth(60f); NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols"); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); if (NGUIEditorTools.DrawHeader("RichTextPrefabs")) { NGUIEditorTools.BeginContents(); List <RichTextPrefabItem> prefabs = mRichTextLabel.Prefabs; for (int i = prefabs.Count - 1; i >= 0; i--) { RichTextPrefabItem prefab = prefabs[i]; if (prefab.prefabObject == null) { prefabs.RemoveAt(i); } } for (int i = 0; i < prefabs.Count; i++) { RichTextPrefabItem prefab = prefabs[i]; if (prefab.prefabObject == null) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(prefab.sequence, GUILayout.Width(100f)); GUILayout.Label(prefab.prefabObject.name, GUILayout.Width(100f)); GUILayout.Label("width:" + prefab.width); GUILayout.Label("height:" + prefab.height); GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove prefab", mRichTextLabel); mPrefabSequence = prefab.sequence; //mPrefabGameObject = prefab.prefab; prefabs.Remove(prefab); mRichTextLabel.MarkAsChanged(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); } if (prefabs.Count > 0) { GUILayout.Space(6f); } GUILayout.BeginHorizontal(); mPrefabSequence = EditorGUILayout.TextField(mPrefabSequence, GUILayout.Width(100f)); mPrefabGameObject = (GameObject)EditorGUILayout.ObjectField(mPrefabGameObject, typeof(GameObject), GUILayout.Width(100f)); mPrefabWidth = EditorGUILayout.FloatField(mPrefabWidth); mPrefabHeight = EditorGUILayout.FloatField(mPrefabHeight); isValid = (!string.IsNullOrEmpty(mPrefabSequence)) && (mPrefabGameObject != null); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add prefab", mRichTextLabel); RichTextPrefabItem tprefab = new RichTextPrefabItem(); tprefab.sequence = mPrefabSequence; tprefab.prefabObject = mPrefabGameObject; tprefab.width = mPrefabWidth; tprefab.height = mPrefabHeight; mRichTextLabel.Prefabs.Add(tprefab); mRichTextLabel.MarkAsChanged(); mPrefabSequence = ""; mPrefabGameObject = null; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (prefabs.Count == 0) { EditorGUILayout.HelpBox("In the field above type ':)', choose a Prefab, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("RichTextEmotion")) { NGUIEditorTools.BeginContents(); GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mEmotionAtlas", GUILayout.MinWidth(20f)); GUILayout.EndHorizontal(); if (mRichTextLabel.EmotionAtlas != null) { List <RichTextEmotionItem> emotions = mRichTextLabel.Emotions; for (int i = 0; i < emotions.Count; i++) { RichTextEmotionItem emotion = emotions[i]; GUILayout.BeginHorizontal(); GUILayout.Label(emotion.sequence, GUILayout.Width(40f)); GUILayout.Label(emotion.spriteName); GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove emotion", mRichTextLabel); mEmotionSequence = emotion.sequence; emotions.Remove(emotion); mRichTextLabel.MarkAsChanged(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); } if (emotions.Count > 0) { GUILayout.Space(6f); } GUILayout.BeginHorizontal(); mEmotionSequence = EditorGUILayout.TextField(mEmotionSequence, GUILayout.Width(40f)); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, mSpriteName, SelectSprite, false); isValid = (!string.IsNullOrEmpty(mEmotionSequence)) && (!string.IsNullOrEmpty(mSpriteName)); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add Sprite", mRichTextLabel); RichTextEmotionItem temotion = new RichTextEmotionItem(); temotion.sequence = mEmotionSequence; temotion.spriteName = mSpriteName; mRichTextLabel.Emotions.Add(temotion); mRichTextLabel.MarkAsChanged(); mEmotionSequence = ""; mSpriteName = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (emotions.Count == 0) { EditorGUILayout.HelpBox("In the field above type ':)', choose a Sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } } NGUIEditorTools.EndContents(); } isValid = true; return(isValid); }
public override void OnInspectorGUI() { GUILayout.Space(3f); NGUIEditorTools.SetLabelWidth(80f); serializedObject.Update(); NGUIEditorTools.DrawProperty("Frame Index", serializedObject, "mFrameIndex"); NGUIEditorTools.DrawProperty("Frame Rate", serializedObject, "mFPS"); NGUIEditorTools.DrawProperty("Loop", serializedObject, "mLoop"); NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "mSnap"); SerializedProperty sp = NGUIEditorTools.DrawProperty("Auto Play", serializedObject, "mAutoPlay"); if (sp.boolValue) { GUILayout.BeginHorizontal(); GUILayout.Space(20f); GUILayout.BeginVertical(); NGUIEditorTools.DrawProperty("Play Mode", serializedObject, "mAutoPlayMode"); NGUIEditorTools.DrawProperty("Restart", serializedObject, "mRestart"); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } List <UISpriteAnimationEx.Keyframe> keyframes = mSpriteAnim.keyframes; for (int index = 0; index < keyframes.Count; index++) { GUILayout.BeginHorizontal(); Undo.RecordObject(mSpriteAnim, "UISpriteAnimationEx.Keyframe.Remove"); bool remove = GUILayout.Button("×", GUILayout.Width(20F), GUILayout.Height(14F)); UISpriteAnimationEx.Keyframe keyframe = mSpriteAnim.keyframes[index]; Undo.RecordObject(mSpriteAnim, "UISpriteAnimationEx.Keyframe.FrameIndex"); keyframe.frameIndex = EditorGUILayout.IntField(keyframe.frameIndex, GUILayout.Width(40F)); NGUIEditorTools.DrawAdvancedSpriteField(mSpriteAnim.sprite.atlas, keyframe.spriteName, spriteName => { keyframe.spriteName = spriteName; }, false); GUI.enabled = index > 0; bool up = GUILayout.Button("▲", GUILayout.Width(20F), GUILayout.Height(14F)); GUI.enabled = index < keyframes.Count - 1; bool down = GUILayout.Button("▼", GUILayout.Width(20F), GUILayout.Height(14F)); GUI.enabled = true; GUILayout.EndHorizontal(); if (remove) { keyframes.RemoveAt(index); } else if (up) { keyframes[index] = keyframes[index - 1]; keyframes[index - 1] = keyframe; } else if (down) { keyframes[index] = keyframes[index + 1]; keyframes[index + 1] = keyframe; } } GUILayout.BeginHorizontal(); Undo.RecordObject(mSpriteAnim, "UISpriteAnimationEx.Keyframe.Append"); if (GUILayout.Button("+")) { keyframes.Add(new UISpriteAnimationEx.Keyframe()); } GUILayout.EndHorizontal(); serializedObject.ApplyModifiedProperties(); if (Application.isPlaying) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Play")) { mSpriteAnim.Play(); } if (GUILayout.Button("Pause")) { mSpriteAnim.Pause(); } GUILayout.EndHorizontal(); } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; NGUITools.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsChanged(); } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsChanged(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } } if (mAtlas.spriteMaterial != null) { Color blueColor = new Color(0f, 0.7f, 1f, 1f); Color greenColor = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } GUILayout.Space(3f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Duplicate")) { UIAtlasMaker.SpriteEntry se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); if (se != null) { NGUISettings.selectedSprite = se.name; } } if (GUILayout.Button("Save As...")) { #if UNITY_3_5 string path = EditorUtility.SaveFilePanel("Save As", NGUISettings.currentPath, sprite.name + ".png", "png"); #else string path = EditorUtility.SaveFilePanelInProject("Save As", sprite.name + ".png", "png", "Extract sprite into which file?", NGUISettings.currentPath); #endif if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name); if (se != null) { byte[] bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); if (GUILayout.Button("Add a Shadow")) { AddShadow(sprite); } if (GUILayout.Button("Add a Soft Outline")) { AddOutline(sprite); } if (GUILayout.Button("Add a Transparent Border")) { AddTransparentBorder(sprite); } if (GUILayout.Button("Add a Clamped Border")) { AddClampedBorder(sprite); } if (GUILayout.Button("Add a Tiled Border")) { AddTiledBorder(sprite); } EditorGUI.BeginDisabledGroup(!sprite.hasBorder); if (GUILayout.Button("Crop Border")) { CropBorder(sprite); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } if (NGUIEditorTools.DrawHeader("Texture Optimization")) { NGUIEditorTools.BeginContents(); GUILayout.Space(3f); EditorGUILayout.BeginHorizontal(); NGUIEditorTools.DrawPadding(); TextureCompressionQuality afterType = (TextureCompressionQuality)EditorGUILayout.EnumPopup("Quality Type", NGUIEditorTools.mTextureType); NGUIEditorTools.DrawPadding(); if (afterType != NGUIEditorTools.mTextureType) { NGUIEditorTools.mTextureType = afterType; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); NGUIEditorTools.DrawPadding(); EditorGUILayout.BeginVertical(); EditorGUI.BeginDisabledGroup(mat.shader.name != "My Shaders/UITextureBinding"); if (GUILayout.Button("원본 사용")) { NGUIEditorTools.SetTextureOptimization(mAtlas, false); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUI.BeginDisabledGroup(mat.shader.name != "Unlit/Transparent Colored"); if (GUILayout.Button("최적화 사용")) { NGUIEditorTools.SetTextureOptimization(mAtlas, true); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); NGUIEditorTools.DrawPadding(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); NGUIEditorTools.DrawPadding(); EditorGUILayout.BeginVertical(); if (GUILayout.Button("전체 원본으로")) { string[] aAtlasFiles = Directory.GetFiles("Assets/Resources/Prefabs/UI_Data/UI_Atlas", "*.prefab", SearchOption.AllDirectories); for (int i = 0; i < aAtlasFiles.Length; ++i) { EditorUtility.DisplayProgressBar("Texture Optimization", "Combine...", ((i + 1) / (float)aAtlasFiles.Length)); UIAtlas sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas; NGUIEditorTools.SetTextureOptimization(sourceAtlas, false); } EditorUtility.ClearProgressBar(); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); if (GUILayout.Button("전체 최적화")) { string[] aAtlasFiles = Directory.GetFiles("Assets/Resources/Prefabs/UI_Data/UI_Atlas", "*.prefab", SearchOption.AllDirectories); for (int i = 0; i < aAtlasFiles.Length; ++i) { EditorUtility.DisplayProgressBar("Texture Optimization", string.Format("Devide..."), ((i + 1) / (float)aAtlasFiles.Length)); UIAtlas sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas; shaderTextureBinding = shaderTextureBinding == null?Shader.Find("My Shaders/UITextureBinding") : shaderTextureBinding; sourceAtlas.spriteMaterial.shader = shaderTextureBinding; NGUIEditorTools.CopyAndChangeTexture(sourceAtlas, true); sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas; NGUIEditorTools.CopyAndChangeTexture(sourceAtlas, false); } EditorUtility.ClearProgressBar(); } EditorGUILayout.EndVertical(); NGUIEditorTools.DrawPadding(); EditorGUILayout.EndHorizontal(); EditorGUILayout.HelpBox("Quality Type : 텍스쳐의 Compression Quality (Best는 속도가 느리기 때문에 빌드할 때만 한다.)\n" + "원본, 최적화 사용 : 해당 아틀라스의 텍스쳐를 원본, 최적화 상태로 변경한다.\n" + "전체 원본, 전체 최적화 : UI_Atlas 폴더에 있는 모든 아틀라스를 일괄 원본, 최적화 상태로 변경한다.", MessageType.Info); NGUIEditorTools.EndContents(); } } } }
private void OnGUI() { GUILayout.Space(10F); if (!m_atlas) { m_atlas = NGUISettings.atlas; } ComponentSelector.Draw <UIAtlas>("Atlas", m_atlas, obj => { if (m_atlas != obj) { m_atlas = obj as UIAtlas; } }, true, GUILayout.MinWidth(80f)); if (m_atlas != null) { GUILayout.BeginHorizontal(); GUILayout.Space(10f); if (GUILayout.Button("Search")) { m_spriteNames.Clear(); Object[] uiSprites = Selection.GetFiltered(typeof(UISprite), SelectionMode.Deep); Object[] uiLabels = Selection.GetFiltered(typeof(UILabel), SelectionMode.Deep); foreach (UISpriteData spriteData in m_atlas.spriteList) { bool found = false; foreach (UISprite uiSprite in uiSprites) { if (uiSprite.atlas == m_atlas && string.Equals(uiSprite.spriteName, spriteData.name)) { found = true; break; } } if (!found) { foreach (UILabel uiLabel in uiLabels) { if (uiLabel.bitmapFont) { foreach (BMSymbol symbol in uiLabel.bitmapFont.symbols) { if (string.Equals(symbol.spriteName, spriteData.name)) { found = true; break; } } if (found) { break; } } } } if (!found) { m_spriteNames.Add(spriteData.name); } } } GUILayout.Space(10f); GUILayout.EndHorizontal(); GUILayout.Space(10f); GUILayout.BeginHorizontal(); GUILayout.Space(5F); EditorGUILayout.BeginVertical(); if (NGUIEditorTools.DrawMinimalisticHeader("Sprites")) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(15f); EditorGUILayout.BeginVertical(); mScroll = EditorGUILayout.BeginScrollView(mScroll); GUILayout.Space(2f); int oldLength = m_spriteNames.Count; int newLength = EditorGUILayout.IntField("Size", oldLength); if (newLength != oldLength) { int minLength = Mathf.Min(newLength, oldLength); string[] sprites = new string[newLength]; for (int i = 0; i < minLength; i++) { sprites[i] = m_spriteNames[i]; } m_spriteNames = new List <string>(sprites); } for (int i = 0; i < newLength; i++) { int index = i; NGUIEditorTools.DrawAdvancedSpriteField(m_atlas, m_spriteNames[index], spriteName => { m_spriteNames[index] = spriteName; Repaint(); }, false); } GUILayout.Space(2f); GUILayout.EndScrollView(); EditorGUILayout.EndVertical(); GUILayout.Space(3f); EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(10f); } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsDirty(); } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsDirty(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } } if (mAtlas.spriteMaterial != null) { Color blue = new Color(0f, 0.7f, 1f, 1f); Color green = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = green; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blue; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; NGUITools.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsChanged(); } #region //add by chenbin if (mAtlas.isBorrowSpriteMode) { GUI.color = Color.green; } else { GUI.color = Color.white; } GUILayout.Label("\n=== ========================================="); if (GUILayout.Button("说明")) { isShowBorrowModeDesc = !isShowBorrowModeDesc; } if (isShowBorrowModeDesc) { GUILayout.Label("勾选isBorrowSpriteMode时,表明该atlas是空atlas,\n" + "当有sprit对象来borrow时,atlas会根据名字从\n" + "设置的路径中去取得图片资源。\n" + //"其中资源必须在Resources/下,\n" + "另外atlas必须要引用一个material,\n" + "就算引用的是个空material也行。\n"); } if (mAtlas != null && runTimes == 0) { runTimes++; isBorrowMode = mAtlas.isBorrowSpriteMode; // isUserUnity3DType = mAtlas.useUnity3DType; } mAtlas.isBorrowSpriteMode = EditorGUILayout.Toggle("isBorrowSpriteMode", mAtlas.isBorrowSpriteMode); if (isBorrowMode != mAtlas.isBorrowSpriteMode) { isBorrowMode = mAtlas.isBorrowSpriteMode; UnityEditor.EditorUtility.SetDirty(mAtlas.gameObject); } // if (mAtlas.isBorrowSpriteMode) { // mAtlas.useUnity3DType = EditorGUILayout.Toggle ("useUnity3DType", mAtlas.useUnity3DType); // if (isUserUnity3DType != mAtlas.useUnity3DType) { // isUserUnity3DType = mAtlas.useUnity3DType; // UnityEditor.EditorUtility.SetDirty (NGUISettings.atlas.gameObject); // } // } GUILayout.Label("============================================\n"); GUI.color = Color.white; if (GUILayout.Button("Clean items if no png")) { if (EditorUtility.DisplayDialog("Alert", "Really ?", "Do it now!", "NO")) { UISpriteData item = null; List <UISpriteData> list = new List <UISpriteData> (); for (int i = 0; i < mAtlas.spriteList.Count; i++) { item = mAtlas.spriteList [i]; string path = Application.dataPath + "/" + item.path; path = path.Replace("/upgradeRes/", "/upgradeRes4Dev/"); path = path.Replace("/upgradeRes4Publish/", "/upgradeRes4Dev/"); if (!File.Exists(path)) { Debug.Log(path); list.Add(item); } } deleteSprites(list); } } #endregion //end ======add by chenbin if (mat != null || mAtlas.isBorrowSpriteMode) // modify by chenbin { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsChanged(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } } if (mAtlas.spriteMaterial != null || mAtlas.isBorrowSpriteMode) //modify by chenbin { Color blueColor = new Color(0f, 0.7f, 1f, 1f); Color greenColor = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } // if (sprite == null) sprite = mAtlas.spriteList[0]; // delete by chenbin #region add by chenbin if (sprite == null) { if (mAtlas.isBorrowSpriteMode) { sprite = mAtlas.spriteList [0]; spriteName = sprite.name; sprite = mAtlas.borrowSpriteByname(spriteName, null); } else { sprite = mAtlas.spriteList [0]; } } #endregion } if (sprite != null) { if (sprite == null) { return; } // Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; //delete by chenbin #region add by chenbin Texture2D tex = null; if (mAtlas != null) { if (mAtlas.isBorrowSpriteMode) { if (sprite != null && sprite.material != null) { tex = sprite.material.mainTexture as Texture2D; } } else { tex = mAtlas.spriteMaterial.mainTexture as Texture2D; } } #endregion // if (tex != null) //modify by chenbin if (tex != null || (mAtlas != null && mAtlas.isBorrowSpriteMode && sprite != null)) //modify by chenbin { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } GUILayout.Space(3f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Duplicate")) { string newName = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); // modify by chenbin if (newName != null) { NGUISettings.selectedSprite = newName; // modify by chenbin } } if (GUILayout.Button("Save As...")) { #if UNITY_3_5 string path = EditorUtility.SaveFilePanel("Save As", NGUISettings.currentPath, sprite.name + ".png", "png"); #else string path = EditorUtility.SaveFilePanelInProject("Save As", sprite.name + ".png", "png", "Extract sprite into which file?", NGUISettings.currentPath); #endif if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name); if (se != null) { byte[] bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); if (GUILayout.Button("Add a Shadow")) { AddShadow(sprite); } if (GUILayout.Button("Add a Soft Outline")) { AddOutline(sprite); } if (GUILayout.Button("Add a Transparent Border")) { AddTransparentBorder(sprite); } if (GUILayout.Button("Add a Clamped Border")) { AddClampedBorder(sprite); } if (GUILayout.Button("Add a Tiled Border")) { AddTiledBorder(sprite); } EditorGUI.BeginDisabledGroup(!sprite.hasBorder); if (GUILayout.Button("Crop Border")) { CropBorder(sprite); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; NGUITools.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsChanged(); } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsChanged(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } if (NGUIEditorTools.DrawHeader("Scale Factor")) { NGUIEditorTools.BeginContents(); { EditorGUILayout.HelpBox( "If the image size(pixel size in photoshop) is not equal to texture size(pixel size in unity), you should set the scale factor to help NGUI to adjust uv.", MessageType.Info, true ); EditorGUILayout.HelpBox( "You should click the the button below to recalculate scale factor for atlas when the atlas' texture is changed. For example, when you add sprite, remove sprite, set compressed format or change maxsize etc.", MessageType.Warning, true ); if (GUILayout.Button("Calculate Scale Factor Automatically")) { if (mAtlas.texture != null) { string path = AssetDatabase.GetAssetPath(mAtlas.texture); string fullPath = Application.dataPath + path.Substring("Assets".Length); if (File.Exists(fullPath)) { MemoryStream memoryStream = null; BinaryReader binaryReader = null; try { byte[] bytes = File.ReadAllBytes(fullPath); memoryStream = new MemoryStream(bytes); binaryReader = new BinaryReader(memoryStream); // Is PNG if (binaryReader.ReadByte() == 0x89 && binaryReader.ReadByte() == 0x50 && binaryReader.ReadByte() == 0x4E && binaryReader.ReadByte() == 0x47 && binaryReader.ReadByte() == 0x0D && binaryReader.ReadByte() == 0x0A && binaryReader.ReadByte() == 0x1A && binaryReader.ReadByte() == 0x0A) { binaryReader.ReadUInt32(); binaryReader.ReadUInt32(); uint width = LittleEndianToBigEndian(binaryReader.ReadUInt32()); uint height = LittleEndianToBigEndian(binaryReader.ReadUInt32()); TextureImporter textureImporter = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(mAtlas.texture)); System.Action <string, UIAtlas.SCALE_PLATFORM, BuildTarget> processScale = delegate(string platformName, UIAtlas.SCALE_PLATFORM platformAtlasEnum, BuildTarget platformEnum) { if (mAtlas.scales == null || mAtlas.scales.Length != (int)UIAtlas.SCALE_PLATFORM.SIZE * 2) { mAtlas.scales = new float[(int)UIAtlas.SCALE_PLATFORM.SIZE * 2] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; } // TextureImportInstructions info = new TextureImportInstructions(); // textureImporter.ReadTextureImportInstructions(info, platformEnum); int maxSize; TextureImporterFormat format; if (textureImporter.GetPlatformTextureSettings(platformName, out maxSize, out format)) { float len = width > height ? width : height; mAtlas.scales[(int)platformAtlasEnum * 2] = len / (float)width; mAtlas.scales[(int)platformAtlasEnum * 2 + 1] = len / (float)height; } else { mAtlas.scales[(int)platformAtlasEnum * 2] = 1; mAtlas.scales[(int)platformAtlasEnum * 2 + 1] = 1; } }; processScale("Web", UIAtlas.SCALE_PLATFORM.WEB, BuildTarget.WebPlayer); processScale("Standalone", UIAtlas.SCALE_PLATFORM.STANDALONE, BuildTarget.StandaloneWindows); processScale("iPhone", UIAtlas.SCALE_PLATFORM.IPHONE, BuildTarget.iOS); processScale("Android", UIAtlas.SCALE_PLATFORM.ANDROID, BuildTarget.Android); NGUITools.SetDirty(mAtlas); } } catch (System.Exception exception) { Debug.LogError(exception.StackTrace); UnityEditor.EditorUtility.DisplayDialog("Error", "Error:Set the scale factor mamually.", "ok"); } finally { if (memoryStream != null) { memoryStream.Close(); memoryStream.Dispose(); memoryStream = null; } if (binaryReader != null) { binaryReader.Close(); binaryReader = null; } } } else { UnityEditor.EditorUtility.DisplayDialog("Alert", "File is not exists\n" + fullPath, "ok"); } } else { UnityEditor.EditorUtility.DisplayDialog("Alert", "Null Texture", "ok"); } } } NGUIEditorTools.EndContents(); } } if (mAtlas.spriteMaterial != null) { Color blueColor = new Color(0f, 0.7f, 1f, 1f); Color greenColor = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } GUILayout.Space(3f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Duplicate")) { UIAtlasMaker.SpriteEntry se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); if (se != null) { NGUISettings.selectedSprite = se.name; } } if (GUILayout.Button("Save As...")) { string path = EditorUtility.SaveFilePanelInProject("Save As", sprite.name + ".png", "png", "Extract sprite into which file?"); if (!string.IsNullOrEmpty(path)) { UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name); if (se != null) { byte[] bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); if (GUILayout.Button("Add a Shadow")) { AddShadow(sprite); } if (GUILayout.Button("Add a Soft Outline")) { AddOutline(sprite); } if (GUILayout.Button("Add a Transparent Border")) { AddTransparentBorder(sprite); } if (GUILayout.Button("Add a Clamped Border")) { AddClampedBorder(sprite); } if (GUILayout.Button("Add a Tiled Border")) { AddTiledBorder(sprite); } EditorGUI.BeginDisabledGroup(!sprite.hasBorder); if (GUILayout.Button("Crop Border")) { CropBorder(sprite); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); if (mAtlas == null) { EditorGUILayout.HelpBox("Invalid asset. Please re-create it.", MessageType.Error, true); return; } UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != (mAtlas as INGUIAtlas) && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object); mAtlas.replacement = mReplacement; NGUITools.SetDirty(mAtlas as Object); } return; } if (mAtlas is UIAtlas) { EditorGUILayout.HelpBox("Legacy atlas type should be upgraded in order to maintain compatibility with Unity 2018 and newer.", MessageType.Warning, true); if (GUILayout.Button("Upgrade")) { var path = EditorUtility.SaveFilePanelInProject("Save As", (mAtlas as Object).name + ".asset", "asset", "Save atlas as...", NGUISettings.currentPath); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); var asset = ScriptableObject.CreateInstance <NGUIAtlas>(); asset.spriteList = mAtlas.spriteList; asset.spriteMaterial = mAtlas.spriteMaterial; var atlasName = path.Replace(".asset", ""); atlasName = atlasName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1); asset.name = atlasName; var existing = AssetDatabase.LoadMainAssetAtPath(path); if (existing != null) { EditorUtility.CopySerialized(asset, existing); } else { AssetDatabase.CreateAsset(asset, path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); asset = AssetDatabase.LoadAssetAtPath <NGUIAtlas>(path); NGUISettings.atlas = asset; Selection.activeObject = NGUISettings.atlas as Object; if (asset != null) { mAtlas.replacement = asset; mAtlas.MarkAsChanged(); } } } } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsChanged(); } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas as Object); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsChanged(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object); mAtlas.pixelSize = pixelSize; } } if (mAtlas.spriteMaterial != null) { Color blueColor = new Color(0f, 0.7f, 1f, 1f); Color greenColor = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); NGUITools.SetDirty(mAtlas as Object); } GUILayout.Space(3f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Duplicate")) { var se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); if (se != null) { NGUISettings.selectedSprite = se.name; } } if (GUILayout.Button("Save As...")) { var path = EditorUtility.SaveFilePanel("Save As", NGUISettings.currentPath, sprite.name + ".png", "png"); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); var se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name); if (se != null) { var bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); //AssetDatabase.ImportAsset(path); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); if (GUILayout.Button("Add a Shadow")) { AddShadow(sprite); } if (GUILayout.Button("Add a Soft Outline")) { AddOutline(sprite); } if (GUILayout.Button("Add a Transparent Border")) { AddTransparentBorder(sprite); } if (GUILayout.Button("Add a Clamped Border")) { AddClampedBorder(sprite); } if (GUILayout.Button("Add a Tiled Border")) { AddTiledBorder(sprite); } EditorGUI.BeginDisabledGroup(!sprite.hasBorder); if (GUILayout.Button("Crop Border")) { CropBorder(sprite); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; NGUIEditorTools.DrawSeparator(); string MaterialName = EditorGUILayout.TextField(" Material Path", mAtlas.MaterialPath); MaterialName = AssetDatabase.GetAssetPath(mAtlas.gameObject); MaterialName = MaterialName.Replace("prefab", "mat"); mAtlas.MaterialPath = MaterialName; EditorUtility.SetDirty(mAtlas); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); if (mType != after) { if (after == AtlasType.Normal) { OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas); NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can have one atlas simply point to\n" + "another one. This is useful if you want to be\n" + "able to quickly replace the contents of one\n" + "atlas with another one, for example for\n" + "swapping an SD atlas with an HD one, or\n" + "replacing an English atlas with a Chinese\n" + "one. All the sprites referencing this atlas\n" + "will update their references to the new one."); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mAtlas); } return; } if (!mConfirmDelete) { NGUIEditorTools.DrawSeparator(); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false); } mAtlas.MarkAsDirty(); mConfirmDelete = false; } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (mSprite != null) { mSprite = mAtlas.GetSprite(mSprite.name); } mAtlas.MarkAsDirty(); } UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates); if (coords != mAtlas.coordinates) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.coordinates = coords; mConfirmDelete = false; } } } if (mAtlas.spriteMaterial != null) { Color blue = new Color(0f, 0.7f, 1f, 1f); Color green = new Color(0.4f, 1f, 0f, 1f); if (mConfirmDelete) { if (mSprite != null) { // Show the confirmation dialog NGUIEditorTools.DrawSeparator(); GUILayout.Label("Are you sure you want to delete '" + mSprite.name + "'?"); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); { GUI.backgroundColor = Color.green; if (GUILayout.Button("Cancel")) { mConfirmDelete = false; } GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete")) { NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas); mAtlas.spriteList.Remove(mSprite); mConfirmDelete = false; } GUI.backgroundColor = Color.white; } GUILayout.EndHorizontal(); } else { mConfirmDelete = false; } } else { if (mSprite == null && mAtlas.spriteList.Count > 0) { string spriteName = PlayerPrefs.GetString("NGUI Selected Sprite"); if (!string.IsNullOrEmpty(spriteName)) { mSprite = mAtlas.GetSprite(spriteName); } if (mSprite == null) { mSprite = mAtlas.spriteList[0]; } } GUI.backgroundColor = Color.green; GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Add/Delete"); if (GUILayout.Button("New Sprite")) { NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas); UIAtlas.Sprite newSprite = new UIAtlas.Sprite(); if (mSprite != null) { newSprite.name = "Copy of " + mSprite.name; newSprite.outer = mSprite.outer; newSprite.inner = mSprite.inner; } else { newSprite.name = "New Sprite"; } mAtlas.spriteList.Add(newSprite); mSprite = newSprite; } // Show the delete button GUI.backgroundColor = Color.red; if (mSprite != null && GUILayout.Button("Delete", GUILayout.Width(55f))) { mConfirmDelete = true; } GUI.backgroundColor = Color.white; } GUILayout.EndHorizontal(); if (!mConfirmDelete && mSprite != null) { NGUIEditorTools.DrawSeparator(); //string spriteName = UISpriteInspector.SpriteField(mAtlas, mSprite.name); //string spriteName = NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, mSprite.name, null, true, GUILayout.Width(200f)); //string spriteName = mSprite.name; NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, mSprite.name, (name) => { //spriteName = name; if (name != mSprite.name) { mSprite = mAtlas.GetSprite(name); PlayerPrefs.SetString("NGUI Selected Sprite", name); } }, true, GUILayout.Width(120f)); if (mSprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { Rect inner = mSprite.inner; Rect outer = mSprite.outer; Rect outOffset = mSprite.outerOffset; string name = EditorGUILayout.TextField("Edit Name", mSprite.name); if (mSprite.name != name && !string.IsNullOrEmpty(name)) { bool found = false; foreach (UIAtlas.Sprite sp in mAtlas.spriteList) { if (sp.name == name) { found = true; break; } } if (!found) { NGUIEditorTools.RegisterUndo("Edit Sprite Name", mAtlas); mSprite.name = name; } } if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { GUI.backgroundColor = green; outOffset = NGUIEditorTools.IntRect("DimenOffset", mSprite.outerOffset); if (GUILayout.Button("应用Offset")) { mSprite.outer = NGUIMath.RectAdd(mSprite.oriOuter, mSprite.outerOffset); } outer = NGUIEditorTools.IntRect("Dimensions", mSprite.outer); Vector4 border = new Vector4( mSprite.inner.xMin - mSprite.outer.xMin, mSprite.inner.yMin - mSprite.outer.yMin, mSprite.outer.xMax - mSprite.inner.xMax, mSprite.outer.yMax - mSprite.inner.yMax); GUI.backgroundColor = blue; border = NGUIEditorTools.IntPadding("Border", border); GUI.backgroundColor = Color.white; inner.xMin = mSprite.outer.xMin + border.x; inner.yMin = mSprite.outer.yMin + border.y; inner.xMax = mSprite.outer.xMax - border.z; inner.yMax = mSprite.outer.yMax - border.w; } else { // Draw the inner and outer rectangle dimensions GUI.backgroundColor = green; outer = EditorGUILayout.RectField("Outer Rect", mSprite.outer); GUI.backgroundColor = blue; inner = EditorGUILayout.RectField("Inner Rect", mSprite.inner); GUI.backgroundColor = Color.white; } if (outer.xMax < outer.xMin) { outer.xMax = outer.xMin; } if (outer.yMax < outer.yMin) { outer.yMax = outer.yMin; } if (outer != mSprite.outer) { float x = outer.xMin - mSprite.outer.xMin; float y = outer.yMin - mSprite.outer.yMin; inner.x += x; inner.y += y; } // Sanity checks to ensure that the inner rect is always inside the outer inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax); inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax); inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax); inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax); EditorGUILayout.Separator(); // Padding is mainly meant to be used by the 'trimmed' feature of TexturePacker if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { int left = Mathf.RoundToInt(mSprite.paddingLeft * mSprite.outer.width); int right = Mathf.RoundToInt(mSprite.paddingRight * mSprite.outer.width); int top = Mathf.RoundToInt(mSprite.paddingTop * mSprite.outer.height); int bottom = Mathf.RoundToInt(mSprite.paddingBottom * mSprite.outer.height); NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top); NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom); if (a.x != left || a.y != top || b.x != right || b.y != bottom) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mSprite.paddingLeft = a.x / mSprite.outer.width; mSprite.paddingTop = a.y / mSprite.outer.width; mSprite.paddingRight = b.x / mSprite.outer.height; mSprite.paddingBottom = b.y / mSprite.outer.height; MarkSpriteAsDirty(); } } else { // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { GUILayout.Label("Correction", GUILayout.Width(75f)); Rect corrected0 = outer; Rect corrected1 = inner; if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { corrected0 = NGUIMath.MakePixelPerfect(corrected0); corrected1 = NGUIMath.MakePixelPerfect(corrected1); } else { corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height); corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height); } if (corrected0 == mSprite.outer && corrected1 == mSprite.inner) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { outer = corrected0; inner = corrected1; GUI.changed = true; } } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Show", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); if (mUseShader != EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f))) { mUseShader = !mUseShader; if (mUseShader && mView == View.Sprite) { // TODO: Remove this when Unity fixes the bug with DrawPreviewTexture not being affected by BeginGroup Debug.LogWarning("There is a bug in Unity that prevents the texture from getting clipped properly.\n" + "Until it's fixed by Unity, your texture may spill onto the rest of the Unity's GUI while using this mode."); } } } GUILayout.EndHorizontal(); if (mSprite.outer != outer || mSprite.inner != inner || mSprite.outerOffset != outOffset) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mSprite.outerOffset = outOffset; mSprite.outer = outer; mSprite.inner = inner; mConfirmDelete = false; MarkSpriteAsDirty(); } Rect uv0 = outer; Rect uv1 = inner; if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels) { uv0 = NGUIMath.ConvertToTexCoords(uv0, tex.width, tex.height); uv1 = NGUIMath.ConvertToTexCoords(uv1, tex.width, tex.height); } // Draw the atlas EditorGUILayout.Separator(); Material m = mUseShader ? mAtlas.spriteMaterial : null; Rect rect = (mView == View.Atlas) ? NGUIEditorTools.DrawAtlas(tex, m) : NGUIEditorTools.DrawSprite(tex, uv0, m); // Draw the sprite outline NGUIEditorTools.DrawOutline(rect, uv0, uv1); EditorGUILayout.Separator(); } } } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UIAtlas; UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null; GUILayout.Space(6f); if (mAtlas.replacement != null) { mType = AtlasType.Reference; mReplacement = mAtlas.replacement; } GUILayout.BeginHorizontal(); AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (mType != after) { if (after == AtlasType.Normal) { mType = AtlasType.Normal; OnSelectAtlas(null); } else { mType = AtlasType.Reference; } } if (mType == AtlasType.Reference) { ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true); GUILayout.Space(6f); EditorGUILayout.HelpBox("You can have one atlas simply point to " + "another one. This is useful if you want to be " + "able to quickly replace the contents of one " + "atlas with another one, for example for " + "swapping an SD atlas with an HD one, or " + "replacing an English atlas with a Chinese " + "one. All the sprites referencing this atlas " + "will update their references to the new one.", MessageType.Info); if (mReplacement != mAtlas && mAtlas.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; NGUITools.SetDirty(mAtlas); } return; } //GUILayout.Space(6f); Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; if (mAtlas.spriteMaterial != mat) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.spriteMaterial = mat; // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } mAtlas.MarkAsChanged(); } if (mat != null) { TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset; if (ta != null) { // Ensure that this atlas has valid import settings if (mAtlas.texture != null) { NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); } NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas); NGUIJson.LoadSpriteData(mAtlas, ta); if (sprite != null) { sprite = mAtlas.GetSprite(sprite.name); } mAtlas.MarkAsChanged(); } float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f)); if (pixelSize != mAtlas.pixelSize) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.pixelSize = pixelSize; } } if (mAtlas.spriteMaterial != null) { Color blueColor = new Color(0f, 0.7f, 1f, 1f); Color greenColor = new Color(0.4f, 1f, 0f, 1f); if (sprite == null && mAtlas.spriteList.Count > 0) { string spriteName = NGUISettings.selectedSprite; if (!string.IsNullOrEmpty(spriteName)) { sprite = mAtlas.GetSprite(spriteName); } if (sprite == null) { sprite = mAtlas.spriteList[0]; } } if (sprite != null) { if (sprite == null) { return; } Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D; if (tex != null) { if (!NGUIEditorTools.DrawHeader("Sprite Details")) { return; } NGUIEditorTools.BeginContents(); GUILayout.Space(3f); NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y); NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight); NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight); NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); sprite.x = sizeA.x; sprite.y = sizeA.y; sprite.width = sizeB.x; sprite.height = sizeB.y; sprite.paddingLeft = padA.x; sprite.paddingRight = padA.y; sprite.paddingBottom = padB.x; sprite.paddingTop = padB.y; sprite.borderLeft = borderA.x; sprite.borderRight = borderA.y; sprite.borderBottom = borderB.x; sprite.borderTop = borderB.y; MarkSpriteAsDirty(); } GUILayout.Space(3f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Duplicate")) { UIAtlasMaker.SpriteEntry se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); if (se != null) { NGUISettings.selectedSprite = se.name; } } if (GUILayout.Button("Save As...")) { string path = EditorUtility.SaveFilePanel("Save As", NGUISettings.currentPath, sprite.name + ".png", "png"); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name); if (se != null) { byte[] bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } if (GUILayout.Button("Save As All")) { string path = EditorUtility.SaveFolderPanel("Save As All", NGUISettings.currentPath, ""); if (!string.IsNullOrEmpty(path)) { var list = mAtlas.spriteList; foreach (var uiSpriteData in list) { var spName = uiSpriteData.name; NGUISettings.currentPath = path; UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, spName); if (se != null) { var filePath = string.Format("{0}/{1}.png", path, spName); byte[] bytes = se.tex.EncodeToPNG(); File.WriteAllBytes(filePath, bytes); AssetDatabase.ImportAsset(filePath); if (se.temporaryTexture) { DestroyImmediate(se.tex); } } } } } GUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.DrawHeader("Modify")) { NGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor); if (GUILayout.Button("Add a Shadow")) { AddShadow(sprite); } if (GUILayout.Button("Add a Soft Outline")) { AddOutline(sprite); } if (GUILayout.Button("Add a Transparent Border")) { AddTransparentBorder(sprite); } if (GUILayout.Button("Add a Clamped Border")) { AddClampedBorder(sprite); } if (GUILayout.Button("Add a Tiled Border")) { AddTiledBorder(sprite); } EditorGUI.BeginDisabledGroup(!sprite.hasBorder); if (GUILayout.Button("Crop Border")) { CropBorder(sprite); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); GUILayout.Space(20f); EditorGUILayout.EndHorizontal(); NGUIEditorTools.EndContents(); } if (NGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name)) { NGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected override bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (NGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UIAtlas>(OnSelectAtlas); } SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UIAtlas atl = atlas.objectReferenceValue as UIAtlas; NGUISettings.atlas = atl; if (atl != null) { NGUIEditorTools.Select(atl.gameObject); } } } GUILayout.EndHorizontal(); SerializedProperty sp = serializedObject.FindProperty("mSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false); UIPolygonSprite sprite = target as UIPolygonSprite; GUILayout.BeginHorizontal(); SerializedProperty fill = serializedObject.FindProperty("mFillCenter"); fill.boolValue = EditorGUILayout.Toggle("Fill", fill.boolValue, GUILayout.Width(95f)); if (!fill.boolValue) { SerializedProperty thickness = serializedObject.FindProperty("mThickness"); thickness.intValue = EditorGUILayout.IntSlider("Thickness", thickness.intValue, 1, sprite.width / 2); } GUILayout.EndHorizontal(); SerializedProperty test = serializedObject.FindProperty("mTest"); test.boolValue = EditorGUILayout.Toggle("SliceTest", test.boolValue, GUILayout.Width(95f)); SerializedProperty spSide = serializedObject.FindProperty("mSideSpriteName"); NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, spSide.stringValue, SelectSideSprite, false); SerializedProperty sides = serializedObject.FindProperty("mPolygonSides"); sides.intValue = EditorGUILayout.IntSlider("Sides", sides.intValue, 3, 360); SerializedProperty verticesDistance = serializedObject.FindProperty("mVerticesDistances"); SerializedProperty spriteSides = serializedObject.FindProperty("mSpriteSides"); if (verticesDistance.arraySize != sides.intValue + 1) { verticesDistance.ClearArray(); verticesDistance.arraySize = sides.intValue + 1; for (int i = 0; i < sides.intValue; i++) { verticesDistance.GetArrayElementAtIndex(i).floatValue = 1f; } if (test.boolValue) { for (int i = 0; i < spriteSides.arraySize; ++i) { UISprite spriteSide = spriteSides.GetArrayElementAtIndex(i).objectReferenceValue as UISprite; if (spriteSide != null) { NGUITools.Destroy(spriteSide.gameObject); spriteSide = null; } } spriteSides.ClearArray(); spriteSides.arraySize = sides.intValue; for (int i = 0; i < sides.intValue; ++i) { if (spSide.stringValue.Length > 0) { UISprite spriteSide = NGUITools.AddSprite(sprite.gameObject, sprite.atlas, spSide.stringValue, sprite.depth + 1); spriteSide.MakePixelPerfect(); spriteSides.GetArrayElementAtIndex(i).objectReferenceValue = spriteSide; } } } } if (NGUIEditorTools.DrawMinimalisticHeader("Distance")) { NGUIEditorTools.BeginContents(true); for (int i = 0; i < sides.intValue; i++) { verticesDistance.GetArrayElementAtIndex(i).floatValue = EditorGUILayout.Slider("Distances " + i, verticesDistance.GetArrayElementAtIndex(i).floatValue, 0, 1); if (test.boolValue) { if (sprite.width * verticesDistance.GetArrayElementAtIndex(i).floatValue < sprite.minWidth) { verticesDistance.GetArrayElementAtIndex(i).floatValue = sprite.minWidth / (float)sprite.width; } } } NGUIEditorTools.EndContents(); } // last vertex is also the first! verticesDistance.GetArrayElementAtIndex(sides.intValue).floatValue = verticesDistance.GetArrayElementAtIndex(0).floatValue; return(true); }