コード例 #1
0
        public void OnSelect(vItemSlot slot)
        {
            if (itemtext != null)
            {
                if (slot.item == null)
                {
                    itemtext.text = "";
                }
                else if (slot.item.displayAttributes)
                {
                    text = new StringBuilder();
                    text.Append(slot.item.name + "\n");
                    text.AppendLine(slot.item.description);
                    if (slot.item.attributes != null)
                    {
                        for (int i = 0; i < slot.item.attributes.Count; i++)
                        {
                            var _text = InsertSpaceBeforeUpperCAse(slot.item.attributes[i].name.ToString());
                            text.AppendLine(_text + " : " + slot.item.attributes[i].value.ToString());
                        }
                    }

                    itemtext.text = text.ToString();
                }
            }

            if (onSelectSlot != null)
            {
                onSelectSlot(slot);
            }
        }
コード例 #2
0
 /// <summary>
 /// Add an item to an slot
 /// </summary>
 /// <param name="slot">target Slot</param>
 /// <param name="item">target Item</param>
 ///
 public void AddItemToEquipSlot(vItemSlot slot, vItem item, bool autoEquip = false)
 {
     if (slot is vEquipSlot && equipSlots.Contains(slot as vEquipSlot))
     {
         AddItemToEquipSlot(equipSlots.IndexOf(slot as vEquipSlot), item, autoEquip);
     }
 }
コード例 #3
0
 public virtual void OnSelect(vItemSlot slot)
 {
     currentSelectedSlot = slot;
     CreateFullItemDescription(slot);
     onSelectCallback?.Invoke(slot);
     onSelectSlot.Invoke(slot);
 }
コード例 #4
0
 /// <summary>
 /// Remove item of an slot
 /// </summary>
 /// <param name="slot">target Slot</param>
 public void RemoveItemOfEquipSlot(vItemSlot slot)
 {
     if (slot is vEquipSlot && equipSlots.Contains(slot as vEquipSlot))
     {
         RemoveItemOfEquipSlot(equipSlots.IndexOf(slot as vEquipSlot));
     }
 }
コード例 #5
0
ファイル: vEquipArea.cs プロジェクト: nerodroid/dog_game
        public void OnPickItem(vItemSlot slot)
        {
            if (onPickUpItemCallBack != null)
            {
                onPickUpItemCallBack(this, slot);
            }

            if (currentSelectedSlot.item != null && slot.item != currentSelectedSlot.item)
            {
                currentSelectedSlot.item.isInEquipArea = false;
                var item = currentSelectedSlot.item;
                if (item == slot.item)
                {
                    lastEquipedItem = item;
                }
                currentSelectedSlot.RemoveItem();
                onUnequipItem.Invoke(this, item);
            }

            if (slot.item != currentSelectedSlot.item)
            {
                currentSelectedSlot.AddItem(slot.item);
                onEquipItem.Invoke(this, currentSelectedSlot.item);
            }
            itemPicker.gameObject.SetActive(false);
        }
コード例 #6
0
 /// <summary>
 /// Event called from inventory UI when unselect an slot
 /// </summary>
 /// <param name="slot">target slot</param>
 public void OnDeselect(vItemSlot slot)
 {
     if (equipSlots.Contains(slot as vEquipSlot))
     {
         currentSelectedSlot = null;
     }
 }
コード例 #7
0
 public void OnSubmit(vItemSlot slot)
 {
     if (onSubmitSlot != null)
     {
         onSubmitSlot(slot);
     }
 }
コード例 #8
0
 public virtual void EnableOptions(vItemSlot slot)
 {
     if (slot == null || slot.item == null)
     {
         return;
     }
     useItemButton.interactable = itemsCanBeUsed.Contains(slot.item.type);
 }
コード例 #9
0
ファイル: vEquipArea.cs プロジェクト: nerodroid/dog_game
 public void OnSubmitSlot(vItemSlot slot)
 {
     if (itemPicker != null)
     {
         currentSelectedSlot = slot as vEquipSlot;
         itemPicker.gameObject.SetActive(true);
         itemPicker.CreateEquipmentWindow(inventory.items, currentSelectedSlot.itemType, slot.item, OnPickItem);
     }
 }
