public void SaveInventory() { StringBuilder sb = new StringBuilder(); foreach (Slot slot in slotList) { if (slot.transform.childCount > 0) { ItemUI itemUI = slot.transform.GetChild(0).GetComponent <ItemUI>(); sb.Append(itemUI.Item.ID + "," + itemUI.Amount + "-"); } else { sb.Append("0-"); } } PlayerPrefs.SetString(this.gameObject.name, sb.ToString()); }
public void RemoveItem(int index) { if (items[index].ID != -1) { ItemUI myItem = slots[SelectedSlot].transform.GetComponentInChildren <ItemUI>(); if (myItem.amount == 0) { items[SelectedSlot].ExitSelected(); items[index] = new Item(); Destroy(slots[index].transform.GetChild(0).gameObject); } else { myItem.amount--; myItem.UpdateAmountText(); } } }
/// <summary> /// 查找是否存在相同的物品 /// </summary> /// <param name="item"></param> /// <returns></returns> private Slot FindSameTypeSlot(Item item) { foreach (var slot in slotArr) { if (slot.transform.childCount == 0) { continue; } ItemUI itemUI = slot.GetItme(); //检测是否相同物品 并检测当前物品的容量是否已到达最大 if (slot.transform.childCount >= 1 && itemUI.item.Id == item.Id && itemUI.amount != itemUI.item.Capacity) { return(slot); } } return(null); }
private void Start() { inputMaster = GameManager.instance.inputMaster; if (!isPickup) { inventory.onAmmoChange += UpdateAmmoUI; for (int i = 0; i < Inventory.ammoTypesCount; i++) { ItemUI ammoItem = ItemUI.CreateItemUIElement( System.Enum.GetNames(typeof(AmmoType))[i], inventory.ammoSprites[i], inventory.currentAmmo[i], AmmoGroupPanel.transform ); ammoUI.Add(ammoItem); } } }
public override void OnPointerDown(PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Right) { if (PickedItem.Instance.IsPickedItem == false && transform.childCount > 0) { ItemUI currentItemUI = transform.GetChild(0).GetComponent <ItemUI>(); Item currentItem = currentItemUI.Item; currentItemUI.ReduceAmount(1); EquipmentPanel.Instance.StoreItem(currentItem.ID); ToolTip.Instance.Hide(); StartCoroutine(UpdateAttr()); } } else if (eventData.button == PointerEventData.InputButton.Left) { if (transform.childCount > 0) { ItemUI currentItemUI = transform.GetChild(0).GetComponent <ItemUI>(); Item item = currentItemUI.Item; if (PickedItem.Instance.IsPickedItem == true && IsRightItem(PickedItem.Instance.item)) { currentItemUI.SetItem(PickedItem.Instance.item); PickedItem.Instance.SetPickItem(item.ID); StartCoroutine(UpdateAttr()); } else if (PickedItem.Instance.IsPickedItem == false) { PickedItem.Instance.SetPickItem(item.ID); Destroy(currentItemUI.gameObject); } } else { if (PickedItem.Instance.IsPickedItem == true && IsRightItem(PickedItem.Instance.item)) { StoreItem(PickedItem.Instance.item); PickedItem.Instance.Hide(); StartCoroutine(UpdateAttr()); } } } }
// Start is called before the first frame update void Awake() { Knapscak knapscak = Knapscak.Instance; content = GameObject.FindGameObjectWithTag("BattleCanvas").transform.Find("PropWindow/Viewport/Content").gameObject; foreach (Slot slot in knapscak.slotArray) { if (slot.transform.childCount != 0 && slot.GetItemType().Equals(ItemDetail.ItemType.Consumable)) { ItemUI itemUI = slot.transform.GetChild(0).GetComponent <ItemUI>(); Object prop_item_P = Resources.Load("Prefabs/prop_item", typeof(GameObject)); GameObject prop_item = Instantiate(prop_item_P) as GameObject; prop_item.transform.SetParent(content.transform); prop_item.GetComponent <PropItemUI>().SetItemUI(itemUI); } } }
private void RemoveItem(int itemId) { foreach (KnapsackSlot slot in ArrKnapsackSlot) { if (slot.transform.childCount != 0) { ItemUI itemUI = slot.transform.GetChild(0).GetComponent <ItemUI>(); if (itemUI.Item.Id == itemId) { itemUI.ReduceAmount(); if (itemUI.Amount == 0) { DestroyImmediate(itemUI.gameObject); } return; } } } }
public virtual void OnPointerDown(PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Right) { if (transform.childCount > 0 && InventoryManager.Instance.IsPickedItem == false) { OnButtonRight(); } } if (eventData.button == PointerEventData.InputButton.Left) { if (transform.childCount > 0) //物品槽不为空 { ItemUI currentItem = transform.GetChild(0).GetComponent <ItemUI>(); if (InventoryManager.Instance.IsPickedItem == false) { OnButtonLeftAndUnPickedItem(); } else { if (currentItem.Item == InventoryManager.Instance.PickedItem.Item) { OnButtonLeftAndPickedItemIsSame(); } else //互换 { OnButtonLeftAndPickedItemIsNotSame(); } } } else //物品槽为空 { if (InventoryManager.Instance.IsPickedItem == true) { OnButtonLeftAndPickedItemNull(); } else { return; } } } }
/// <summary> /// 技能书合成界面 /// </summary> public void ShowComposeUi() { if (GameCenter.mercenaryMng.isComposedBook) { choosedBookInMat.Clear(); GameCenter.mercenaryMng.isComposedBook = false;//技能合成清空 composeBookId = 0; ItemUI item = composeBookBtn.GetComponent <ItemUI>(); if (item != null) { item.SetEmpty(); } } if (GameCenter.mercenaryMng.seleteEquip != null) { composeBookId = GameCenter.mercenaryMng.seleteEquip.EID; NewPetSkillComposeRef composeRef = ConfigMng.Instance.GetPetSkillComposeRef(composeBookId); if (composeRef != null && composeBookId != 0) { composeMatLab.gameObject.SetActive(true); needBookNum = composeRef.needNum; needLev = composeRef.needLevel; if (composeRef.needLevel == 3) { composeMatLab.text = ConfigMng.Instance.GetUItext(35, new string[1] { "[6ef574]" + needBookNum }); } if (composeRef.needLevel == 4) { composeMatLab.text = ConfigMng.Instance.GetUItext(36, new string[1] { "[6ef574]" + needBookNum }); } } } else { composeMatLab.text = " "; } ShowBookInMat(); ShowBookInBag(); }
public void BeginDrag(ItemUI slot) { DraggedSlot = slot; isDraggingItem = true; CurrentDragged = ResourcesLoader.Instance.GetRecycledObject("DraggedItem"); CurrentDragged.GetComponent <Image>().sprite = ResourcesLoader.Instance.GetSprite(slot.CurrentItem.IconKey); CurrentDragged.transform.SetParent(transform, false); CurrentDragged.transform.SetAsLastSibling(); Game.Instance.CurrentScene.StartSellMode(slot.CurrentItem); if (DragRoutineInstance != null) { StopCoroutine(DragRoutineInstance); } DragRoutineInstance = StartCoroutine(DragSlotRoutine(slot)); }
//捡起UI public void OnPointerDown(PointerEventData eventData) { if (UIKnapscakPanel.isPick) { //正在拖拽 ItemUI PickUI = UIKnapscakPanel.pickUI; PickUI.Exchange(itemUI); UIKnapscakPanel.isPick = false; UIKnapscakPanel.pickUI = null; } else { if (null != itemUI.Item) { UIKnapscakPanel.isPick = true; UIKnapscakPanel.pickUI = itemUI; } } }
void OnClickCloseBtn(GameObject go)//关闭清空 { composeMatLab.text = " "; for (int i = 0; i < choosedBookInMat.Count; i++) { if (!bookInBag.ContainsKey(choosedBookInMat[i])) { choosedPetSkill.Add(choosedBookInMat[i]); } } ItemUI item = composeBookBtn.GetComponent <ItemUI>(); if (item != null) { item.SetEmpty(); } choosedBookInMat.Clear(); this.gameObject.SetActive(false); }
public void UpdateUI() { if (!itemsParent) { Debug.LogError(name + " has no transform as items parent!"); return; } for (int i = 0; i < itemsParent.childCount; i++) { Destroy(itemsParent.GetChild(i).gameObject); } for (int i = 0; i < inventory.Items.Length; i++) { ItemUI iUI = Instantiate(itemUI, itemsParent); iUI.SetItem(inventory.Items[i]); } }
public override void Deselect(bool activeSelection) { base.Deselect(activeSelection); if (!activeSelection) { return; } // explicit deselection - no more item, remove ui ItemUI ui = FindObjectOfType <ItemUI>(true); ui.SetItemImage(null); ui.TurnOff(); // remove item from plyer ivnentory PlayerController controller = FindObjectOfType <PlayerController>(true); controller.SetItem(null); }
public void MousePutDownOnBlacksmith(Blacksmith blacksmith) { if (airItem == null) { myUI.ClearActiveNpcWindow(); return; } if (!(airItem.item is EquippableItem)) { airItem = null; myUI.ClearActiveNpcWindow(); return; } if (airItem.UpgradeLevel == 9) { airItem = null; myUI.ClearActiveNpcWindow(); return; } if (airItem.eqPieceSlot != null) { airItem = null; myUI.ClearActiveNpcWindow(); return; } if (airItem.onActionBar) { airItem = null; myUI.ClearActiveNpcWindow(); return; } GameObject prefab = GetApropriatePrefab(airItem.item); GameObject newGo = Instantiate(prefab, blacksmith.itemScreenLocation.position, Quaternion.identity, blacksmith.itemScreenLocation); newGo.GetComponent <Button>().enabled = false; newGo.GetComponent <ItemUI>().item = airItem.item; newGo.GetComponent <ItemUI>().UpgradeLevel = airItem.UpgradeLevel; newGo.GetComponent <ItemUI>().itemX = -1; newGo.GetComponent <ItemUI>().itemY = -1; newGo.GetComponent <Image>().sprite = airItem.item.inventoryIcon; blacksmith.SetupUpgradeWindow(newGo.GetComponent <ItemUI>(), airItem, myUI.playerUI.gameObject.GetComponent <PlayerRpg>()); airItem = null; }
void FillAItem(int _copyKey) { if (petSkillByCopyAll.ContainsKey(_copyKey)) { int skillId = petSkillByCopyAll[_copyKey]; if (bookItem == null) { bookItem = BookItem.CeateBook(0, parent, false); bookItem.gameObject.SetActive(true); bookItem.transform.localPosition = new Vector3(200, -50); ItemUI bookItemUI = bookItem.GetComponent <ItemUI>(); bookItemUI.FillInfo(new EquipmentInfo(skillId, EquipmentBelongTo.PREVIEW)); bookItem.transform.parent = parent.transform; bookItem.chooseBtn.gameObject.SetActive(true); bookItem.chooseYetBtn.gameObject.SetActive(false); if (bookItem.chooseBtn != null) { UIEventListener.Get(bookItem.chooseBtn.gameObject).onClick -= OnClickChooseOneToBag; UIEventListener.Get(bookItem.chooseBtn.gameObject).onClick += OnClickChooseOneToBag; UIEventListener.Get(bookItem.chooseBtn.gameObject).parameter = _copyKey; } } else { ItemUI bookItemUi = bookItem.GetComponent <ItemUI>(); bookItemUi.FillInfo(new EquipmentInfo(skillId, EquipmentBelongTo.PREVIEW)); bookItem.transform.parent = parent.transform; bookItem.chooseBtn.gameObject.SetActive(true); bookItem.chooseYetBtn.gameObject.SetActive(false); if (_copyKey == GameCenter.mercenaryMng.choosedSkillId) { bookItem.chooseBtn.gameObject.SetActive(false); bookItem.chooseYetBtn.gameObject.SetActive(true); } if (bookItem.chooseBtn != null) { UIEventListener.Get(bookItem.chooseBtn.gameObject).onClick -= OnClickChooseOneToBag; UIEventListener.Get(bookItem.chooseBtn.gameObject).onClick += OnClickChooseOneToBag; UIEventListener.Get(bookItem.chooseBtn.gameObject).parameter = _copyKey; } } } }
/// <summary> /// 创建一个新的itemUI by吴江 /// </summary> /// <param name="_parent"></param> /// <param name="_index"></param> /// <param name="_tooltipTrigger"></param> /// <returns></returns> public static ItemUI CreatNew(UIExGrid _parent, int _index, GameObject _tooltipTrigger = null) { if (_parent == null) { GameSys.LogError("父grid组件为空!如果没有父控件,请使用合适的重载方法!"); return(null); } if (_index < 0) { GameSys.LogError("位置序数不能为负数!"); return(null); } Object prefab = null; if (prefab == null) { prefab = exResources.GetResource(ResourceType.GUI, "Item_icon/Item_icon"); } if (prefab == null) { GameSys.LogError("找不到预制:Item_icon/Item_icon"); return(null); } GameObject obj = Instantiate(prefab) as GameObject; Transform parentTransf = _parent.gameObject.transform; obj.transform.parent = parentTransf; obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one; prefab = null; ItemUI itemUI = obj.GetComponent <ItemUI>(); if (itemUI == null) { GameSys.LogError("预制上找不到组件:<ItemUI>"); return(null); } itemUI.pos = _index; _parent.AddSolt(obj.transform, _index); //itemUI.tooltipTrigger = _tooltipTrigger; return(itemUI); }
public WeaponType wpType; //武器类型 public override void OnPointerDown(PointerEventData eventData) { //装备栏必须是鼠标左键才能操作 if (eventData.button == PointerEventData.InputButton.Left) { return; } //判断当前跟是否有物品槽跟随鼠标移动 if (InventoryManager.Instance.isClickItem) { //获取当前移动的物品 ItemUI pickedItem = InventoryManager.Instance.clickItemUI; if (transform.childCount > 0) { //获取当前点击的物品槽子物体 ItemUI currentItem = transform.GetChild(0).GetComponent <ItemUI>(); //判断是否可以放置 可以放置交换物品 if (IsRightItem(pickedItem.item)) { base.SetItemParent(pickedItem, currentItem); } } else { //判断是否可以放置 if (IsRightItem(pickedItem.item)) { base.SetCurrentItem(pickedItem); } } } else { //获取当前点击的物品槽子物体 if (transform.childCount > 0) { ItemUI currentItem = transform.GetChild(0).GetComponent <ItemUI>(); base.SetMoveItemParent(currentItem); } } }
//"-"区分不同的物品 “0”代表卡槽为空 public void SaveInventory() { StringBuilder info = new StringBuilder(); foreach (Slot slot in m_slotArr) { if (slot.transform.childCount > 0) { ItemUI itemUI = slot.transform.GetChild(0).GetComponent <ItemUI>(); info.Append(itemUI.m_item.m_ID + "," + itemUI.m_amount + "-"); } else { info.Append("0-"); } } Debug.Log("info = " + info.ToString()); PlayerPrefs.SetString(this.gameObject.name, info.ToString()); }
public void SetUIForItem(ItemUI itemUI) { ParentCanvas.SetActive(itemUI && itemUI.Item); if (ParentCanvas.activeSelf) { transform.position = itemUI.transform.position; itemUI.Item.HandleDescriptionUI(this); for (int i = 3; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(true); } } else { for (int i = 3; i < transform.childCount; i++) { Destroy(transform.GetChild(i).gameObject); } } }
public IActionResult Display(int id) { List <SelectListItem> categorySelector = new List <SelectListItem>(); foreach (CategoryUI cat in repo.GetAllCategories().OrderBy(c => c.Name)) { categorySelector.Add(new SelectListItem() { Value = cat.Id.ToString(), Text = cat.Name }); } ItemUI item = repo.GetItem(id); CategoryUI category = repo.GetCategory(item.CategoryId); ItemVM vm = new ItemVM() { Item = item, Category = category, CategorySelector = categorySelector }; return(View(vm)); }
public void OnDrop(PointerEventData eventData) { if (eventData.pointerDrag != null) { ItemUI itemUI = eventData.pointerDrag.GetComponent <ItemUI>(); if (itemUI != null) { itemUI.ChangeParent(transform); if (InventoryIndex > -1) { OnObjectDropped?.Invoke(InventoryIndex, itemUI.ItemReference); } else { OnObjectEquipped?.Invoke(EquipedIndex, itemUI.ItemReference); } } } }
public void ShowItems(Transform _parent, Item[] items) { foreach (Transform t in _parent) { Destroy(t.gameObject); } for (int i = 0; i < items.Length; i++) { GameObject go = GameObject.Instantiate(model_item); go.transform.SetParent(_parent); go.transform.position = new Vector3(0, 0, 0); go.transform.localScale = new Vector3(1, 1, 1); ItemUI ui = go.GetComponent <ItemUI>(); ui.nombre = items[i].nombre; ui.index = i; ui.cant = items[i].cant; ui.Refresh(); } }
private void Update() { //物品跟随鼠标移动 if (isClickItem && moveParentTransform.childCount > 0) { moveParentTransform.transform.localPosition = Utility.GetWorldToScreenPos() + new Vector2(15, -15); toolTip.Hide(); } //提示信息面板跟随鼠标移动 else if (isToolTipShow) { toolTip.transform.localPosition = Utility.GetWorldToScreenPos() + toolTipPosionOffset; } //判断当前鼠标左键下是否存在ui(丢弃物品) if (isClickItem && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject(-1)) { isClickItem = false; clickItemUI = null; Destroy(moveParentTransform.GetChild(0).gameObject); } }
private void Select(ItemUI toHighlight) { if (selectedItem == toHighlight) { print("hey"); foreach (var interaction in selectedItem.DisplayedItem.item.itemClickInteractions) { interaction.Act(null); } } selectedItem = toHighlight; if (selectedItem.DisplayedItem == null) { selectedItem = null; return; } myHighlighter.gameObject.SetActive(true); myHighlighter.position = selectedItem.transform.position; myHighlighter.SetParent(toHighlight.transform); }
private void Awake() { itemsToDisplay = new List <ItemUI>(); int k = 0; for (int i = 0; i < itemSlotsContainers.Length; i++) { for (int j = 0; j < itemSlotsContainers[i].childCount; j++) { ItemUI itemSlot = itemSlotsContainers[i].GetChild(j).GetComponent <ItemUI>(); if (itemSlot != null) { itemsToDisplay.Add(itemSlot); itemSlot.DisplayNull(); itemSlot.SlotID = k++; } } } k = 0; }
private void Start() { itemCount = Random.Range(3, 6); for (int i = 0; i < itensRef.Length; i++) { StoreItens itemToRandom = itensRef[i]; int randomizeIndex = Random.Range(0, itensRef.Length); itensRef[i] = itensRef[randomizeIndex]; itensRef[randomizeIndex] = itemToRandom; } for (int i = 0; i < itemCount; i++) { GameObject storeItemRef = Instantiate(itemPrefab, itensPlace); itensInStore.Add(storeItemRef); ItemUI itemRef = storeItemRef.GetComponent <ItemUI>(); itemRef.itensSO = itensRef[i]; } EventSystem.current.SetSelectedGameObject(itensInStore[0]); }
private void PopulateGrid() { ShopItems = new List <ItemUI>(); int i = 0; for (; i < Items.Count; ++i) { GameObject NewItem = Instantiate(ItemPrefab, Grid); ItemUI ui = NewItem.GetComponent <ItemUI>(); ui.SetupUI(Items[i].ItemName, Items[i].ItemCost, Items[i].ItemImage); ShopItems.Add(ui); } while (i % 4 > 0) { GameObject NewItem = Instantiate(ItemPrefab, Grid); ItemUI ui = NewItem.GetComponent <ItemUI>(); ui.SetupUI(); ++i; } ScrollPercent = 0.25f / (((i / 4) - 2) == 0 ? 1f :2 * ((i / 4) - 2)); }
// ------------------------------------------------------------------------ public void Open() { gameObject.SetActive(true); m_open = true; if (m_open) { Clear(); } foreach (Item item in Inventory.Items) { GameObject itemObj = Instantiate(ItemPrefab, InventoryParent) as GameObject; ItemUI itemUI = itemObj.GetComponent <ItemUI>(); if (itemUI != null) { itemUI.SetItem(item, ItemDialogueUI); } } }
/// <summary> /// 一键放入 /// </summary> void OnClickPutInBagBtn(GameObject go) { ItemUI choodeitem = composeBookBtn.GetComponent <ItemUI>(); if (choodeitem != null && choodeitem.EQInfo != null && choosedBookInMat.Count < needBookNum) //选择了要合成的技能书了才可点击 { foreach (int bookId in bookInBag.Keys) { EquipmentRef info = ConfigMng.Instance.GetEquipmentRef(bookId); NewPetSkillRef petskill = ConfigMng.Instance.GetPetSkillRefByBook(bookId); //合成材料 NewPetSkillRef composeskill = ConfigMng.Instance.GetPetSkillRefByBook(composeBookId); //要合成的书 int num = 0; for (int j = 0; j < choosedBookInMat.Count; j++) { if (bookId == choosedBookInMat[j]) { ++num; } } int val = GameCenter.inventoryMng.GetNumberByType(bookId) - num; if (info != null && petskill != null) { if (petskill.kind != composeskill.kind && info.psetSkillLevel >= needLev) //不同类别、且材料等级要高 { while (val > 0 && choosedBookInMat.Count < needBookNum) //判断满足条件的书数量,满足添加到材料链表 { choosedBookInMat.Add(bookId); --val; } if (val <= 0) //如果书都添加到材料链表就从背包移出该书 { choosedPetSkill.Remove(bookId); } } } } ShowBookInMat(); ShowBookInBag(); } }
void Awake() { if(instance) DestroyImmediate(gameObject); else { instance = this; DontDestroyOnLoad(gameObject); } showItemList = false; }
protected void btnAdd_Click(object sender, EventArgs e) { ItemUI objUI = new ItemUI(); MastersController objController = new MastersController(); string lblMsg = ""; int ItemCode = Convert.ToInt32(txtItemCode.Text.Trim()); int GroupID = 0; if (rdoAdd.Checked) { GroupID = SaveItemGroupName(); } if (rdoAssign.Checked) { if (drpItemGroup.SelectedIndex != 0) { // strModelCode = drpModelCode.SelectedItem.Text; GroupID = Convert.ToInt32(drpItemGroup.SelectedValue); } } if (GroupID > 0) { string strDescription = txtDesc.Text.Trim(); int IsActive = 0; if (chkActive.Checked) { IsActive = 1; } else { IsActive = 0; } int InReport = 0; if (chkReport.Checked) { InReport = 1; } else { InReport = 0; } //DateTime strCalDate = CalstartDate.SelectedDate; // string strDate = getDate(strCalDate); objUI.ItemCode = ItemCode; objUI.GroupID = GroupID; objUI.Description = strDescription; objUI.IsActive = IsActive; objUI.InReport = InReport; objUI.IsGroup = 1; //string DateTimeAppointment = Convert.ToString(CalstartDate.SelectedDate); string Date = objDate.ConvertDateFormat(CalstartDate.Value); if (Date == "") { objUI.EffectDate = Convert.ToDateTime("1/1/1900"); } else { objUI.EffectDate = Convert.ToDateTime(Date); } objUI.StatusID = Convert.ToInt32(hdnStatusID.Value); //string strQuery = "Insert into Item (Code,Description,IsActive,InReport,EffectDate) values (" + ItemCode + ",'" + strDescription + "'," + IsActive + "," + InReport + ",'" + strDate + "')"; try { //objQueryController.ExecuteQuery(strQuery); objController.AddItem(objUI, null); Response.Redirect(strProjectName+"/View/Forms/Master/ItemDefault.aspx"); } catch (Exception ex) { string strMessage = ex.Message; if (strMessage.Contains("Cannot insert duplicate")) { lblMsg = "Cannot insert duplicate value, Please check the item code"; string strjscript = "<script language='javascript'>"; strjscript += " setMessageText('ctl00_ContentPlaceHolder1_lblMessage','" + lblMsg + "' );"; strjscript += "</script" + ">"; Literal1.Text = strjscript; //lblMessage.Text = "Cannot insert duplicate value, Please check the item code"; } else { lblMsg = "Record could not be added successfully"; string strjscript = "<script language='javascript'>"; strjscript += " setMessageText('ctl00_ContentPlaceHolder1_lblMessage','" + lblMsg + "' );"; strjscript += "</script" + ">"; Literal1.Text = strjscript; // lblMessage.Text = "Record could not be added successfully"; } } } }