void Start() { image = GetComponent <Image>(); if (uiType.ToString() == "YUYU") { actualFill = GameObject.FindGameObjectWithTag("Player").GetComponent <YuyuController>()._actualYuyu; } if (uiType.ToString() == "FLUSFLUS") { actualFill = GameObject.FindGameObjectWithTag("Player").GetComponent <ShootingController>().flusAmmo; } float portion = Mathf.InverseLerp(0, totalFill, actualFill); image.fillAmount = portion; }
/*** * @params: * iconsumperpage * iconname * materialdic * iconrespath* * iconprefabpath* * **/ public void initComponents(params object[] paras) { //暂时用同一个size _iconSumPerPage = BackpackItemManager.Instance.GetSize(tabIndexToItemType[0]); string iconName = Convert.ToString(paras[0]); _uiType = (UITypes)paras[1]; _iconResPath = paras[2] == null ? _iconResPath : Convert.ToString(paras[2]); _materials = new int[_iconSumPerPage]; _iconbases = new UIIcon[_iconSumPerPage]; _buttons = new GameObject[_iconSumPerPage]; _bagBtnGrid = this.transform.Find("Grid"); for (int i = 0; i < _iconSumPerPage; i++) { addItemIcon(i); } if (paras[3] != null) { _selectSprite = GameObject.Find(Convert.ToString(paras[3])); _selectSprite.SetActive(false); } GridLayoutGroup glg = _bagBtnGrid.GetComponent <GridLayoutGroup>(); float height = (glg.cellSize.y + glg.spacing.y) * (_iconSumPerPage / 6); RectTransform rtf = _bagBtnGrid.GetComponent <RectTransform>(); rtf.sizeDelta = new Vector2(rtf.sizeDelta.x, height); EventManager.RegisterEvent(UIEventMacro.CLICK_TAB, onClickTab); UIEventManager.RegisterEvent(UIEventManager.ET_UI_CLICK, _uiType.ToString(), onSelect); showIcon(0); }
public void SetIconFor(UITypes type, Item item, Slot slot) { ItemData createdGo = CreateSlotPlaceholder(item, slot); switch (type) { case UITypes.hotbarUI_hotslots: hotbarUI.hotSlots[hotbarUI.hotSlots.IndexOf(slot)].itemData = createdGo; break; case UITypes.inventoryUI_hotSlots: inventoryUI.hotSlots[inventoryUI.hotSlots.IndexOf(slot)].itemData = createdGo; break; case UITypes.inventoryUI_invSlots: inventoryUI.invSlots[inventoryUI.invSlots.IndexOf(slot)].itemData = createdGo; break; case UITypes.mechanismUI_hotSlots: mechanismUI.hotSlots[mechanismUI.hotSlots.IndexOf(slot)].itemData = createdGo; break; case UITypes.mechanismUI_invSlots: mechanismUI.invSlots[mechanismUI.invSlots.IndexOf(slot)].itemData = createdGo; break; default: Debug.Log("None set for " + type.ToString()); break; } }
public void SetSlotFor(UISlotType slotType, UITypes type, int slotNumber) { switch (slotType) { case UISlotType.hotbar: switch (type) { case UITypes.hotbarUI_hotslots: hotbarUI.hotSlots.Add(CreateSlot(hotbarUI, slotType, hotbarUI.hotbarGo.transform, slotNumber)); break; case UITypes.inventoryUI_hotSlots: inventoryUI.hotSlots.Add(CreateSlot(inventoryUI, slotType, inventoryUI.hotbarGo.transform, slotNumber)); break; case UITypes.mechanismUI_hotSlots: mechanismUI.hotSlots.Add(CreateSlot(mechanismUI, slotType, mechanismUI.hotbarGo.transform, slotNumber)); break; default: Debug.Log("None set for " + type.ToString()); break; } break; case UISlotType.inventory: switch (type) { case UITypes.inventoryUI_invSlots: inventoryUI.invSlots.Add(CreateSlot(inventoryUI, slotType, inventoryUI.inventoryGo.transform, slotNumber)); break; case UITypes.mechanismUI_invSlots: mechanismUI.invSlots.Add(CreateSlot(mechanismUI, slotType, mechanismUI.inventoryGo.transform, slotNumber)); break; default: Debug.Log("None set for " + type.ToString()); break; } break; } }
public override void InitElements() { _imageTrans = mTrans.FindChild("Image"); _imageTrans.GetComponent <UGUIImage>().SetPath(_resPath); AddElement("Image", _imageTrans.GetComponent <UGUIImage>()); _button = gameObject.GetComponent <Button>(); _button.onClick.AddListener(delegate() { UIEventManager.SendEvent(UIEventManager.ET_UI_CLICK, _uiType.ToString(), "Image", "", IconResManager.getIconNameByMId(_materialId), _materialId, id); }); }
public void initComponents(params object[] paras) { _uiType = (UITypes)paras[0]; _iconContainer = GameObject.Find("BagSelectContainer"); UIEventManager.RegisterEvent(UIEventManager.ET_UI_CLICK, _uiType.ToString(), onSelect); _prefab = _prefab == null?Resources.Load(_iconPrefabPath) as GameObject : _prefab; GameObject icon = GameObject.Instantiate(_prefab) as GameObject; RectTransform rectTrans = icon.GetComponent <RectTransform>(); Vector3 localPosition = rectTrans.anchoredPosition3D; rectTrans.SetParent(_iconContainer.transform); rectTrans.anchoredPosition3D = localPosition; rectTrans.localScale = Vector3.one; icon.AddComponent <UIIcon>(); _iconBase = icon.GetComponent <UIIcon>(); _iconBase.Init("0", _uiType, _iconResPath); _iconBase.setEnable(false); }
public void dispose() { UIEventManager.UnRegisterEvent(UIEventManager.ET_UI_CLICK, _uiType.ToString(), onSelect); }