コード例 #10
0
 public void OnSubmit(vItemSlot slot)
 {
     currentSelectedSlot = slot;
     if (slot.item)
     {
         var rect = slot.GetComponent <RectTransform>();
         optionWindow.transform.position = rect.position;
         optionWindow.gameObject.SetActive(true);
         optionWindow.EnableOptions(slot);
         currentSelectedSlot = slot;
     }
 }
コード例 #11
0
 public void OnPickUpItemCallBack(vEquipArea area, vItemSlot slot)
 {
     for (int i = 0; i < equipAreas.Count; i++)
     {
         var sameSlots = equipAreas[i].equipSlots.FindAll(slotInArea => slotInArea != slot && slotInArea.item != null && slotInArea.item == slot.item);
         for (int a = 0; a < sameSlots.Count; a++)
         {
             equipAreas[i].UnequipItem(sameSlots[a]);
         }
     }
     CheckTwoHandItem(area, slot);
 }
コード例 #12
0
        /// <summary>
        /// Event called from inventory UI when select an slot
        /// </summary>
        /// <param name="slot">target slot</param>
        public void OnSelectSlot(vItemSlot slot)
        {
            if (equipSlots.Contains(slot as vEquipSlot))
            {
                currentSelectedSlot = slot as vEquipSlot;
            }
            else
            {
                currentSelectedSlot = null;
            }

            onSelectEquipArea.Invoke(this);
            CreateFullItemDescription(slot);
        }
コード例 #13
0
 /// <summary>
 /// Event called from Inventory slot UI on Submit
 /// </summary>
 /// <param name="slot"></param>
 public void OnSubmitSlot(vItemSlot slot)
 {
     lastSelectedSlot = currentSelectedSlot;
     if (itemPicker != null)
     {
         currentSelectedSlot = slot as vEquipSlot;
         if (setEquipSlotWhenSubmit)
         {
             SetEquipSlot(equipSlots.IndexOf(currentSelectedSlot));
         }
         itemPicker.gameObject.SetActive(true);
         itemPicker.onCancelSlot.RemoveAllListeners();
         itemPicker.onCancelSlot.AddListener(CancelCurrentSlot);
         itemPicker.CreateEquipmentWindow(inventory.items, currentSelectedSlot.itemType, slot.item, OnPickItem);
         onInitPickUpItem.Invoke();
     }
 }
コード例 #14
0
        public void ReloadItems(List <vItem> items)
        {
            int indexOfSlot = slots.Contains(currentSelectedSlot) ? slots.IndexOf(currentSelectedSlot) : 0;

            for (int i = 0; i < slots.Count; i++)
            {
                if (i >= 0 && i < slots.Count)
                {
                    if (slots[i] != null && (slots[i].item == null || !items.Contains(slots[i].item)))
                    {
                        Destroy(slots[i].gameObject);
                        slots.Remove(slots[i]);
                        if (i == indexOfSlot)
                        {
                            currentSelectedSlot = i - 1 >= 0 ? slots[i - 1] : slots.Count - 1 > 0 ? slots[0] : null;
                            if (currentSelectedSlot != null)
                            {
                                CreateFullItemDescription(currentSelectedSlot);
                            }
                        }
                        i--;
                    }
                    else if (slots[i] == null)
                    {
                        slots.RemoveAt(i);
                        i--;
                    }
                }
            }
            if (currentSelectedSlot == null || currentSelectedSlot.item == null || slots.Count == 0)
            {
                CreateFullItemDescription(null);
                if (slots.Count == 0)
                {
                    onClearSlots.Invoke();
                }
            }
            else
            {
                CreateFullItemDescription(currentSelectedSlot);
            }
        }
コード例 #15
0
        /// <summary>
        /// Create item description
        /// </summary>
        /// <param name="slot">target slot</param>
        protected virtual void CreateFullItemDescription(vItemSlot slot)
        {
            var _name        = slot.item ? slot.item.name : "";
            var _type        = slot.item ? slot.item.ItemTypeText() : "";
            var _amount      = slot.item ? slot.item.amount.ToString() : "";
            var _description = slot.item ? slot.item.description : "";
            var _attributes  = slot.item ? slot.item.GetItemAttributesText(ignoreAttributes) : "";

            if (displayNameText)
            {
                displayNameText.text = _name;
            }
            onChangeName.Invoke(_name);

            if (displayTypeText)
            {
                displayTypeText.text = _type;
            }
            onChangeType.Invoke(_type);

            if (displayAmountText)
            {
                displayAmountText.text = _amount;
            }
            onChangeAmount.Invoke(_amount);

            if (displayDescriptionText)
            {
                displayDescriptionText.text = _description;
            }
            onChangeDescription.Invoke(_description);

            if (displayAttributesText)
            {
                displayAttributesText.text = _attributes;
            }
            onChangeAttributes.Invoke(_attributes);
        }
