public void complete() { m_VisualSelector.onComplete(); this.sourceInventory = null; this.targetInventory = null; this.sourceSlot = null; }
public override void close() { base.close(); this.indexInFilter = -1; m_ItemSlot = null; TezSamplePool <TezInventoryFilterSlot> .instance.recycle(this); }
private TezInventoryFilterSlot createOrGetFilterSlot(TezInventoryItemSlot itemSlot) { if (!m_SlotDic.TryGetValue(itemSlot.index, out var slot)) { foreach (var filter_slot in m_SlotList) { if (filter_slot.itemSlot == null) { slot = filter_slot; break; } } if (slot == null) { slot = TezInventoryFilterSlot.create(); slot.index = m_SlotList.Count; m_SlotList.Add(slot); } m_SlotDic.Add(itemSlot.index, slot); slot.bindItemSlot(itemSlot); } return(slot); }
public virtual void close() { this.sourceInventory = null; this.targetInventory = null; this.sourceSlot = null; }
private TezInventoryItemSlot findSlotStackable(TezComData gameObject) { TezInventoryItemSlot result_slot = null; int result_index = 0; while (result_index < m_Slots.Count) { var slot = m_Slots[result_index]; ///找空格子 if (result_slot == null && slot.item == null) { result_slot = slot; } ///找相同格子 ///可堆叠的物品 ///他们的模板相同 if (slot.item != null && slot.item.templateAs(gameObject)) { result_slot = slot; break; } result_index++; } return(result_slot); }
private void onItemAdded(TezInventoryItemSlot itemSlot) { ///添加物品时需要计算过滤范围 ///如果不符合条件 ///就不显示 if (m_CurrentFilter.calculate(itemSlot.item)) { var data_slot = m_CurrentFilter.createSlot(itemSlot); if (data_slot != null) { onItemChanged?.Invoke(data_slot); } } }
/// <summary> /// 堆叠型加入 /// </summary> public void store(TezComData gameObject, int count) { var stack_max_count = TezDatabaseItemConfig.getConfig(gameObject.category).stackCount; TezInventoryItemSlot result_slot = this.findSlotStackable(gameObject); ///找到空格子 if (result_slot != null) { if (result_slot.item != null) { result_slot.count += count; var remain = result_slot.count - stack_max_count; if (remain > 0) { result_slot.count = stack_max_count; this.store(gameObject, remain); } else { gameObject.close(); } } else { result_slot.item = gameObject; if (count > stack_max_count) { result_slot.count = stack_max_count; this.store(gameObject, count - stack_max_count); } else { result_slot.count = count; } } } ///没有找到空格子 else { result_slot = this.createItemSlot(); result_slot.item = gameObject; result_slot.count = count; result_slot.index = m_Slots.Count; m_Slots.Add(result_slot); } onItemAdded?.Invoke(result_slot); }
private void onItemRemoved(TezInventoryItemSlot itemSlot) { ///删除时无需检测过滤条件 ///只需要检测是否被当前过滤条件记录即可 var data_slot = m_CurrentFilter.convertToDataSlot(itemSlot); if (data_slot != null) { onItemChanged?.Invoke(data_slot); if (data_slot.category == TezInventoryDataSlot.Category.Filter) { if (itemSlot.item == null) { m_SlotDic.Remove(itemSlot.index); ((TezInventoryFilterSlot)data_slot).bindItemSlot(null); } } } }
/// <summary> /// 存入 /// 不允许堆叠 /// </summary> public void store(TezComData gameObject) { TezInventoryItemSlot result_slot = this.findSlotUnstackable(); ///找到空格子 if (result_slot != null) { result_slot.item = gameObject; result_slot.count = -1; } ///没有找到空格子 else { result_slot = this.createItemSlot(); result_slot.item = gameObject; result_slot.count = -1; result_slot.index = m_Slots.Count; m_Slots.Add(result_slot); } onItemAdded?.Invoke(result_slot); }
public void setSlot(TezInventoryItemSlot slot) { this.sourceSlot = slot; this.sourceInventory = slot.inventory; m_VisualSelector.onSelect(slot.item); }
public void bindItemSlot(TezInventoryItemSlot slot) { m_ItemSlot = slot; }
public override TezInventoryDataSlot createSlot(TezInventoryItemSlot itemSlot) { return(this.manager.createOrGetFilterSlot(itemSlot)); }
public override TezInventoryDataSlot createSlot(TezInventoryItemSlot itemSlot) { return(itemSlot); }
public override TezInventoryDataSlot convertToDataSlot(TezInventoryItemSlot itemSlot) { return(itemSlot); }
public abstract TezInventoryDataSlot createSlot(TezInventoryItemSlot itemSlot);
/// <summary> /// 将当前ItemSlot /// 转化为Filter中的Slot /// </summary> public abstract TezInventoryDataSlot convertToDataSlot(TezInventoryItemSlot itemSlot);
public static void selectSlot(TezInventory inventory, TezInventoryItemSlot itemSlot) { if (itemSlot.picked) { return; } ///没有被选择的Inventory 或者是一样的 就是Pick功能 if (m_SelectedInventory == null) { itemSlot.picked = true; m_SelectedInventory = inventory; m_SelectedItemList.Add(itemSlot); eventState?.Invoke(State.BeginAdd); } else { if (m_SelectedInventory == inventory) { itemSlot.picked = true; m_SelectedItemList.Add(itemSlot); eventState?.Invoke(State.ContinueAdd); } else { ///只选择了一个 if (m_SelectedItemList.Count == 1) { ///如果选择的槽位有item了 ///就是交换功能 if (itemSlot.item != null) { var count = m_SelectedItemList[0].count; var temp = m_SelectedItemList[0].take(); m_SelectedItemList[0].item = itemSlot.item; m_SelectedItemList[0].count = itemSlot.count; itemSlot.item = temp; itemSlot.count = count; eventState?.Invoke(State.ItemSwitch); } ///否则就是存储功能 else { var count = m_SelectedItemList[0].count; var item = m_SelectedItemList[0].take(); itemSlot.store(item, count); eventState?.Invoke(State.ContinueAdd); } } ///大量释放就是存储功能 else { for (int i = 0; i < m_SelectedItemList.Count; i++) { var count = m_SelectedItemList[i].count; var item = m_SelectedItemList[i].take(); inventory.store(item, count); } eventState?.Invoke(State.ContinueAdd); } } } }
public override TezInventoryDataSlot convertToDataSlot(TezInventoryItemSlot itemSlot) { this.manager.m_SlotDic.TryGetValue(itemSlot.index, out var slot); return(slot); }