本文整理汇总了C#中ComboBox.comboButtonPressed方法的典型用法代码示例。如果您正苦于以下问题:C# ComboBox.comboButtonPressed方法的具体用法?C# ComboBox.comboButtonPressed怎么用?C# ComboBox.comboButtonPressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComboBox
的用法示例。
在下文中一共展示了ComboBox.comboButtonPressed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddButton
public static void AddButton(ComboBox box, string text)
{
//Debug.Log("Adding button...");
GameObject panel = box.transform.FindChild("Panel").gameObject;
List<GameObject> children = new List<GameObject>(box.transform.FindChild("Panel").childCount);
for (int i = 0; i < box.transform.FindChild("Panel").childCount; i++)
children.Add(panel.transform.GetChild(i).gameObject);
if (children.Exists(child => child.transform.FindChild("Text").GetComponent<Text>().text == text)) return;
GameObject newButton = GameObject.Instantiate(box.transform.FindChild("ComboButton").gameObject) as GameObject;
GameObject parent = box.transform.parent.gameObject;
float canvasScaleFactor = box.RootCanvas.GetComponent<Canvas>().scaleFactor;
newButton.transform.SetParent(box.gameObject.transform.FindChild("Panel"));
newButton.GetComponent<Button>().onClick.RemoveAllListeners();
newButton.GetComponent<Button>().onClick.AddListener(() => box.comboButtonPressed(newButton));
newButton.transform.FindChild("Text").GetComponent<Text>().text = text;
RectTransform buttonTransform = newButton.GetComponent<RectTransform>();
RectTransform panelTransform = box.gameObject.transform.FindChild("Panel").gameObject.GetComponent<RectTransform>();
Rect buttonRect = buttonTransform.rect;
Rect panelRect = panelTransform.rect;
//float distance = box.ButtonDistance / canvasScaleFactor;
//Debug.Log(distance);
float offset = buttonRect.height * (box.buttons.Count); //+ distance;
Vector2 panelPos = panelTransform.anchoredPosition;
//Debug.Log(panelPos);
Vector2 buttonPos = new Vector2(panelTransform.anchoredPosition.x, panelTransform.anchoredPosition.y - offset);
//Debug.Log (buttonPos);
buttonTransform.anchoredPosition = buttonPos;
float newHeigth = buttonRect.height * (box.buttons.Count + 1.0f);// + distance;
panelTransform.sizeDelta = new Vector2(panelRect.width, newHeigth);
newButton.transform.localScale = newButton.transform.localScale * canvasScaleFactor;
box.buttons.Add(newButton);
if (box.buttons.Count == 1)
box.transform.FindChild("ComboButton").FindChild("Text").gameObject.GetComponent<Text>().text = text;
}