public virtual void Show(string alertTitleString_, string confirmationBtnString_, string[] otherBtnStrings_, bool showTitleIcon_) { if (Application.isEditor && !Application.isPlaying) { Debug.LogWarning("Show can only be called in play mode"); return; } InitializeLabelWithTextSafely(titleLabel, alertTitleString_); InitializeSlicedButtonWithTextSafely(confirmationButton, confirmationBtnString_); if (otherBtnStrings_ != null && cancelButton != null) { int buttonIndex_ = 0; foreach (string btnTitle_ in otherBtnStrings_) { UISlicedImageButton button_ = null; if (buttonIndex_ == 0) { button_ = cancelButton; } else //make new instance of button { GameObject go = NGUITools.AddChild(buttonsGroupTransform.gameObject, cancelButton.gameObject); go.transform.localPosition = cancelButton.transform.localPosition; UIButtonMessage btnMsg = go.AddComponent <UIButtonMessage>(); btnMsg.functionName = "OnButton"; btnMsg.target = gameObject; button_ = go.GetComponent <UISlicedImageButton>(); } NGUITools.SetActive(button_.gameObject, true); button_.SetTitle(btnTitle_); button_.Commit(); button_.name = buttonIndex_ + ".Other button"; buttonIndex_++; } } else if (cancelButton != null) { // there is no cancel button NGUITools.SetActive(cancelButton.gameObject, false); } if (titleIconSprite != null) { NGUITools.SetActive(titleIconSprite.gameObject, showTitleIcon_); } Reposition(); Present(); }
public void InitializeSlicedButtonWithTextSafely(UISlicedImageButton button, string text) { if (string.IsNullOrEmpty(text)) { if (button != null) { NGUITools.SetActive(button.gameObject, false); } } else { if (button != null) { NGUITools.SetActive(button.gameObject, true); button.SetTitle(text); button.Commit(); } } }
public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(); mButton = target as UISlicedImageButton; mSprite = EditorGUILayout.ObjectField("Sprite", mButton.sprite, typeof(UISprite), true) as UISprite; mIconSprite = EditorGUILayout.ObjectField("Icon Sprite", mButton.iconSprite, typeof(UISprite), true) as UISprite; //////////////// SPRITE /////////////////////// if (mButton.sprite != mSprite) { NGUIEditorTools.RegisterUndo("Image Button Change", mButton); mButton.sprite = mSprite; if (mSprite != null) { mSprite.spriteName = mButton.normalImageName; } UpdateSizes(); } if (mSprite != null) { ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectSpriteAtlas); if (mSprite.atlas != null) { NGUIEditorTools.SpriteField("Normal", mSprite.atlas, mButton.normalImageName, OnNormal); NGUIEditorTools.SpriteField("Pressed", mSprite.atlas, mButton.pressedImageName, OnPressed); NGUIEditorTools.SpriteField("Hover", mSprite.atlas, mButton.hoverImageName, OnHover); } } //////////////// ICON SPRITE /////////////////// if (mButton.iconSprite != mIconSprite) { NGUIEditorTools.RegisterUndo("Image Button Change", mButton); mButton.iconSprite = mIconSprite; if (mIconSprite != null) { mIconSprite.spriteName = mButton.iconImageName; } UpdateSizes(); } if (mIconSprite != null) { ComponentSelector.Draw <UIAtlas>(mIconSprite.atlas, OnSelectIconSpriteAtlas); if (mIconSprite != null) { NGUIEditorTools.SpriteField("Icon", mIconSprite.atlas, mButton.iconImageName, OnIconChanged); } } if (mButton.iconSprite != mIconSprite) { NGUIEditorTools.RegisterUndo("Image Button Change", mButton); mButton.iconSprite = mIconSprite; if (mIconSprite != null) { mIconSprite.spriteName = mButton.iconImageName; } UpdateSizes(); } ///////////////////////////////////////////////// bool needUpdate = false; //isHighlighted mIsEnabled = EditorGUILayout.Toggle("Enabled", mButton.isEnabled, GUILayout.Width(500)); if (mButton.isEnabled != mIsEnabled) { mButton.isEnabled = mIsEnabled; needUpdate = true; } mDisabledColor = EditorGUILayout.ColorField("Disabled Color", mButton.disabledColor, GUILayout.Width(150)); if (mButton.disabledColor != mDisabledColor) { mButton.disabledColor = mDisabledColor; needUpdate = true; } //public UILabel titleLabe mTitleLabel = EditorGUILayout.ObjectField("Title Label", mButton.titleLabel, typeof(UILabel), true) as UILabel; if (mButton.titleLabel != mTitleLabel) { mButton.titleLabel = mTitleLabel; if (mTitleLabel != null) { mTitleLabel.text = "Title"; } } if (mTitleLabel != null) { mTitleLabelText = EditorGUILayout.TextField("Label Text", mButton.titleLabel.text, GUILayout.Width(500)); if (string.Compare(mButton.titleLabel.text, mTitleLabelText, false) != 0) { mButton.titleLabel.text = mTitleLabelText; needUpdate = true; } } //public UISlicedImageButtonPivot pivot mPivot = (UIImageButtonPivot)EditorGUILayout.EnumPopup("Pivot", mButton.pivot); if (mButton.pivot != mPivot) { mButton.pivot = mPivot; needUpdate = true; } // leftInsetPx mLeftInset = EditorGUILayout.FloatField("Left Inset", mButton.leftInsetPx); if (mButton.leftInsetPx != mLeftInset) { mButton.leftInsetPx = mLeftInset; needUpdate = true; } // rightInsetPx mRightInset = EditorGUILayout.FloatField("Right Inset", mButton.rightInsetPx); if (mButton.rightInsetPx != mRightInset) { mButton.rightInsetPx = mRightInset; needUpdate = true; } // minWidthPx if (mIconSprite != null && mLeftInset > 0) { mIconCenter = EditorGUILayout.IntSlider("Icon Center", mButton.iconCenterPx, 0, (int)mLeftInset, GUILayout.Width(500)); if (mButton.iconCenterPx != mIconCenter) { mButton.iconCenterPx = mIconCenter; needUpdate = true; } } // minWidthPx mMinWidth = EditorGUILayout.FloatField("Min Width", mButton.minWidthPx); if (mButton.minWidthPx != mMinWidth) { mButton.minWidthPx = mMinWidth; needUpdate = true; } mMinHeight = EditorGUILayout.FloatField("Min Height", mButton.minHeightPx); if (mButton.minHeightPx != mMinHeight) { mButton.minHeightPx = mMinHeight; needUpdate = true; } if (needUpdate) { EditorUtility.SetDirty(target); } }