コード例 #16
0
        void CheckTwoHandItem(vEquipArea area, vItemSlot slot)
        {
            if (slot.item == null)
            {
                return;
            }
            var opposite = equipAreas.Find(_area => _area != null && area.equipPointName.Equals("LeftArm") && _area.currentEquipedItem != null);

            //var RightEquipmentController = changeEquipmentControllers.Find(equipCtrl => equipCtrl.equipArea != null && equipCtrl.equipArea.equipPointName.Equals("RightArm"));
            if (area.equipPointName.Equals("LeftArm"))
            {
                opposite = equipAreas.Find(_area => _area != null && area.equipPointName.Equals("RightArm") && _area.currentEquipedItem != null);
            }
            else if (!area.equipPointName.Equals("RightArm"))
            {
                return;
            }
            if (opposite != null && (slot.item.twoHandWeapon || opposite.currentEquipedItem.twoHandWeapon))
            {
                opposite.onUnequipItem.Invoke(opposite, slot.item);
                opposite.UnequipItem(slot as vEquipSlot);
            }
        }
コード例 #17
0
ファイル: vEquipArea.cs プロジェクト: nerodroid/dog_game
        public void OnSelectSlot(vItemSlot slot)
        {
            if (equipSlots.Contains(slot as vEquipSlot))
            {
                currentSelectedSlot = slot as vEquipSlot;
            }
            else
            {
                currentSelectedSlot = null;
            }

            onSelectEquipArea.Invoke(this);

            if (itemtext != null)
            {
                if (slot.item == null)
                {
                    itemtext.text = "";
                }
                else
                {
                    text = new StringBuilder();
                    text.Append(slot.item.name + "\n");
                    text.AppendLine(slot.item.description);
                    if (slot.item.attributes != null)
                    {
                        for (int i = 0; i < slot.item.attributes.Count; i++)
                        {
                            var _text = InsertSpaceBeforeUpperCase(slot.item.attributes[i].name.ToString());
                            text.AppendLine(_text + " : " + slot.item.attributes[i].value.ToString());
                        }
                    }

                    itemtext.text = text.ToString();
                }
            }
        }
コード例 #18
0
 public virtual void OnSelectSlot(vItemSlot slot)
 {
     currentSelectedSlot = slot;
 }
コード例 #19
0
 public virtual void OnSubmit(vItemSlot slot)
 {
     currentSelectedSlot = slot;
     onSubmitSlotCallback?.Invoke(slot);
     onSubmitSlot.Invoke(slot);
 }
