/// <summary> /// 设置btns数组下对应按钮属性 /// </summary> /// <param name="buttonObject">btns数组中对应的按钮(如果buttonObject不存在于btns数组中,不会进行任何操作)</param> public void SetButton(IMCButton buttonObject, MessageBoxButtonAttribute buttonAttribute) { if (btns.Contains(buttonObject)) { MSetButton(buttonObject, buttonAttribute.buttonTitle, buttonAttribute.buttonSprite, buttonAttribute.buttonAction); } }
/// <summary> /// 设置btns数组下对应按钮属性 /// </summary> /// <param name="buttonObject">btns数组中对应的按钮(如果buttonObject不存在于btns数组中,不会进行任何操作)</param> public void SetButton(IMCButton buttonObject, string buttonTitle = "", Sprite buttonSprite = null, UnityAction buttonAction = null) { if (btns.Contains(buttonObject)) { MSetButton(buttonObject, buttonTitle, buttonSprite, buttonAction); } }
public static GameObject CreateButton(Resources resources) { GameObject buttonRoot = CreateUIElementRoot("IMC Button", s_ThickElementSize); GameObject childText = new GameObject("Text"); SetParentAndAlign(childText, buttonRoot); IMCImage image = buttonRoot.AddComponent <IMCImage>(); image.sprite = resources.standard; image.type = IMCImage.Type.Sliced; image.color = s_DefaultSelectableColor; IMCButton bt = buttonRoot.AddComponent <IMCButton>(); SetDefaultColorTransitionValues(bt); IMCText text = childText.AddComponent <IMCText>(); text.raycastTarget = false; text.text = "IMC Button"; text.alignment = TextAnchor.MiddleCenter; SetDefaultTextValues(text); RectTransform textRectTransform = childText.GetComponent <RectTransform>(); textRectTransform.anchorMin = Vector2.zero; textRectTransform.anchorMax = Vector2.one; textRectTransform.sizeDelta = Vector2.zero; return(buttonRoot); }
/// <summary> /// 移除btns数组中指定的按钮 /// </summary> /// <param name="buttonObject">btn数组中的button对象(如果buttonObject不存在于btns数组中,不会进行任何操作)</param> public void RemoveButtonElement(IMCButton buttonObject) { if (btns.Contains(buttonObject)) { btns.Remove(buttonObject); Destroy(buttonObject.gameObject); } }
/// <summary> /// 移除btns数组中指定的按钮 /// </summary> /// <param name="buttonIndex">btns数组中的索引(如果索引值非法,不会进行任何操作)</param> public void RemovButtonElement(int buttonIndex) { if (buttonIndex >= 0 && buttonIndex <= btns.Count - 1) { IMCButton tempButton = btns[buttonIndex]; btns.Remove(tempButton); tempButton.UnInit(); } }
private void MSetButton(IMCButton buttonObject, string buttonTitle, Sprite buttonSprite, UnityAction buttonAction) { if (buttonObject.Text && buttonTitle != "") { buttonObject.Text.text = buttonTitle; } if (buttonAction != null) { buttonObject.AddListener(buttonAction); } if (buttonSprite != null) { buttonObject.image.sprite = buttonSprite; } }
public static GameObject CreateOrderShowButtons(Resources resources) { GameObject go = CreateImage(resources); go.name = "IMC Order Show Buttons"; go.AddComponent <CanvasGroup>(); IMCImage tempIma = go.GetComponent <IMCImage>(); IMCOrderShowButtons orderShowButtons = go.AddComponent <IMCOrderShowButtons>(); GameObject leftBtn = CreateButton(resources); leftBtn.name = "LeftButton"; IMCButton tempLeftBtn = leftBtn.GetComponent <IMCButton>(); tempLeftBtn.anchorMin = new Vector2(0, 0.5f); tempLeftBtn.anchorMax = new Vector2(0, 0.5f); tempLeftBtn.pivot = new Vector2(0, 0.5f); tempLeftBtn.Text.text = "LeftButton"; GameObject rightBtn = CreateButton(resources); rightBtn.name = "RightButton"; IMCButton tempRightBtn = rightBtn.GetComponent <IMCButton>(); tempRightBtn.anchorMin = new Vector2(1, 0.5f); tempRightBtn.anchorMax = new Vector2(1, 0.5f); tempRightBtn.pivot = new Vector2(1, 0.5f); tempRightBtn.Text.text = "RightButton"; tempIma.color = new Color(0, 0, 0, 0); tempIma.sizeDelta = new Vector2(tempLeftBtn.sizeDelta.x * 3, tempLeftBtn.sizeDelta.y); leftBtn.transform.SetParent(orderShowButtons.transform); tempLeftBtn.anchoredPosition3D = Vector3.zero; rightBtn.transform.SetParent(orderShowButtons.transform); tempRightBtn.anchoredPosition3D = Vector3.zero; orderShowButtons.leftBtn = leftBtn.GetComponent <IMCButton>(); orderShowButtons.rightBtn = rightBtn.GetComponent <IMCButton>(); return(go); }
protected virtual GameObject CreateBlocker(Canvas rootCanvas) { // Create blocker GameObject. GameObject blocker = new GameObject("Blocker"); // Setup blocker RectTransform to cover entire root canvas area. RectTransform blockerRect = blocker.AddComponent <RectTransform>(); blockerRect.SetParent(rootCanvas.transform, false); blockerRect.anchorMin = Vector3.zero; blockerRect.anchorMax = Vector3.one; blockerRect.sizeDelta = Vector2.zero; // Make blocker be in separate canvas in same layer as dropdown and in layer just below it. Canvas blockerCanvas = blocker.AddComponent <Canvas>(); blockerCanvas.overrideSorting = true; Canvas dropdownCanvas = m_Dropdown.GetComponent <Canvas>(); blockerCanvas.sortingLayerID = dropdownCanvas.sortingLayerID; blockerCanvas.sortingOrder = dropdownCanvas.sortingOrder - 1; // Add raycaster since it's needed to block. blocker.AddComponent <IMCGraphicRaycaster>(); // Add image since it's needed to block, but make it clear. IMCImage blockerImage = blocker.AddComponent <IMCImage>(); blockerImage.color = Color.clear; // Add button since it's needed to block, and to close the dropdown when blocking area is clicked. IMCButton blockerButton = blocker.AddComponent <IMCButton>(); blockerButton.onClick.AddListener(Hide); return(blocker); }