/// <summary> /// Draw a button + object selection combo filtering specified types. /// </summary> static public void Draw <T> (string buttonName, T obj, OnSelectionCallback cb, bool editButton, params GUILayoutOption[] options) where T : Object { GUILayout.BeginHorizontal(); bool show = UGUIEditorTools.DrawPrefixButton(buttonName); T o = EditorGUILayout.ObjectField(obj, typeof(T), false, options) as T; if (editButton && o != null && o is MonoBehaviour) { Component mb = o as Component; if (Selection.activeObject != mb.gameObject && GUILayout.Button("Edit", GUILayout.Width(40f))) { Selection.activeObject = mb.gameObject; } } else if (o != null && GUILayout.Button("X", GUILayout.Width(20f))) { o = null; } GUILayout.EndHorizontal(); if (show) { Show <T>(cb); } else { cb(o); } }
/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected virtual bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (UGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UGUIAtlas>(OnSelectAtlas); } SerializedProperty atlas = UGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UGUIAtlas atl = atlas.objectReferenceValue as UGUIAtlas; UGUISettings.atlas = atl; UGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); UGUISprite uguiSprite = target as UGUISprite; string spriteName = uguiSprite.sprite == null ? "" : uguiSprite.sprite.name; UGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UGUIAtlas, spriteName, SelectSprite, true); return(true); }
public override void OnInspectorGUI() { GUILayout.Space(6f); UGUIEditorTools.SetLabelWidth(110f); base.OnInspectorGUI(); DrawCommonProperties(); }
/// <summary> /// Show the sprite selection wizard. /// </summary> static public void ShowSelected() { if (UGUISettings.atlas != null) { Show(delegate(string sel) { UGUIEditorTools.SelectSprite(sel); }); } }
/// <summary> /// Integer vector field. /// </summary> static public IntVector IntPair(string prefix, string leftCaption, string rightCaption, int x, int y) { GUILayout.BeginHorizontal(); if (string.IsNullOrEmpty(prefix)) { GUILayout.Space(82f); } else { GUILayout.Label(prefix, GUILayout.Width(74f)); } UGUIEditorTools.SetLabelWidth(48f); IntVector retVal; retVal.x = EditorGUILayout.IntField(leftCaption, x, GUILayout.MinWidth(30f)); retVal.y = EditorGUILayout.IntField(rightCaption, y, GUILayout.MinWidth(30f)); UGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); return(retVal); }
/// <summary> /// Helper function that draws a compact Rect. /// </summary> static public void DrawRectProperty(string name, SerializedObject serializedObject, string field, float labelWidth, float spacing) { if (serializedObject.FindProperty(field) != null) { GUILayout.BeginHorizontal(); { GUILayout.Label(name, GUILayout.Width(labelWidth)); UGUIEditorTools.SetLabelWidth(20f); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("X", serializedObject, field + ".x", GUILayout.MinWidth(50f)); UGUIEditorTools.DrawProperty("Y", serializedObject, field + ".y", GUILayout.MinWidth(50f)); GUILayout.EndVertical(); UGUIEditorTools.SetLabelWidth(50f); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("Width", serializedObject, field + ".width", GUILayout.MinWidth(80f)); UGUIEditorTools.DrawProperty("Height", serializedObject, field + ".height", GUILayout.MinWidth(80f)); GUILayout.EndVertical(); UGUIEditorTools.SetLabelWidth(80f); if (spacing != 0f) { GUILayout.Space(spacing); } } GUILayout.EndHorizontal(); } }
/// <summary> /// Integer rectangle field. /// </summary> static public Rect IntRect(string prefix, Rect rect) { int left = Mathf.RoundToInt(rect.xMin); int top = Mathf.RoundToInt(rect.yMin); int width = Mathf.RoundToInt(rect.width); int height = Mathf.RoundToInt(rect.height); UGUIEditorTools.IntVector a = UGUIEditorTools.IntPair(prefix, "Left", "Top", left, top); UGUIEditorTools.IntVector b = UGUIEditorTools.IntPair(null, "Width", "Height", width, height); return(new Rect(a.x, a.y, b.x, b.y)); }
/// <summary> /// Integer vector field. /// </summary> static public Vector4 IntPadding(string prefix, Vector4 v) { int left = Mathf.RoundToInt(v.x); int top = Mathf.RoundToInt(v.y); int right = Mathf.RoundToInt(v.z); int bottom = Mathf.RoundToInt(v.w); UGUIEditorTools.IntVector a = UGUIEditorTools.IntPair(prefix, "Left", "Top", left, top); UGUIEditorTools.IntVector b = UGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom); return(new Vector4(a.x, a.y, b.x, b.y)); }
/// <summary> /// Draw the inspector properties. /// </summary> public override void OnInspectorGUI() { UGUIEditorTools.SetLabelWidth(80f); EditorGUILayout.Space(); serializedObject.Update(); EditorGUI.BeginDisabledGroup(!ShouldDrawProperties()); DrawCustomProperties(); EditorGUI.EndDisabledGroup(); DrawFinalProperties(); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Draw the sprite preview. /// </summary> public override void OnPreviewGUI(Rect rect, GUIStyle background) { UGUISprite uguiSprite = target as UGUISprite; Texture2D tex = uguiSprite.mainTexture as Texture2D; if (tex == null) { return; } // UISpriteData sd = sprite.atlas.GetSprite(sprite.spriteName); UGUIEditorTools.DrawSprite(tex, rect, uguiSprite.sprite, uguiSprite.color); }
protected void DrawCommonProperties() { UITweener tw = target as UITweener; if (UGUIEditorTools.DrawHeader("Tweener")) { UGUIEditorTools.BeginContents(); UGUIEditorTools.SetLabelWidth(110f); GUI.changed = false; UITweener.Style style = (UITweener.Style)EditorGUILayout.EnumPopup("Play Style", tw.style); AnimationCurve curve = EditorGUILayout.CurveField("Animation Curve", tw.animationCurve, GUILayout.Width(170f), GUILayout.Height(62f)); //UITweener.Method method = (UITweener.Method)EditorGUILayout.EnumPopup("Play Method", tw.method); GUILayout.BeginHorizontal(); float dur = EditorGUILayout.FloatField("Duration", tw.duration, GUILayout.Width(170f)); GUILayout.Label("seconds"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); float del = EditorGUILayout.FloatField("Start Delay", tw.delay, GUILayout.Width(170f)); GUILayout.Label("seconds"); GUILayout.EndHorizontal(); int tg = EditorGUILayout.IntField("Tween Group", tw.tweenGroup, GUILayout.Width(170f)); bool ts = EditorGUILayout.Toggle("Ignore TimeScale", tw.ignoreTimeScale); if (GUI.changed) { UGUIEditorTools.RegisterUndo("Tween Change", tw); tw.animationCurve = curve; //tw.method = method; tw.style = style; tw.ignoreTimeScale = ts; tw.tweenGroup = tg; tw.duration = dur; tw.delay = del; UGUIEditorTools.SetDirty(tw); } UGUIEditorTools.EndContents(); } UGUIEditorTools.SetLabelWidth(80f); UGUIEditorTools.DrawEvents("On Finished", tw, tw.onFinished); }
/// <summary> /// Convert the specified list of delegate entries into a string array. /// </summary> static public string[] GetNames(List <Entry> list, string choice, out int index) { index = 0; string[] names = new string[list.Count + 1]; names[0] = string.IsNullOrEmpty(choice) ? "<Choose>" : choice; for (int i = 0; i < list.Count;) { Entry ent = list[i]; string del = UGUIEditorTools.GetFuncName(ent.target, ent.name); names[++i] = del; if (index == 0 && string.Equals(del, choice)) { index = i; } } return(names); }
/// <summary> /// Get a previously saved object from settings. /// </summary> static public T Get <T> (string name, T defaultValue) where T : Object { string path = EditorPrefs.GetString(name); if (string.IsNullOrEmpty(path)) { return(null); } T retVal = UGUIEditorTools.LoadAsset <T>(path); if (retVal == null) { int id; if (int.TryParse(path, out id)) { return(EditorUtility.InstanceIDToObject(id) as T); } } return(retVal); }
/// <summary> /// Draw a list of fields for the specified list of delegates. /// </summary> static public void DrawEvents(string text, Object undoObject, List <EventDelegate> list, string noTarget, string notValid, bool minimalistic) { if (!UGUIEditorTools.DrawHeader(text, text, false, minimalistic)) { return; } if (!minimalistic) { UGUIEditorTools.BeginContents(minimalistic); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); Field(undoObject, list, notValid, notValid, minimalistic); GUILayout.EndVertical(); GUILayout.EndHorizontal(); UGUIEditorTools.EndContents(); } else { Field(undoObject, list, notValid, notValid, minimalistic); } }
/// <summary> /// Helper function that draws a compact Vector4. /// </summary> static public void DrawBorderProperty(string name, SerializedObject serializedObject, string field) { if (serializedObject.FindProperty(field) != null) { GUILayout.BeginHorizontal(); { GUILayout.Label(name, GUILayout.Width(75f)); UGUIEditorTools.SetLabelWidth(50f); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("Left", serializedObject, field + ".x", GUILayout.MinWidth(80f)); UGUIEditorTools.DrawProperty("Bottom", serializedObject, field + ".y", GUILayout.MinWidth(80f)); GUILayout.EndVertical(); GUILayout.BeginVertical(); UGUIEditorTools.DrawProperty("Right", serializedObject, field + ".z", GUILayout.MinWidth(80f)); UGUIEditorTools.DrawProperty("Top", serializedObject, field + ".w", GUILayout.MinWidth(80f)); GUILayout.EndVertical(); UGUIEditorTools.SetLabelWidth(80f); } GUILayout.EndHorizontal(); } }
public override void OnInspectorGUI() { serializedObject.Update(); GUILayout.Space(6f); UGUIEditorTools.SetLabelWidth(80f); GUILayout.BeginHorizontal(); // Key not found in the localization file -- draw it as a text field SerializedProperty sp = UGUIEditorTools.DrawProperty("Key", serializedObject, "key"); string myKey = sp.stringValue; //Debug.Log(myKey); bool isPresent = !string.IsNullOrEmpty(myKey) && Localization.localizationHasBeenSet; GUI.color = isPresent ? Color.green : Color.red; GUILayout.BeginVertical(GUILayout.Width(22f)); GUILayout.Space(2f); GUILayout.Label(isPresent ? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f)); GUILayout.EndVertical(); GUI.color = Color.white; GUILayout.EndHorizontal(); if (isPresent) { if (UGUIEditorTools.DrawHeader("Preview")) { UGUIEditorTools.BeginContents(); string[] keys; string[] values; string value; if (Localization.dictionary.TryGetValue(myKey, out value)) { keys = new string[] { myKey }; values = new string[] { value }; for (int i = 0; i < keys.Length; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label(keys[i], GUILayout.Width(70f)); if (GUILayout.Button(values[i], "AS TextArea", GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f))) { (target as UGUILocalize).value = values[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } GUILayout.EndHorizontal(); } } else { GUILayout.Label("No preview available"); } UGUIEditorTools.EndContents(); } } else if (mKeys != null && !string.IsNullOrEmpty(myKey)) { GUILayout.BeginHorizontal(); GUILayout.Space(80f); GUILayout.BeginVertical(); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f); int matches = 0; for (int i = 0; i < mKeys.Count; ++i) { if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey)) { if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge")) { sp.stringValue = mKeys[i]; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } if (++matches == 8) { GUILayout.Label("...and more"); break; } } } GUI.backgroundColor = Color.white; GUILayout.EndVertical(); GUILayout.Space(22f); GUILayout.EndHorizontal(); } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { UGUIEditorTools.SetLabelWidth(80f); GUILayout.Label(mTitle, "LODLevelNotifyText"); GUILayout.Space(6f); if (mObjects == null || mObjects.Length == 0) { EditorGUILayout.HelpBox("No " + GetName(mType) + " components found.\nTry creating a new one.", MessageType.Info); bool isDone = false; EditorGUILayout.Space(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // if (mType == typeof(UIFont)) // { // if (GUILayout.Button("Open the Font Maker", GUILayout.Width(150f))) // { // EditorWindow.GetWindow<UIFontMaker>(false, "Font Maker", true).Show(); // isDone = true; // } // } // else // if (mType == typeof(UGUIAtlas)) // { // if (GUILayout.Button("Open the Atlas Maker", GUILayout.Width(150f))) // { // EditorWindow.GetWindow<UGUIAtlasMaker>(false, "Atlas Maker", true).Show(); // isDone = true; // } // } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (isDone) { Close(); } } else { Object sel = null; mScroll = GUILayout.BeginScrollView(mScroll); foreach (Object o in mObjects) { if (DrawObject(o)) { sel = o; } } GUILayout.EndScrollView(); if (sel != null) { mCallback(sel); Close(); } } if (!mSearched) { GUILayout.Space(6f); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); bool search = GUILayout.Button("Show All", "LargeButton", GUILayout.Width(120f)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (search) { Search(); } } }
/// <summary> /// Draw an editor field for the Unity Delegate. /// </summary> static public bool Field(Object undoObject, EventDelegate del, bool removeButton, bool minimalistic) { if (del == null) { return(false); } bool prev = GUI.changed; GUI.changed = false; bool retVal = false; MonoBehaviour target = del.target; bool remove = false; if (removeButton && (del.target != null || del.isValid)) { if (!minimalistic) { UGUIEditorTools.SetLabelWidth(82f); } if (del.target == null && del.isValid) { EditorGUILayout.LabelField("Notify", del.ToString()); } else { target = EditorGUILayout.ObjectField("Notify", del.target, typeof(MonoBehaviour), true) as MonoBehaviour; } GUILayout.Space(-18f); GUILayout.BeginHorizontal(); GUILayout.Space(70f); if (GUILayout.Button("", "ToggleMixed", GUILayout.Width(20f), GUILayout.Height(16f))) { target = null; remove = true; } GUILayout.EndHorizontal(); } else { target = EditorGUILayout.ObjectField("Notify", del.target, typeof(MonoBehaviour), true) as MonoBehaviour; } if (remove) { UGUIEditorTools.RegisterUndo("Delegate Selection", undoObject); del.Clear(); EditorUtility.SetDirty(undoObject); } else if (del.target != target) { UGUIEditorTools.RegisterUndo("Delegate Selection", undoObject); del.target = target; EditorUtility.SetDirty(undoObject); } if (del.target != null && del.target.gameObject != null) { GameObject go = del.target.gameObject; List <Entry> list = GetMethods(go); int index = 0; string[] names = PropertyReferenceDrawer.GetNames(list, del.ToString(), out index); int choice = 0; GUILayout.BeginHorizontal(); choice = EditorGUILayout.Popup("Method", index, names); UGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (choice > 0 && choice != index) { Entry entry = list[choice - 1]; UGUIEditorTools.RegisterUndo("Delegate Selection", undoObject); del.target = entry.target as MonoBehaviour; del.methodName = entry.name; EditorUtility.SetDirty(undoObject); retVal = true; } GUI.changed = false; EventDelegate.Parameter[] ps = del.parameters; if (ps != null) { for (int i = 0; i < ps.Length; ++i) { EventDelegate.Parameter param = ps[i]; Object obj = EditorGUILayout.ObjectField(" Arg " + i, param.obj, typeof(Object), true); if (GUI.changed) { GUI.changed = false; param.obj = obj; EditorUtility.SetDirty(undoObject); } if (obj == null) { continue; } GameObject selGO = null; System.Type type = obj.GetType(); if (type == typeof(GameObject)) { selGO = obj as GameObject; } else if (type.IsSubclassOf(typeof(Component))) { selGO = (obj as Component).gameObject; } if (selGO != null) { // Parameters must be exact -- they can't be converted like property bindings PropertyReferenceDrawer.filter = param.expectedType; PropertyReferenceDrawer.canConvert = false; List <PropertyReferenceDrawer.Entry> ents = PropertyReferenceDrawer.GetProperties(selGO, true, false); int selection; string[] props = GetNames(ents, GetFuncName(param.obj, param.field), out selection); GUILayout.BeginHorizontal(); int newSel = EditorGUILayout.Popup(" ", selection, props); UGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); if (GUI.changed) { GUI.changed = false; if (newSel == 0) { param.obj = selGO; param.field = null; } else { param.obj = ents[newSel - 1].target; param.field = ents[newSel - 1].name; } EditorUtility.SetDirty(undoObject); } } else if (!string.IsNullOrEmpty(param.field)) { param.field = null; EditorUtility.SetDirty(undoObject); } PropertyReferenceDrawer.filter = typeof(void); PropertyReferenceDrawer.canConvert = true; } } } else { retVal = GUI.changed; } GUI.changed = prev; return(retVal); }
/// <summary> /// Draw the specified sprite. /// </summary> public static void DrawTexture(Texture2D tex, Rect rect, Rect uv, Color color, Material mat) { int w = Mathf.RoundToInt(tex.width * uv.width); int h = Mathf.RoundToInt(tex.height * uv.height); // Create the texture rectangle that is centered inside rect. Rect outerRect = rect; outerRect.width = w; outerRect.height = h; if (outerRect.width > 0f) { float f = rect.width / outerRect.width; outerRect.width *= f; outerRect.height *= f; } if (rect.height > outerRect.height) { outerRect.y += (rect.height - outerRect.height) * 0.5f; } else if (outerRect.height > rect.height) { float f = rect.height / outerRect.height; outerRect.width *= f; outerRect.height *= f; } if (rect.width > outerRect.width) { outerRect.x += (rect.width - outerRect.width) * 0.5f; } // Draw the background UGUIEditorTools.DrawTiledTexture(outerRect, UGUIEditorTools.backdropTexture); // Draw the sprite GUI.color = color; if (mat == null) { GUI.DrawTextureWithTexCoords(outerRect, tex, uv, true); } else { // NOTE: There is an issue in Unity that prevents it from clipping the drawn preview // using BeginGroup/EndGroup, and there is no way to specify a UV rect... le'suq. UnityEditor.EditorGUI.DrawPreviewTexture(outerRect, tex, mat); } GUI.color = Color.white; // Draw the lines around the sprite Handles.color = Color.black; Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMin, outerRect.yMax)); Handles.DrawLine(new Vector3(outerRect.xMax, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMax)); Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMin)); Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMax), new Vector3(outerRect.xMax, outerRect.yMax)); // Sprite size label string text = string.Format("Texture Size: {0}x{1}", w, h); EditorGUI.DropShadowLabel(GUILayoutUtility.GetRect(Screen.width, 18f), text); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { EditorGUIUtility.labelWidth = 80; if (UGUISettings.atlas == null) { GUILayout.Label("No Atlas selected.", "LODLevelNotifyText"); } else { UGUIAtlas atlas = UGUISettings.atlas; bool close = false; GUILayout.Label(atlas.name + " Sprites", "LODLevelNotifyText"); UGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string before = UGUISettings.partialSprite; string after = EditorGUILayout.TextField("", before, "SearchTextField"); if (before != after) { UGUISettings.partialSprite = after; } if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f))) { UGUISettings.partialSprite = ""; GUIUtility.keyboardControl = 0; } GUILayout.Space(84f); GUILayout.EndHorizontal(); // Texture2D tex = atlas.mainTexture as Texture2D; // // if (tex == null) // { // GUILayout.Label("The atlas doesn't have a texture to work with"); // return; // } BetterList <string> sprites = atlas.GetListOfSprites(UGUISettings.partialSprite); float size = 80f; float padded = size + 10f; int columns = Mathf.FloorToInt(Screen.width / padded) / 2; if (columns < 1) { columns = 1; } // Debug.LogWarning (columns); int offset = 0; Rect rect = new Rect(10f, 0, size, size); GUILayout.Space(10f); mPos = GUILayout.BeginScrollView(mPos); int rows = 1; while (offset < sprites.size) { GUILayout.BeginHorizontal(); { int col = 0; rect.x = 10f; for (; offset < sprites.size; ++offset) { Sprite sprite = atlas.GetSprite(sprites[offset]); if (sprite == null) { continue; } // Button comes first if (GUI.Button(rect, "")) { if (Event.current.button == 0) { float delta = Time.realtimeSinceStartup - mClickTime; mClickTime = Time.realtimeSinceStartup; if (UGUISettings.selectedSprite != sprite.name) { if (mSprite != null) { UGUIEditorTools.RegisterUndo("Atlas Selection", mSprite); mSprite.SetNativeSize(); EditorUtility.SetDirty(mSprite.gameObject); } UGUISettings.selectedSprite = sprite.name; UGUIEditorTools.RepaintSprites(); if (mCallback != null) { mCallback(sprite.name); } } else if (delta < 0.5f) { close = true; } } else { // NGUIContextMenu.AddItem("Edit", false, EditSprite, sprite); // NGUIContextMenu.AddItem("Delete", false, DeleteSprite, sprite); // NGUIContextMenu.Show(); } } if (Event.current.type == EventType.Repaint) { // On top of the button we have a checkboard grid UGUIEditorTools.DrawTiledTexture(rect, UGUIEditorTools.backdropTexture); // Rect uv = new Rect(sprite.rect.x, sprite.rect.y, sprite.rect.width, sprite.rect.height); // uv = UGUIMath.ConvertToTexCoords(uv, tex.width, tex.height); // Calculate the texture's scale that's needed to display the sprite in the clipped area // float scaleX = rect.width / uv.width; // float scaleY = rect.height / uv.height; // Stretch the sprite so that it will appear proper // float aspect = (scaleY / scaleX) / ((float)tex.height / tex.width); // Rect clipRect = rect; // // if (aspect != 1f) // { // if (aspect < 1f) // { // // The sprite is taller than it is wider // float padding = size * (1f - aspect) * 0.5f; // clipRect.xMin += padding; // clipRect.xMax -= padding; // } // else // { // // The sprite is wider than it is taller // float padding = size * (1f - 1f / aspect) * 0.5f; // clipRect.yMin += padding; // clipRect.yMax -= padding; // } // } GUI.DrawTexture(rect, sprite.texture); // Draw the selection if (UGUISettings.selectedSprite == sprite.name) { UGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } } GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); GUI.contentColor = new Color(1f, 1f, 1f, 0.7f); GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), sprite.name, "ProgressBarBack"); GUI.contentColor = Color.white; GUI.backgroundColor = Color.white; if (++col >= columns) { ++offset; break; } rect.x += padded; } } GUILayout.EndHorizontal(); GUILayout.Space(padded); rect.y += padded + 26; ++rows; } GUILayout.Space(rows * 26); GUILayout.EndScrollView(); if (close) { Close(); } } }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { UGUIEditorTools.SetLabelWidth(80f); mAtlas = target as UGUIAtlas; Sprite sprite = (mAtlas != null) ? mAtlas.GetSprite(UGUISettings.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); UGUIEditorTools.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 <UGUIAtlas>(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) { UGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); mAtlas.replacement = mReplacement; UGUITools.SetDirty(mAtlas); } return; } GUILayout.Space(6f); // Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material; // // if (mAtlas.spriteMaterial != mat) // { // UGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); // mAtlas.spriteMaterial = mat; // // // Ensure that this atlas has valid import settings // if (mAtlas.texture != null) UGUIEditorTools.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) UGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha); // // UGUIEditorTools.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) // { // UGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); // mAtlas.pixelSize = pixelSize; // } // } // if (mAtlas.mainTexture != 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 = UGUISettings.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.mainTexture as Texture2D; // if (tex != null) { if (!UGUIEditorTools.DrawHeader("Sprite Details")) { return; } UGUIEditorTools.BeginContents(); GUILayout.Space(3f); UGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true); GUILayout.Space(6f); GUI.changed = false; GUI.backgroundColor = greenColor; UGUIEditorTools.IntVector sizeA = UGUIEditorTools.IntPair("Dimensions", "X", "Y", (int)sprite.textureRect.x, (int)sprite.textureRect.y); UGUIEditorTools.IntVector sizeB = UGUIEditorTools.IntPair(null, "Width", "Height", (int)sprite.textureRect.width, (int)sprite.textureRect.height); EditorGUILayout.Separator(); GUI.backgroundColor = blueColor; UGUIEditorTools.IntVector borderA = UGUIEditorTools.IntPair("Border", "Left", "Right", (int)sprite.border.x, (int)sprite.border.y); UGUIEditorTools.IntVector borderB = UGUIEditorTools.IntPair(null, "Bottom", "Top", (int)sprite.border.y, (int)sprite.border.z); EditorGUILayout.Separator(); GUI.backgroundColor = Color.white; UGUIEditorTools.IntVector padA = UGUIEditorTools.IntPair("Padding", "Left", "Right", (int)sprite.rect.xMin, (int)sprite.rect.xMax); UGUIEditorTools.IntVector padB = UGUIEditorTools.IntPair(null, "Bottom", "Top", (int)sprite.rect.yMax, (int)sprite.rect.yMin); if (GUI.changed) { // UGUIEditorTools.RegisterUndo("Atlas Change", mAtlas); // // sprite.rect.x = sizeA.x; // sprite.rect.y = sizeA.y; // sprite.rect.width = sizeB.x; // sprite.rect.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")) // { // UGUIAtlasMaker.SpriteEntry se = UGUIAtlasMaker.DuplicateSprite(mAtlas, sprite.name); // if (se != null) UGUISettings.selectedSprite = se.name; // } // if (GUILayout.Button("Save As...")) // { // #if UNITY_3_5 // string path = EditorUtility.SaveFilePanel("Save As", // UGUISettings.currentPath, sprite.name + ".png", "png"); // #else // string path = EditorUtility.SaveFilePanelInProject("Save As", // sprite.name + ".png", "png", // "Extract sprite into which file?", UGUISettings.currentPath); // #endif // // if (!string.IsNullOrEmpty(path)) // { // UGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); // UGUIAtlasMaker.SpriteEntry se = UGUIAtlasMaker.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(); UGUIEditorTools.EndContents(); } if (UGUIEditorTools.DrawHeader("Modify")) { UGUIEditorTools.BeginContents(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); EditorGUILayout.BeginVertical(); UGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", UGUISettings.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(); UGUIEditorTools.EndContents(); } if (UGUIEditorTools.previousSelection != null) { GUILayout.Space(3f); GUI.backgroundColor = Color.green; if (GUILayout.Button("<< Return to " + UGUIEditorTools.previousSelection.name)) { UGUIEditorTools.SelectPrevious(); } GUI.backgroundColor = Color.white; } } } }