コード例 #20
0
        public void CreateEquipmentWindow(List <vItem> items, OnSubmitSlot onPickUpItemCallBack = null, OnSelectSlot onSelectSlotCallBack = null, bool destroyAdictionSlots = true)
        {
            var _items = supportedItems.Count == 0? items:items.FindAll(i => supportedItems.Contains(i.type));

            if (_items.Count == 0)
            {
                if (itemtext)
                {
                    itemtext.text = "";
                }
                if (slots.Count > 0 && destroyAdictionSlots)
                {
                    for (int i = 0; i < slots.Count; i++)
                    {
                        Destroy(slots[i].gameObject);
                    }
                    slots.Clear();
                }
                return;
            }

            bool selecItem = false;

            onSubmitSlot = onPickUpItemCallBack;
            onSelectSlot = onSelectSlotCallBack;
            if (slots == null)
            {
                slots = new List <vItemSlot>();
            }
            var count = slots.Count;

            if (updateSlotCount)
            {
                if (count < _items.Count)
                {
                    for (int i = count; i < _items.Count; i++)
                    {
                        var slot = Instantiate(slotPrefab) as vItemSlot;
                        slots.Add(slot);
                        var rectTranform = slot.GetComponent <RectTransform>();
                        rectTranform.SetParent(contentWindow);
                        rectTranform.localPosition = Vector3.zero;

                        rectTranform.localScale = Vector3.one;
                    }
                }
                else if (count > _items.Count)
                {
                    for (int i = count - 1; i > _items.Count - 1; i--)
                    {
                        Destroy(slots[slots.Count - 1].gameObject);
                        slots.RemoveAt(slots.Count - 1);
                    }
                }
            }

            count = slots.Count;
            for (int i = 0; i < _items.Count; i++)
            {
                vItemSlot slot = null;
                if (i < count)
                {
                    slot = slots[i];
                    slot.AddItem(_items[i]);
                    slot.CheckItem(_items[i].isInEquipArea);
                    slot.onSubmitSlotCallBack = OnSubmit;
                    slot.onSelectSlotCallBack = OnSelect;

                    if (currentItem != null && currentItem == _items[i])
                    {
                        selecItem = true;
                        SetSelectable(slot.gameObject);
                    }
                }
            }

            if (slots.Count > 0 && !selecItem)
            {
                StartCoroutine(SetSelectableHandle(slots[0].gameObject));
            }

            if (onCompleteSlotListCallBack != null)
            {
                onCompleteSlotListCallBack(slots);
            }
        }
コード例 #21
0
        protected virtual IEnumerator CreateEquipmentWindowRoutine(List <vItem> items, UnityAction <vItemSlot> onPickUpItemCallBack = null, UnityAction <vItemSlot> onSelectSlotCallBack = null, bool destroyAdictionSlots = true)
        {
            var _items = supportedItems.Count == 0 ? items : items.FindAll(i => supportedItems.Contains(i.type));

            if (_items.Count == 0)
            {
                CreateFullItemDescription(null);
                onClearSlots.Invoke();
                if (slots.Count > 0 && destroyAdictionSlots && updateSlotCount)
                {
                    for (int i = 0; i < slots.Count; i++)
                    {
                        yield return(null);

                        Destroy(slots[i].gameObject);
                    }
                    slots.Clear();
                }
            }
            else
            {
                if (slots.Count > _items.Count && destroyAdictionSlots && updateSlotCount)
                {
                    int difference = slots.Count - _items.Count;

                    for (int i = 0; i < difference; i++)
                    {
                        yield return(null);

                        Destroy(slots[0].gameObject);
                        slots.RemoveAt(0);
                    }
                }
                bool selecItem = false;
                onSubmitSlotCallback = onPickUpItemCallBack;
                onSelectCallback     = onSelectSlotCallBack;
                if (slots == null)
                {
                    slots = new List <vItemSlot>();
                }
                var count = items.Count;
                //  if (updateSlotCount)
                {
                    for (int i = 0; i < _items.Count; i++)
                    {
                        vItemSlot slot = null;
                        if (i < slots.Count)
                        {
                            slot = slots[i];
                        }
                        else
                        {
                            slot = Instantiate(slotPrefab) as vItemSlot;

                            slots.Add(slot);
                            var rectTranform = slot.GetComponent <RectTransform>();
                            rectTranform.SetParent(contentWindow);
                            rectTranform.localPosition = Vector3.zero;
                            rectTranform.localScale    = Vector3.one;
                            yield return(null);
                        }
                        //  slot = slots[i];
                        slot.AddItem(_items[i]);
                        slot.CheckItem(_items[i].isInEquipArea);
                        slot.onSubmitSlotCallBack = OnSubmit;
                        slot.onSelectSlotCallBack = OnSelect;

                        if (currentItem != null && currentItem == _items[i])
                        {
                            selecItem           = true;
                            currentSelectedSlot = slot;
                            SetSelectable(slot.gameObject);
                        }
                    }
                }
                if (slots.Count > 0 && !selecItem)
                {
                    currentSelectedSlot = slots[0];
                    StartCoroutine(SetSelectableHandle(slots[0].gameObject));
                }
            }

            if (slots.Count > 0)
            {
                onAddSlots.Invoke();
                CreateFullItemDescription(currentSelectedSlot);
            }
            onCompleteSlotListCallBack.Invoke(slots);
        }