FairyGUI筆記:下拉框(十五)
阿新 • • 發佈:2018-12-20
-
GComboBox
我們可以在編輯器編輯下拉列表的專案,也可以用程式碼動態設定
GComboBox combo = gcom.GetChild("n1").asComboBox; //items是列表專案標題的陣列。 combo.items = new string[] { "Item 1", "Item 2", ...}; //values是可選的,代表每個列表專案的value。 combo.values = new string[] { "value1", "value2", ...}; //獲得當前選中項的索引 Debug.Log(combo.selectedIndex); //獲得當前選中項的value。 Debug.Log(combo.value); //設定選中項,通過索引 combo.selectedIndex = 1; //設定選中項,通過value combo.value = "value1";
下拉框選擇改變時有通知事件:
//Unity/Cry combo.onChanged.Add(onChanged); //AS3 combo.addEventListener(StateChangeEvent.CHANGED, onChanged); //Egret combo.addEventListener(fairygui.StateChangeEvent.CHANGED, this.onChanged, this); //Laya combo.on(fairygui.Events.STATE_CHANGED, this, this.onChanged); //Cocos2dx combo->addEventListener(UIEventType::Changed, CC_CALLBACK_1(AClass::onChanged, this));
點選空白處後彈出框會自動關閉,如果要獲得這個關閉的通知,可以監聽移出舞臺的事件,例如:
//Unity/Cry combo.dropdown.onRemoveFromStage.Add(onPopupClosed); //AS3 combo.dropdown.addEventListener(Event.REMOVED_FROM_STAGE, onPopupClosed); //Egret combo.dropdown.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onPopupClosed, this); //Laya combo.dropdown.on(laya.events.Event.UNDISPLAY, this, this.onPopupClosed); //Cocos2dx combo->getDropdown()->addEventListener(UIEventType::Exit, CC_CALLBACK_1(AClass::onPopupClosed, this));
如果要手工關閉彈出框:
GRoot.inst.HidePopup();