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> /// 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); } }
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 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; } } } }