private void InitToggleGroup() { mToggleGroup = new ToggleGroup<Panel>(); foreach (Panel p in menuTopPanel.Children) { mToggleGroup.Items.Add(p); } foreach (Panel p in menuBottomPanel.Children) { mToggleGroup.Items.Add(p); } mToggleGroup.StateChanged += (item, selected) => { if (item == null) { return; } if (selected) { item.Background = new SolidColorBrush(Color.FromArgb(0xff, 0x99, 0xc1, 0x5c)); } else { item.Background = new SolidColorBrush(Color.FromArgb(0x00, 0x00, 0x00, 0x00)); } }; }
private int _lastRoleIndex = 2;//假装记录上次选择的角色 private void Awake() { _roleListContent = transform.Find("RoleList/Viewport/Content").gameObject; _btnEnter = transform.Find("BtnEnter").GetComponent <Button>(); _roleListToggleGroup = _roleListContent.GetComponent <ToggleGroup>(); _btnEnter.onClick.AddListener(onBtnEnterClick); _modelTouchRotate = gameObject.Find <TouchEX>("TouchRotate"); //处理模型摄影棚部分 _modelStudio = new ModelStudio(); _modelStudio.Init(); //前面的地址变成了后面的地址 //_modelTouchRotate.target = _modelPositon.transform; _modelTouchRotate.DragCallback = OnTouchRotate; //初始化角色列表,用表格读取角色从1开始累加/通过服务器读取从0开始累加 int i = 0; foreach (var roleInfo in UserData.instance.allRole) //foreach(var roleInfo in RoleTable.instance.GetAll()) { var roleItem = ResourcesManager.instance.GetInstance(("UIPrefabs/SelectRole/RoleItem"), _roleListContent.transform); //获取roleItem的text和image var textName = roleItem.transform.Find("Label").GetComponent <Text>(); var toggle = roleItem.GetComponent <Toggle>(); toggle.group = _roleListToggleGroup; textName.text = roleInfo.name; //textName.text = roleInfo.Value.name; //用闭包实现角色索引和Toggle的绑定 var index = i; ++i; toggle.onValueChanged.AddListener((isOn) => { OnToggleValueChanged(index, isOn); }); //默认选中 toggle.isOn = index == _lastRoleIndex; } }
public void InitializeLoadGamePanel() { var metas = SaveController.Instance.loadSaveMetas(); var panelContent = loadGamePanel.GetComponentInChildren <TargetAnchor>().gameObject; DestroyAllChildren(panelContent.transform); this.saveSelection.Clear(); ToggleGroup toggleGroup = panelContent.GetComponent <ToggleGroup>(); foreach (var meta in metas) { var option = ConstructSingleLoadGameOption(meta); var saveGameSelectionController = option.GetComponent <SaveGameSelectionController>(); saveGameSelectionController.toggleGroup = toggleGroup; saveGameSelectionController.menuController = this; option.transform.SetParent(panelContent.transform, false); } }
private IEnumerator Start() { toggleGroup = GetComponent <ToggleGroup>(); if (toggleGroup != null) { yield return(null); toggles = GetComponentsInChildren <Toggle>(); foreach (var toggle in toggles) { if (toggle != null) { if (toggle.group == null || overrideGroup) { toggle.group = toggleGroup; } } } } }
static int set_allowSwitchOff(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); ToggleGroup obj = (ToggleGroup)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name allowSwitchOff"); } else { LuaDLL.luaL_error(L, "attempt to index allowSwitchOff on a nil value"); } } obj.allowSwitchOff = LuaScriptMgr.GetBoolean(L, 3); return(0); }
private void Awake() { dayTexts = new List <Text[]>(); dayToggles = new List <Toggle[]>(); toggleGroup = GetComponent <ToggleGroup>(); foreach (RectTransform rect in rows) { //add all child rect the the dayTexts.Add(rect.GetComponentsInChildren <Text>()); Toggle[] toggles = rect.GetComponentsInChildren <Toggle>(); dayToggles.Add(toggles); foreach (Toggle toggle in toggles) { toggle.group = toggleGroup; } } selectedDay = DateTime.Now.Day; selectedMonth = DateTime.Now.Month; }
/// <summary> /// 当前选中的高亮:设置文字颜色 /// </summary> public static void CurrentToggleHighlight(GameObject group, Color normal, Color highlight) { ToggleGroup toggleGroup = group.GetComponent <ToggleGroup>(); if (toggleGroup == null) { throw new Exception("ToggleGroup is necessary"); } for (int i = 0; i < group.transform.childCount; i++) { Toggle tab = group.transform.GetChild(i).gameObject.GetComponent <Toggle>(); Text label = group.transform.GetChild(i).Find("Label").GetComponent <Text>(); if (tab.isOn) { label.color = highlight; } else { label.color = normal; } } }
// Use this for initialization void Start() { if (this.difficultyModeGroup == null) { GameObject[] menu = GameObject.FindGameObjectsWithTag("Menu"); if (menu != null && menu.Length > 0) { foreach (GameObject obj in menu) { if (obj.GetComponent <DifficultyGroup>() != null) { this.difficultyModeGroup = obj.GetComponent <ToggleGroup>(); break; } } } if (this.difficultyModeGroup == null) { Debug.LogError("Toggle group isn't set. Please check."); } } }
public void Show(ItemTeamData itd) { this.root.SetParent(a3_teamMemberList.contant); ToggleGroup component = a3_teamMemberList.contant.GetComponent <ToggleGroup>(); this.toggle.GetComponent <Toggle>().group = component; this.root.localScale = Vector3.one; this.root.SetAsLastSibling(); this.txtName.text = itd.name; this.txtLvl.text = string.Concat(new object[] { itd.zhuan, "转", itd.lvl, "级" }); this.txtKnightage.text = itd.knightage; this.txtMap.text = ((SvrMapConfig.instance.getSingleMapConf(itd.mapId) == null) ? "" : SvrMapConfig.instance.getSingleMapConf(itd.mapId)["map_name"]._str); this.iconCaptain.gameObject.SetActive(itd.isCaptain); this.iconCarr.sprite = a3_teamMemberList._instance.iconSpriteDic[itd.carr]; this.root.gameObject.SetActive(true); }
//set options public void setOptions(GameObject optionprefab, GameObject DishContent) { GameObject optionsContent = DishContent.transform.Find("OptionList/ScrollRect/Content").gameObject; for (int i = 0; i < optionsContent.transform.childCount; i++) { Destroy(optionsContent.transform.GetChild(i).gameObject); } optionlist = new List <GameObject>(); optionsContent.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0); //referencing the toggleGroup in order to group all the toggles (options) into one Toggle Group Transform _optionList = menuinfoTransform.gameObject.transform.Find("OptionList/ScrollRect/"); ToggleGroup toggleGroup = _optionList.Find("Content").GetComponent <ToggleGroup>(); for (int i = 0; content.options != null && i < content.options.Count; i++) { GameObject option = GameObject.Instantiate(optionprefab); option.transform.SetParent(optionsContent.transform); option.transform.localScale = new Vector3(1, 1, 1); option.transform.localPosition = new Vector3(i * 360 + 60, -50, 0); option.transform.Find("Text").GetComponent <Text>().text = content.options[i]; if (i == 0) { option.GetComponent <Toggle>().isOn = true; } else { option.GetComponent <Toggle>().isOn = false; } //set the toggleGroup option.GetComponent <Toggle>().group = toggleGroup; optionsContent.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, ((RectTransform)optionsContent.transform).rect.width + 360); optionlist.Add(option); } }
public unsafe void Initialise(DeckPresetPanel parent, Sprite sprite, ToggleGroup group, Action <DeckSlot> OnEdit) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) m_bgDefaultVisual.SetActive(false); m_editButton.get_gameObject().SetActive(false); m_slectedOutline.set_enabled(false); m_deckIcon.set_sprite(sprite); m_toggle = this.GetComponent <AnimatedToggleButton>(); m_toggle.onValueChanged.AddListener(new UnityAction <bool>((object)this, (IntPtr)(void *) /*OpCode not supported: LdFtn*/)); _003C_003Ec__DisplayClass18_0 _003C_003Ec__DisplayClass18_; m_editButton.get_onClick().AddListener(new UnityAction((object)_003C_003Ec__DisplayClass18_, (IntPtr)(void *) /*OpCode not supported: LdFtn*/)); m_rectTransform = this.GetComponent <RectTransform>(); m_defaultSizeDelta = m_rectTransform.get_sizeDelta(); m_selectedSizeDelta = m_defaultSizeDelta; m_selectedSizeDelta.x *= 1.11f; }
public void SetInfo(int heroId, string name, string coin, string money, ToggleGroup tg) { HeroId = heroId; Name.text = name; Coin = coin; Money = money; ResourceLoader.LoadAssetAndInstantiate(string.Format("PrefabUI/Main/Hero/{0}", HeroId), transform, new Vector3(-136f, 50f)); ResourceLoader.LoadAssetAndInstantiate(string.Format("PrefabUI/Main/Item/{0}", HeroId), transform, new Vector3(-5.7f, 10f)); Toggle.group = tg; BuyBtn.gameObject.SetActive(Coin != "0" && Money != "0"); CoinBtn.gameObject.SetActive(Coin != "0" && Money == "0"); MoneyBtn.gameObject.SetActive(Coin == "0" && Money != "0"); if (Coin != "0" && Money != "0") { CoinBtn.transform.localPosition = new Vector2(176f, -116f); MoneyBtn.transform.localPosition = new Vector2(176f, -116f + 71f); CoinBtn.transform.localScale = new Vector3(0.45f, 0.5f, 1f); MoneyBtn.transform.localScale = new Vector3(0.45f, 0.5f, 1f); } }
private new void Awake() { base.Awake(); musicSelectTF = CptUtil.getCptFormParentByName <Transform, Transform>(transform, "Content"); if (musicSelectTF != null) { musicSelect = musicSelectTF.gameObject.AddComponent <GameMusicDetails>(); musicSelect.addMusicSelectCallBack(this); musicSelect.loadData(); } musicSwitchGroup = CptUtil.getCptFormParentByName <Transform, ToggleGroup>(transform, "GameMusicSwitch"); if (musicSwitchGroup != null) { musicSwitchCpt = musicSwitchGroup.gameObject.AddComponent <GameMusicSwitch>(); musicSwitchCpt.addRadioButtonCallBack(this); } gameCancelBT = CptUtil.getCptFormParentByName <Transform, Button>(transform, "GameCancelBT"); gameCancelBT.onClick.AddListener(cancelUI); }
void Awake() { mAvatarImg = transform.Find("avatar").GetComponent <RawImage>(); mAvatarSpawnPos = GameObject.FindGameObjectWithTag(Tags.AvatarCamTag).transform.Find("SpawnPos"); mWeaponTogGroup = transform.Find("weapon").GetComponent <ToggleGroup>(); mWeaponGrid = transform.Find("weapon/scroll/gridlayout").GetComponent <GridLayoutGroup>(); mEnterBtn = transform.Find("enter").GetComponent <Button>(); mReturnBtn = transform.Find("return").GetComponent <Button>(); UIEventListener.Get(mAvatarImg.gameObject).onDrag += OnDragAvatarImage; UIEventListener.Get(mEnterBtn.gameObject).onClick += OnEnterBtnClick; UIEventListener.Get(mReturnBtn.gameObject).onClick += OnReturnBtnClick; ToggleGroup group = transform.Find("herolist").GetComponent <ToggleGroup>(); Toggle[] toglist = group.GetComponentsInChildren <Toggle>(); for (int i = 0; i < toglist.Length; i++) { AvatarItem item = new AvatarItem(); item.Init(toglist[i], i); item.mAvatarItemClick += OnRoleToggleClick; mAvatarList.Add(item); } group = transform.Find("equipment").GetComponent <ToggleGroup>(); toglist = group.GetComponentsInChildren <Toggle>(); for (int i = 0; i < toglist.Length; i++) { EquipItem item = new EquipItem(); item.Init(toglist[i], i); item.mEquipItemClick += OnEquipToggleClick; mEquipList.Add(item); } if (mAvatarList.Count > 0) { mAvatarList[0].Selected(); } }
public void CreateUIToggles(int mode) { foreach (Transform child in uiToggleParent) { Destroy(child.gameObject); } ToggleGroup tg = uiToggleParent.GetComponent <ToggleGroup>(); GridContentFactory factory = tileContentFactory; if (mode == 0) { factory = tileContentFactory; createGridContentAct.parentMode = CreateGridContentAct.ParentMode.Tile; } else if (mode == 1) { factory = chunkContentFactory; createGridContentAct.parentMode = CreateGridContentAct.ParentMode.Chunk; } for (int i = 0; i < factory.items.Count; i++) { Transform t = Instantiate(uiTogglePrefab); //t.name = factory.items.contentType.contentName; t.SetParent(uiToggleParent); Toggle toggle = t.GetComponent <Toggle>(); if (i != 0) { toggle.isOn = false; } toggle.group = tg; int index = i; toggle.onValueChanged.AddListener((isSeleted) => { createGridContentAct.ChangeActiveContentId(index); }); } }
// Use this for initialization void Start() { m_model = Context.model; SetModel(m_model); RegisterKeyEventCallback("show_unit_list", () => { new SerialProcess() .Add((System.Action next) => { m_model.ShowUnits(next); }) .Add((System.Action next) => { m_model.ShowSkills(next); }) .Flush(); }); // ページ切り替え用トグルの設定 Context.Toggle = GetComponent <Toggle>(); ToggleGroup toggleGroup = GetComponentInParent <ToggleGroup>(); if (toggleGroup != null) { Context.Toggle.group = toggleGroup; } // コールバック設定 PartyParamQuestPartyPanel partyParam = GetComponentInParent <PartyParamQuestPartyPanel>(); if (partyParam != null) { Context.Toggle.onValueChanged.AddListener(partyParam.OnChangedPartyParam); } }
private void Awake() { _group = GetComponent <ToggleGroup>(); for (int i = 0; i < toggleList.Count; i++) { if (toggleList[i].group == null) { toggleList[i].group = _group; } else if (toggleList[i].group != _group) { toggleList[i].group = _group; } int index = i; toggleList[i].onValueChanged.AddListener((bool active) => { if (active && onChangedIndex != null) { onChangedIndex(index); } }); } }
private void InitUI() { mMapLoader = GameObject.FindWithTag("MapLoader"); mExitButton = GameObject.FindWithTag("ExitMapButton"); GameObject ListParent = GameObject.FindWithTag("ListContentParent"); mListContentParent = ListParent.GetComponent <RectTransform>(); mToggleGroup = ListParent.GetComponent <ToggleGroup>(); mPlaneDetectionToggle = GameObject.FindWithTag("PlaneDetectionToggle"); mLabelText = GameObject.FindWithTag("LabelText").GetComponent <Text>(); uploadText = GameObject.FindWithTag("UploadText").GetComponent <Text>(); mapButton = GameObject.FindWithTag("MapButton"); mRadiusSlider = GameObject.FindWithTag("RadiusSlider").GetComponent <Slider>(); nameHolder = GameObject.FindWithTag("name").GetComponent <Text>(); nameInput = GameObject.FindWithTag("nameInput").GetComponent <InputField>(); ResetSlider(); mMapLoader.SetActive(false); // needs to be active at Start, so the reference to it can be found LoadLocalData(); //UpdateName(); }
// Use this for initialization void Start() { joinMainView = transform.GetComponentInParent <JoinMainView>(); joinGuide = transform.GetComponentInParent <JoinGuide>(); tg = transform.GetComponent <ToggleGroup>(); int count = transform.childCount; for (int i = 0; i < count; i++) { int index = i; Toggle t = transform.GetChild(i).GetComponent <Toggle>(); t.group = tg; t.onValueChanged.AddListener(delegate { SelectOneColor(t.isOn, index); }); toggleLst.Add(t); } toggleLst[2].isOn = true; //初始选中红色单色蜡笔 joinMainView.SelectColor(2, GameData.instance.ColorList[2]); }
protected override void Start() { base.Start(); //Group = gameObject.GetComponent<ToggleGroup>(); if (null == Group) { Group = gameObject.AddComponent <ToggleGroup>(); Group.allowSwitchOff = false; } if (!Dynamically && null != mToggls) { for (int i = 0; i < mToggls.Count; i++) { addToggleToGroup(i, mToggls[i]); } } //#if UNITY_EDITOR // if (Application.isPlaying) // { // StartCoroutine(test()); // } //#endif }
void Awake() { audio = GetComponent <AudioSource>(); toggle = GetComponent <ToggleGroup>(); int number = PlayerPrefs.GetInt("difficulty"); mode = (Difficulty.difficulty)number; if (mode == (Difficulty.difficulty) 0) { easyButton.isOn = true; } else if (mode == (Difficulty.difficulty) 1) { easyButton.isOn = false; mediumButton.isOn = true; } else { easyButton.isOn = false; hardButton.isOn = true; } }
// Use this for initialization void Start() { dbInteractionScript = GameObject.Find("HolderOfValues").GetComponent <InteractWithDB>(); inputIdade = GameObject.Find("Idade").GetComponentInChildren <InputField>(); inputAltura = GameObject.Find("Altura").GetComponentInChildren <InputField>(); inputEtnia = GameObject.Find("Etnia").GetComponentInChildren <InputField>(); inputProfissao = GameObject.Find("Profissão").GetComponentInChildren <InputField>(); inputCorPreferida = GameObject.Find("CorPreferida").GetComponentInChildren <InputField>(); inputMusica = GameObject.Find("EstiloMúsica").GetComponentInChildren <InputField>(); inputIdolos = GameObject.Find("Idolos").GetComponentInChildren <InputField>(); inputFilmes = GameObject.Find("Filmes").GetComponentInChildren <InputField>(); groupOlhos = GameObject.Find("Olhos").GetComponent <ToggleGroup>(); groupCorCabelo = GameObject.Find("CorCabelo").GetComponent <ToggleGroup>(); groupAnimais = GameObject.Find("Animais").GetComponent <ToggleGroup>(); groupFilhos = GameObject.Find("Filhos").GetComponent <ToggleGroup>(); groupImportante = GameObject.Find("ImportanteSi"); groupTracos = GameObject.Find("Traços"); groupDefeitos = GameObject.Find("Defeitos"); groupTemposLivres = GameObject.Find("TemposLivres"); }
void update_callback() { ToggleGroup tg = GetComponentInChildren <ToggleGroup>(); Toggle[] toggles = GetComponentsInChildren <Toggle>(); int i = 0; List <string> item_names = InventoryManager.networkInv.GetAllItemNames(); foreach (Toggle toggle in toggles) { string cur_name = item_names.ElementAtOrDefault(i++); toggle.GetComponentInChildren <Text>().text = cur_name; if (im.actionSlots.shared_item != null && im.actionSlots.shared_item.name() == cur_name) { toggle.isOn = true; } else { toggle.isOn = false; } } init = true; }
protected override void OnStart() { // tab ToggleGroup m_TabToggleGroup = tabContentPanel.GetComponent <ToggleGroup>(); m_TabToggleGroup.allowSwitchOff = false; // tab ScrollRect m_TabScrollRect = tabContentPanel.GetComponentInParent <ScrollRect>(); m_TabScrollRect.onValueChanged.AddListener(TabRectChange); m_TabScrollRect.vertical = false; m_TabScrollRect.horizontal = true; // page ScrollRect m_PageScrollRect = pageContentPanel.GetComponentInParent <ScrollRect>(); m_PageScrollRect.vertical = false; // disable vertical scroll temporarily m_PageScrollRect.horizontal = false; // arrow click event & default hide arrow arrowPrevious.onClick.AddListener(TabPrevious); arrowNext.onClick.AddListener(TabNext); arrowPrevious.gameObject.SetActive(false); arrowNext.gameObject.SetActive(false); }
public void SetSlot(StatusPanel statusPanel, Unit unit, bool isFirstTurn, ToggleGroup group) { icon.sprite = unit.icon; frame.sprite = unit.team.teamTurnSlotFrame; GetComponent <Toggle>().group = group; GetComponent <Toggle>().onValueChanged.AddListener((isOn) => { if (isOn) { statusPanel.SetStatusForUnit(unit); CameraMgr.Instance.SetTarget(unit); } else { statusPanel.UnsetPanel(); } }); if (isFirstTurn) { glowFrame.SetActive(true); if (glowFrame.GetComponent <Image>().DOPause() == 0) { glowFrame.GetComponent <Image>().DOFade(0.4f, 0.4f).SetLoops(int.MaxValue, LoopType.Yoyo); } else { glowFrame.GetComponent <Image>().DOPlay(); } } else { glowFrame.SetActive(false); } icon.transform.DOPause(); icon.transform.localScale = new Vector3(0f, 0f, 0f); icon.transform.DOScale(0.8f, 0.7f); }
// ---------[ UI FUNCTIONALITY ]--------- private static GameObject CreateCategoryDisplayInstance(ModTagCategory category, List <string> selectedTags, GameObject prefab, RectTransform container) { GameObject displayGO = GameObject.Instantiate(prefab, new Vector3(), Quaternion.identity, container); displayGO.name = category.name; ModTagCategoryDisplay display = displayGO.GetComponent <ModTagCategoryDisplay>(); display.Initialize(); display.DisplayCategory(category); ToggleGroup toggleGroup = null; if (!category.isMultiTagCategory) { toggleGroup = display.gameObject.AddComponent <ToggleGroup>(); toggleGroup.allowSwitchOff = true; } ModTagContainer tagContainer = displayGO.GetComponent <ModTagContainer>(); foreach (ModTagDisplay tagDisplay in tagContainer.tagDisplays) { Toggle tagToggle = tagDisplay.GetComponent <Toggle>(); tagToggle.isOn = selectedTags.Contains(tagDisplay.data.tagName); tagToggle.group = toggleGroup; // TODO(@jackson): Need to register? } return(displayGO); }
private void Awake() { var root = transform; data = GameDataManager.GetData(); if (data == null) { data = GameData.Init(); } skinTG = root.Find("ControlPanel/Skin").GetComponent <ToggleGroup>(); scienceSkin = skinTG.transform.Find("ScienceSkin").GetComponent <Toggle>(); yellowSkin = skinTG.transform.Find("YellowSkin").GetComponent <Toggle>(); modelTG = root.Find("ControlPanel/Mode").GetComponent <ToggleGroup>(); borderMode = modelTG.transform.Find("BorderMode").GetComponent <Toggle>(); freedomMode = modelTG.transform.Find("FreedomMode").GetComponent <Toggle>(); var lastScore = root.Find("ControlPanel/Score/LastScore"); lastScore.Find("LastLengthLabel/LastLengthText").GetComponent <Text>() .text = data.LastLength.ToString(); lastScore.Find("LastScoreLabel/LastScoreText").GetComponent <Text>() .text = data.LastScore.ToString(); var bestScore = root.Find("ControlPanel/Score/BestScore"); bestScore.Find("BestLengthLabel/BestLengthText").GetComponent <Text>() .text = data.BestLength.ToString(); bestScore.Find("BestScoreLabel/BestScoreText").GetComponent <Text>() .text = data.BestScore.ToString(); root.Find("StartButton").GetComponent <Button>() .onClick.AddListener(StartGame); }
public override void Init() { base.Init(); //GameObject canvas = UITool.GetCanvas(); //得到主画布 canvas = GameObject.Find("DoubleCanvas"); mPanel = UITool.FindOneOfAllChild(canvas, "Panel"); mPlayer1 = UITool.FindOneOfAllChild(canvas, "Player1"); mPlayer2 = UITool.FindOneOfAllChild(canvas, "Player2"); mToggleGroup1 = UITool.FindChild <ToggleGroup>(mPanel, "Player1WhichTurret"); mToggleGroup2 = UITool.FindChild <ToggleGroup>(mPanel, "Player2WhichTurret"); anyToggle1 = mToggleGroup1.ActiveToggles(); anyToggle2 = mToggleGroup2.ActiveToggles(); play1 = UnityTool.FindAllChild(mPlayer1); //Debug.Log(play1); //Debug.Log(play1.Count); play2 = UnityTool.FindAllChild(mPlayer2); mButton_Exit = UITool.FindChild <Button>(canvas, "Button_Exit"); mButton_Exit.onClick.AddListener(OnExitButtonClickOn); mButton_Ready = UITool.FindChild <Button>(mPanel, "ReadyButton"); mButton_Ready.onClick.AddListener(OnReadyButtonClickOn); mImage = canvas.GetComponent <Image>(); canvas.SetActive(false); //canvas.GetComponent<Canvas>().sortingOrder = 0; }
public override void Initialize() { base.Initialize(); _toggleGroup = new ToggleGroup(); _toggleGroup.OnToggledOn.Subscribe(SubscribeOnToggledOn).AddTo(gameObject); _toggleGroup.RegisterToggleable(buyButton); _toggleGroup.RegisterToggleable(sellButton); inventory.SharedModel.SelectedItemView .Subscribe(ShowTooltip) .AddTo(gameObject); inventory.OnDoubleClickItemView .Subscribe(view => ShowActionPopup(view.Model)) .AddTo(gameObject); shopItems.SharedModel.SelectedItemView .Subscribe(ShowTooltip) .AddTo(gameObject); shopItems.SharedModel.OnDoubleClickItemView .Subscribe(view => ShowActionPopup(view.Model)) .AddTo(gameObject); SharedModel.State.Value = StateType.Show; SharedModel.State .Subscribe(SubscribeState) .AddTo(gameObject); SharedModel.ItemCountAndPricePopup.Value.Item .Subscribe(SubscribeItemPopup) .AddTo(gameObject); SharedModel.ItemCountAndPricePopup.Value.OnClickSubmit .Subscribe(SubscribeItemPopupSubmit) .AddTo(gameObject); SharedModel.ItemCountAndPricePopup.Value.OnClickCancel .Subscribe(SubscribeItemPopupCancel) .AddTo(gameObject); }
public void AddItem(string item) { if (listbox == null) { listbox = transform.FindChild("ListBox").gameObject; } if (toggleGroup == null) { toggleGroup = listbox.GetComponent <ToggleGroup>(); } GameObject obj = Instantiate(Resources.Load("UIListBoxItem") as GameObject); obj.transform.SetParent(listbox.transform, false); Toggle toggle = obj.GetComponent <Toggle>(); toggle.group = toggleGroup; toggle.GetComponentInChildren <Text>().text = item; toggle.onValueChanged.AddListener((isOn) => { Text text = toggle.GetComponentInChildren <Text>(); if (onSelected != null) { onSelected.Invoke(text.text); } buttonText.text = text.text; listbox.gameObject.SetActive(false); }); }
/// <summary> /// Refresh the UI list of Area Descriptions. /// </summary> public void RefreshAreaDescriptionList() { AreaDescription[] areaDescriptions = AreaDescription.GetList(); _SelectAreaDescription(null); // Always remove all old children. foreach (Transform child in m_listParent) { Destroy(child.gameObject); } if (areaDescriptions != null) { // Add new children ToggleGroup toggleGroup = GetComponent <ToggleGroup>(); foreach (AreaDescription areaDescription in areaDescriptions) { AreaDescriptionListElement button = GameObject.Instantiate(m_listElement) as AreaDescriptionListElement; button.m_areaDescriptionName.text = areaDescription.GetMetadata().m_name; button.m_areaDescriptionUUID.text = areaDescription.m_uuid; button.m_toggle.group = toggleGroup; // Ensure the lambda gets a copy of the reference to areaDescription in its current state. // (See https://resnikb.wordpress.com/2009/06/17/c-lambda-and-foreach-variable/) AreaDescription lambdaParam = areaDescription; button.m_toggle.onValueChanged.AddListener((value) => _OnAreaDescriptionToggleChanged(lambdaParam, value)); button.transform.SetParent(m_listParent, false); } m_listEmptyText.gameObject.SetActive(false); } else { m_listEmptyText.gameObject.SetActive(true); } }
public void Register(ToggleGroup toggleGroup) { this.toggle.group = toggleGroup; }
/// <summary> /// Parses the children of the specified element into a list of template blocks. /// </summary> /// <param name="source">The original string source of the template.</param> /// <param name="element">The element to parse</param> /// <param name="withinTemplate">Indicates that the children of the given element are within a template control.</param> /// <param name="lastNestedTemplateIndex">Tracks the index of the last template element that was encountered. Passed through to recursive calls excluding templates.</param> /// <param name="nestedTemplates">Out parameter that returns the number of template controls represented by the children of the given element.</param> /// <returns>A list of template blocks.</returns> static List<Block> ParseChildren(string source, XmlElement element, bool withinTemplate, int lastNestedTemplateIndex, out int nestedTemplates) { // Track the blocks represented by the current element var blocks = new List<Block>(); nestedTemplates = 0; // Process the child nodes of the current element foreach (XmlNode node in element.ChildNodes) { switch (node.NodeType) { // XML Element, which could be a control, bound element start tag, or just literal content case XmlNodeType.Element: var child = (XmlElement)node; // Control if (child.HasAttribute("sys:attach") || child.HasAttribute("sys:if") || child.HasAttribute("sys:content-template") || child.HasAttribute("sys:id") || child.HasAttribute("id")) { bool parseChildren = true; Control control; if (child.HasAttribute("sys:attach")) { switch (child.GetAttribute("sys:attach")) { // Template case "template": control = new Template() { Attributes = GetAttributes(child, "class", "sys:attach", "sys:if", "sys:content-template", "template:name", "template:kind", "template:datatype", "template:islist", "template:isreference"), Name = GetLiteralTokens(child, "template:name"), Source = source + " [" + child.GetAttribute("template:name") + "]" + (child.HasAttribute("template:datatype") ? " - " + child.GetAttribute("template:datatype") : ""), IsList = GetBoolean(child, "template:islist"), IsReference = GetBoolean(child, "template:isreference"), Kind = GetStringLiteral(child, "template:kind"), DataType = GetStringLiteral(child, "template:datatype"), Class = GetLiteralTokens(child, "class").Where(c => c.ToLower() != "sys-template").ToArray(), ContentTemplateNames = GetLiteralTokens(child, "sys:content-template") }; break; // DataView case "dataview": control = new DataView() { Attributes = GetAttributes(child, "sys:attach", "sys:if", "sys:content-template", "dataview:data"), Data = GetBinding(child, "dataview:data"), Template = GetTemplate(child), ContentTemplate = GetBinding(child, "sys:content-template") }; break; // Content case "content": control = new Content() { Attributes = GetAttributes(child, "sys:attach", "sys:if", "sys:content-template", "content:data", "content:template"), Data = GetBinding(child, "content:data"), Template = GetBinding(child, "content:template"), DataType = GetBinding(child, "content:datatype"), ContentTemplate = GetBinding(child, "sys:content-template") }; break; // Toggle case "toggle": control = new Toggle() { Attributes = GetAttributes(child, "sys:attach", "sys:if", "sys:content-template", "toggle:on", "toggle:action", "toggle:class", "toggle:groupname", "toggle:strictmode", "toggle:when"), On = GetBinding(child, "toggle:on"), Class = GetBinding(child, "toggle:class"), ClassName = GetBinding(child, "toggle:classname"), Action = GetBinding(child, "toggle:action"), GroupName = GetBinding(child, "toggle:groupname"), StrictMode = GetBinding(child, "toggle:strictmode"), When = GetBinding(child, "toggle:when"), ContentTemplate = GetBinding(child, "sys:content-template") }; break; // ToggleGroup case "togglegroup": control = new ToggleGroup() { Attributes = GetAttributes(child, "sys:attach", "sys:if", "sys:content-template"), ContentTemplate = GetBinding(child, "sys:content-template") }; break; // Behavior case "behavior": control = new Behavior() { Attributes = GetAttributes(child, "sys:attach", "sys:if", "sys:content-template"), ContentTemplate = GetBinding(child, "sys:content-template") }; break; // Html case "html": control = new Html() { Attributes = GetAttributes(child, "sys:attach", "sys:if", "sys:content-template"), ContentTemplate = GetBinding(child, "sys:content-template") }; break; default: throw new ArgumentException("Controls of type '" + child.GetAttribute("sys:attach") + "' are not supported for server rendering."); } // Add data-sys-attach to indicate the control type when performing linking on the client control.Attributes.Add(new Attribute() { Name = "data-sys-attach", Value = child.GetAttribute("sys:attach") }); } else { control = new Control() { Attributes = GetAttributes(child, "sys:if", "sys:content-template", "sys:innerhtml", "sys:innertext"), ContentTemplate = GetBinding(child, "sys:content-template"), IsEmpty = child.ChildNodes.Count == 0 }; if (child.InnerXml.Trim().StartsWith("{") && child.InnerXml.Trim().EndsWith("}")) { parseChildren = false; control.Attributes.Add(new Attribute() { Name = "innerhtml", Binding = Binding.Parse(GetDefaultProperty(child), child.InnerXml.Trim()), Value = child.InnerXml.Trim() }); control.IsEmpty = true; } } var isTemplate = IsTemplate(control); // If the sys:content-template attribute is found, then ensure it is within or on a templated control if (child.HasAttribute("sys:content-template") && !withinTemplate && !isTemplate) throw new ApplicationException("The sys:content-template attribute must be used on or within an control that implements Sys.UI.IContentTemplateConsumer."); // Process the controls child blocks if (parseChildren) { // Determine the number of top-level templates represented by this node int numTopLevelTemplates; if (isTemplate) { // A templated control represents only 1 top-level nested template numTopLevelTemplates = 1; // Set nested template index control.NestedTemplateIndex = lastNestedTemplateIndex + 1; // Parse child blocks as a new template region. This means that lastNestedTemplateIndex // starts fresh (-1) and the number of child templates are not relevant here. control.Blocks = ParseChildren(source, child, true); } else // Parse children and capture the number of top-level templates contained within control.Blocks = ParseChildren(source, child, withinTemplate, lastNestedTemplateIndex, out numTopLevelTemplates); // Increment the number of nested templates and last index by // the number of top-level templates that this node represents nestedTemplates += numTopLevelTemplates; lastNestedTemplateIndex += numTopLevelTemplates; } else // A non-control with a binding expression as its inner-html contains no blocks control.Blocks = new List<Block>(); control.Tag = child.Name; control.Markup = GetMarkup(child); control.If = GetBinding(child, "sys:if"); // Add the control blocks.Add(control); } // Element else if (child.Attributes.Cast<XmlAttribute>().Any(a => a.Value.StartsWith("{") && a.Value.EndsWith("}")) || (child.ChildNodes.Cast<XmlNode>().All(n => n.NodeType != XmlNodeType.Element) && child.InnerXml.Trim().StartsWith("{") && child.InnerXml.Trim().EndsWith("}"))) { var isBinding = child.InnerXml.Trim().StartsWith("{") && child.InnerXml.Trim().EndsWith("}"); // Add the bound element var e = new Element() { Markup = isBinding || child.ChildNodes.Count == 0 ? GetMarkup(child) : GetElementMarkup(child), Attributes = GetAttributes(child), Tag = child.Name, IsEmpty = isBinding || child.ChildNodes.Count == 0 }; if (isBinding) e.Attributes.Add(new Attribute() { Name = "innerhtml", Binding = Binding.Parse(GetDefaultProperty(child), child.InnerXml.Trim()) }); blocks.Add(e); // Process child nodes, if the element content is not bound if (!e.IsEmpty) { int numTopLevelTemplates; var children = ParseChildren(source, child, withinTemplate, lastNestedTemplateIndex, out numTopLevelTemplates); lastNestedTemplateIndex += numTopLevelTemplates; nestedTemplates += numTopLevelTemplates; blocks.AddRange(children); blocks.Add(new Block() { Markup = "</" + child.Name + ">" }); } } // Literal else { // Get the blocks contained by the literal element int numTopLevelTemplates; var children = ParseChildren(source, child, withinTemplate, lastNestedTemplateIndex, out numTopLevelTemplates); lastNestedTemplateIndex += numTopLevelTemplates; nestedTemplates += numTopLevelTemplates; // Add the entire element as a block if it only contains literal content if (children.Count == 0 || (children.Count == 1 && children.First().GetType() == typeof(Block))) blocks.Add(new Block() { Markup = GetMarkup(child) }); // Otherwise, process the child blocks else { blocks.Add(new Block() { Markup = GetElementMarkup(child) }); blocks.AddRange(children); blocks.Add(new Block() { Markup = "</" + child.Name + ">" }); } } break; // Literal content case XmlNodeType.Text: blocks.Add(new Block() { Markup = GetMarkup(node) }); break; } } // Condense adjacent literal blocks Block literal = null; for (int i = blocks.Count - 1; i >= 0; i--) { if (blocks[i].GetType() == typeof(Block)) { if (literal == null) literal = blocks[i]; else { literal.Markup = blocks[i].Markup + literal.Markup; blocks.RemoveAt(i); } } else literal = null; } return blocks; }