This commit is contained in:
Nim XD
2024-08-27 21:01:33 +05:30
parent 99eaf514fd
commit 121a1b7c73
31803 changed files with 623461 additions and 623399 deletions

View File

@@ -1,145 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using Assets.HeroEditor4D.InventorySystem.Scripts.Helpers;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents hero (player) equipment. Based on equipment slots.
/// </summary>
public class Equipment : ItemContainer
{
public Action OnRefresh;
/// <summary>
/// Defines what kinds of items can be equipped.
/// </summary>
public List<ItemSlot> Slots;
/// <summary>
/// Equipped items will be instantiated in front of equipment slots.
/// </summary>
public GameObject ItemPrefab;
/// <summary>
/// Character preview.
/// </summary>
public Character Preview;
public Transform Scheme;
public int BagSize;
public readonly List<InventoryItem> InventoryItems = new List<InventoryItem>();
public void OnValidate()
{
if (Application.isPlaying) return;
Slots = GetComponentsInChildren<ItemSlot>(true).ToList();
//if (Character == null)
//{
// Character = FindObjectOfType<Character>();
//}
}
public void Start()
{
//Character.Animator.SetBool("Ready", false);
}
public void SetBagSize(int size)
{
BagSize = size;
var supplies = GetComponentsInChildren<ItemSlot>(true).Where(i => i.Types.Contains(ItemType.Supply)).ToList();
for (var i = 0; i < supplies.Count; i++)
{
supplies[i].Locked = i >= size;
}
}
public bool SelectAny()
{
if (InventoryItems.Count > 0)
{
InventoryItems[0].Select(true);
return true;
}
return false;
}
public override void Refresh(Item selected)
{
var items = Slots.Select(FindItem).Where(i => i != null).ToList();
var toggleGroup = GetComponentInParent<ToggleGroup>(includeInactive: true);
Reset();
foreach (var slot in Slots)
{
var item = FindItem(slot);
slot.gameObject.SetActive(item == null);
if (item == null) continue;
var inventoryItem = Instantiate(ItemPrefab, slot.transform.parent).GetComponent<InventoryItem>();
inventoryItem.Initialize(item, toggleGroup);
inventoryItem.Count.text = null;
inventoryItem.transform.position = slot.transform.position;
inventoryItem.transform.SetSiblingIndex(slot.transform.GetSiblingIndex());
if (AutoSelect) inventoryItem.Select(item == selected);
InventoryItems.Add(inventoryItem);
}
if (Preview)
{
CharacterInventorySetup.Setup(Preview, items);
Preview.Initialize();
}
OnRefresh?.Invoke();
}
private void Reset()
{
foreach (var inventoryItem in InventoryItems)
{
Destroy(inventoryItem.gameObject);
}
InventoryItems.Clear();
}
private Item FindItem(ItemSlot slot)
{
if (slot.Types.Contains(ItemType.Shield))
{
var copy = Items.SingleOrDefault(i => i.Params.Type == ItemType.Weapon && (i.IsTwoHanded || i.IsFirearm));
if (copy != null)
{
return copy;
}
}
var index = Slots.Where(i => i.Types.SequenceEqual(slot.Types)).ToList().IndexOf(slot);
var items = Items.Where(slot.Supports).ToList();
return index < items.Count ? items[index] : null;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using Assets.HeroEditor4D.InventorySystem.Scripts.Helpers;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents hero (player) equipment. Based on equipment slots.
/// </summary>
public class Equipment : ItemContainer
{
public Action OnRefresh;
/// <summary>
/// Defines what kinds of items can be equipped.
/// </summary>
public List<ItemSlot> Slots;
/// <summary>
/// Equipped items will be instantiated in front of equipment slots.
/// </summary>
public GameObject ItemPrefab;
/// <summary>
/// Character preview.
/// </summary>
public Character Preview;
public Transform Scheme;
public int BagSize;
public readonly List<InventoryItem> InventoryItems = new List<InventoryItem>();
public void OnValidate()
{
if (Application.isPlaying) return;
Slots = GetComponentsInChildren<ItemSlot>(true).ToList();
//if (Character == null)
//{
// Character = FindObjectOfType<Character>();
//}
}
public void Start()
{
//Character.Animator.SetBool("Ready", false);
}
public void SetBagSize(int size)
{
BagSize = size;
var supplies = GetComponentsInChildren<ItemSlot>(true).Where(i => i.Types.Contains(ItemType.Supply)).ToList();
for (var i = 0; i < supplies.Count; i++)
{
supplies[i].Locked = i >= size;
}
}
public bool SelectAny()
{
if (InventoryItems.Count > 0)
{
InventoryItems[0].Select(true);
return true;
}
return false;
}
public override void Refresh(Item selected)
{
var items = Slots.Select(FindItem).Where(i => i != null).ToList();
var toggleGroup = GetComponentInParent<ToggleGroup>(includeInactive: true);
Reset();
foreach (var slot in Slots)
{
var item = FindItem(slot);
slot.gameObject.SetActive(item == null);
if (item == null) continue;
var inventoryItem = Instantiate(ItemPrefab, slot.transform.parent).GetComponent<InventoryItem>();
inventoryItem.Initialize(item, toggleGroup);
inventoryItem.Count.text = null;
inventoryItem.transform.position = slot.transform.position;
inventoryItem.transform.SetSiblingIndex(slot.transform.GetSiblingIndex());
if (AutoSelect) inventoryItem.Select(item == selected);
InventoryItems.Add(inventoryItem);
}
if (Preview)
{
CharacterInventorySetup.Setup(Preview, items);
Preview.Initialize();
}
OnRefresh?.Invoke();
}
private void Reset()
{
foreach (var inventoryItem in InventoryItems)
{
Destroy(inventoryItem.gameObject);
}
InventoryItems.Clear();
}
private Item FindItem(ItemSlot slot)
{
if (slot.Types.Contains(ItemType.Shield))
{
var copy = Items.SingleOrDefault(i => i.Params.Type == ItemType.Weapon && (i.IsTwoHanded || i.IsFirearm));
if (copy != null)
{
return copy;
}
}
var index = Slots.Where(i => i.Types.SequenceEqual(slot.Types)).ToList().IndexOf(slot);
var items = Items.Where(slot.Supports).ToList();
return index < items.Count ? items[index] : null;
}
}
}

View File

@@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: a0b571b9054039e4599e0d695cdcab42
timeCreated: 1508495828
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a0b571b9054039e4599e0d695cdcab42
timeCreated: 1508495828
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,201 +1,201 @@
using System;
using System.Collections;
using Assets.HeroEditor4D.Common.Scripts.Common;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents inventory item and handles drag & drop operations.
/// </summary>
public class InventoryItem : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
[Header("Main")]
public Image Icon;
public Image Background;
public Image Frame;
public Text Count;
public Toggle Toggle;
[Header("Extra")]
public Sprite IconEmpty;
public Sprite IconMissed;
public Image Comparer;
public Image Fragment;
public GameObject Modificator;
public Text ModificatorText;
public Item Item { get; private set; }
private Action _scheduled;
private float _clickTime;
/// <summary>
/// These actions should be set when inventory UI is opened.
/// </summary>
public static Action<Item> OnLeftClick;
public static Action<Item> OnRightClick;
public static Action<Item> OnDoubleClick;
public static Action<Item> OnMouseEnter;
public static Action<Item> OnMouseExit;
public void OnEnable()
{
if (_scheduled != null)
{
StartCoroutine(ExecuteScheduled());
}
}
public void Initialize(Item item, ToggleGroup toggleGroup = null)
{
Item = item;
if (Item == null)
{
Reset();
return;
}
Icon.enabled = true;
Icon.sprite = item.Id == null ? IconEmpty : ItemCollection.Active.GetItemIcon(Item)?.Sprite ?? IconMissed;
Background.sprite = ItemCollection.Active.GetBackground(Item) ?? ItemCollection.Active.BackgroundBrown;
Background.color = Color.white;
Frame.raycastTarget = true;
if (Count)
{
Count.SetActive(true);
Count.text = item.Count.ToString();
}
if (Fragment)
{
Fragment.SetActive(true);
Fragment.SetActive(Item.Params.Type == ItemType.Fragment);
}
if (Toggle)
{
Toggle.group = toggleGroup ?? GetComponentInParent<ToggleGroup>();
}
if (Modificator)
{
var mod = Item.Modifier != null && Item.Modifier.Id != ItemModifier.None;
Modificator.SetActive(mod);
if (mod)
{
string text;
switch (Item.Modifier.Id)
{
case ItemModifier.LevelDown: text = "G-"; break;
case ItemModifier.LevelUp: text = "G+"; break;
default: text = Item.Modifier.Id.ToString().ToUpper()[0].ToString(); break;
}
ModificatorText.text = text;
}
}
}
public void Reset()
{
Icon.enabled = false;
Icon.sprite = null;
Background.sprite = ItemCollection.Active.BackgroundBrown ?? Background.sprite;
Background.color = new Color32(150, 150, 150, 255);
Frame.raycastTarget = false;
if (Count) Count.SetActive(false);
if (Toggle) { Toggle.group = null; Toggle.SetIsOnWithoutNotify(false); }
if (Modificator) Modificator.SetActive(false);
if (Comparer) Comparer.SetActive(false);
if (Fragment) Fragment.SetActive(false);
}
public void OnPointerClick(PointerEventData eventData)
{
OnPointerClick(eventData.button);
}
public void OnPointerEnter(PointerEventData eventData)
{
OnMouseEnter?.Invoke(Item);
}
public void OnPointerExit(PointerEventData eventData)
{
OnMouseExit?.Invoke(Item);
}
public void OnPointerClick(PointerEventData.InputButton button)
{
if (button == PointerEventData.InputButton.Left)
{
OnLeftClick?.Invoke(Item);
var delta = Mathf.Abs(Time.time - _clickTime);
if (delta < 0.5f) // If double click.
{
_clickTime = 0;
if (OnDoubleClick != null)
{
StartCoroutine(ExecuteInNextUpdate(() => OnDoubleClick(Item)));
}
}
else
{
_clickTime = Time.time;
}
}
else if (button == PointerEventData.InputButton.Right)
{
OnRightClick?.Invoke(Item);
}
}
private static IEnumerator ExecuteInNextUpdate(Action action)
{
yield return null;
action();
}
public void Select(bool selected)
{
if (Toggle == null) return;
if (gameObject.activeInHierarchy || !selected)
{
Toggle.isOn = selected;
}
else
{
_scheduled = () => Toggle.isOn = true;
}
if (selected)
{
OnLeftClick?.Invoke(Item);
}
}
private IEnumerator ExecuteScheduled()
{
yield return null;
_scheduled();
_scheduled = null;
}
}
using System;
using System.Collections;
using Assets.HeroEditor4D.Common.Scripts.Common;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents inventory item and handles drag & drop operations.
/// </summary>
public class InventoryItem : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
[Header("Main")]
public Image Icon;
public Image Background;
public Image Frame;
public Text Count;
public Toggle Toggle;
[Header("Extra")]
public Sprite IconEmpty;
public Sprite IconMissed;
public Image Comparer;
public Image Fragment;
public GameObject Modificator;
public Text ModificatorText;
public Item Item { get; private set; }
private Action _scheduled;
private float _clickTime;
/// <summary>
/// These actions should be set when inventory UI is opened.
/// </summary>
public static Action<Item> OnLeftClick;
public static Action<Item> OnRightClick;
public static Action<Item> OnDoubleClick;
public static Action<Item> OnMouseEnter;
public static Action<Item> OnMouseExit;
public void OnEnable()
{
if (_scheduled != null)
{
StartCoroutine(ExecuteScheduled());
}
}
public void Initialize(Item item, ToggleGroup toggleGroup = null)
{
Item = item;
if (Item == null)
{
Reset();
return;
}
Icon.enabled = true;
Icon.sprite = item.Id == null ? IconEmpty : ItemCollection.Active.GetItemIcon(Item)?.Sprite ?? IconMissed;
Background.sprite = ItemCollection.Active.GetBackground(Item) ?? ItemCollection.Active.BackgroundBrown;
Background.color = Color.white;
Frame.raycastTarget = true;
if (Count)
{
Count.SetActive(true);
Count.text = item.Count.ToString();
}
if (Fragment)
{
Fragment.SetActive(true);
Fragment.SetActive(Item.Params.Type == ItemType.Fragment);
}
if (Toggle)
{
Toggle.group = toggleGroup ?? GetComponentInParent<ToggleGroup>();
}
if (Modificator)
{
var mod = Item.Modifier != null && Item.Modifier.Id != ItemModifier.None;
Modificator.SetActive(mod);
if (mod)
{
string text;
switch (Item.Modifier.Id)
{
case ItemModifier.LevelDown: text = "G-"; break;
case ItemModifier.LevelUp: text = "G+"; break;
default: text = Item.Modifier.Id.ToString().ToUpper()[0].ToString(); break;
}
ModificatorText.text = text;
}
}
}
public void Reset()
{
Icon.enabled = false;
Icon.sprite = null;
Background.sprite = ItemCollection.Active.BackgroundBrown ?? Background.sprite;
Background.color = new Color32(150, 150, 150, 255);
Frame.raycastTarget = false;
if (Count) Count.SetActive(false);
if (Toggle) { Toggle.group = null; Toggle.SetIsOnWithoutNotify(false); }
if (Modificator) Modificator.SetActive(false);
if (Comparer) Comparer.SetActive(false);
if (Fragment) Fragment.SetActive(false);
}
public void OnPointerClick(PointerEventData eventData)
{
OnPointerClick(eventData.button);
}
public void OnPointerEnter(PointerEventData eventData)
{
OnMouseEnter?.Invoke(Item);
}
public void OnPointerExit(PointerEventData eventData)
{
OnMouseExit?.Invoke(Item);
}
public void OnPointerClick(PointerEventData.InputButton button)
{
if (button == PointerEventData.InputButton.Left)
{
OnLeftClick?.Invoke(Item);
var delta = Mathf.Abs(Time.time - _clickTime);
if (delta < 0.5f) // If double click.
{
_clickTime = 0;
if (OnDoubleClick != null)
{
StartCoroutine(ExecuteInNextUpdate(() => OnDoubleClick(Item)));
}
}
else
{
_clickTime = Time.time;
}
}
else if (button == PointerEventData.InputButton.Right)
{
OnRightClick?.Invoke(Item);
}
}
private static IEnumerator ExecuteInNextUpdate(Action action)
{
yield return null;
action();
}
public void Select(bool selected)
{
if (Toggle == null) return;
if (gameObject.activeInHierarchy || !selected)
{
Toggle.isOn = selected;
}
else
{
_scheduled = () => Toggle.isOn = true;
}
if (selected)
{
OnLeftClick?.Invoke(Item);
}
}
private IEnumerator ExecuteScheduled()
{
yield return null;
_scheduled();
_scheduled = null;
}
}
}

View File

@@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: e0aafb945e34dad42af9accb93f787da
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e0aafb945e34dad42af9accb93f787da
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,30 +1,30 @@
using System.Collections.Generic;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using UnityEngine;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Abstract item container. It can be inventory bag, player equipment or trader goods.
/// </summary>
public abstract class ItemContainer : MonoBehaviour
{
/// <summary>
/// List of items.
/// </summary>
public List<Item> Items { get; protected set; } = new List<Item>();
[Header("Settings")]
[Tooltip("Stack identical inventory items to a single UI element.")]
public bool Stacked = true;
public bool AutoSelect = true;
public abstract void Refresh(Item selected);
public void Initialize(ref List<Item> items, Item selected = null)
{
Items = items;
Refresh(selected);
}
}
using System.Collections.Generic;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using UnityEngine;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Abstract item container. It can be inventory bag, player equipment or trader goods.
/// </summary>
public abstract class ItemContainer : MonoBehaviour
{
/// <summary>
/// List of items.
/// </summary>
public List<Item> Items { get; protected set; } = new List<Item>();
[Header("Settings")]
[Tooltip("Stack identical inventory items to a single UI element.")]
public bool Stacked = true;
public bool AutoSelect = true;
public abstract void Refresh(Item selected);
public void Initialize(ref List<Item> items, Item selected = null)
{
Items = items;
Refresh(selected);
}
}
}

View File

@@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: cba7422e860e3ac42ad3a70a98329be1
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: cba7422e860e3ac42ad3a70a98329be1
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,137 +1,137 @@
using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents item when it was selected. Displays icon, name, price and properties.
/// </summary>
public class ItemInfo : MonoBehaviour
{
public GameObject Selection;
public GameObject Buttons;
public Text Name;
public Text Labels;
public Text Values;
public Text Price;
public Image Icon;
public Image Background;
public Item Item { get; protected set; }
protected static readonly List<PropertyId> Sorting = new List<PropertyId>
{
PropertyId.Damage,
PropertyId.StaminaMax,
PropertyId.Blocking,
PropertyId.Resistance
};
public void OnEnable()
{
if (Item == null)
{
Reset();
}
}
public void Reset()
{
Selection.SetActive(false);
Buttons.SetActive(false);
if (Name) Name.text = null;
if (Labels) Labels.text = null;
if (Values) Values.text = null;
if (Price) Price.text = null;
}
public virtual void Initialize(Item item, int price, bool trader = false)
{
Item = item;
if (item == null)
{
Reset();
return;
}
Selection.SetActive(true);
Buttons.SetActive(true);
Name.text = item.Params.GetLocalizedName(Application.systemLanguage.ToString());
Icon.sprite = ItemCollection.Active.FindIcon(item.Params.IconId);
Background.sprite = ItemCollection.Active.GetBackground(item);
UpdatePrice(item, price, trader);
var main = new List<object> { item.Params.Type };
if (item.Params.Class != ItemClass.Undefined) main.Add(item.Params.Class);
foreach (var t in item.Params.Tags)
{
main.Add(t);
}
var dict = new Dictionary<string, object> { { "ItemInfo.Type", string.Join(" / ", main) } };
if (item.Params.Level >= 0) dict.Add("ItemInfo.Level", item.Params.Level);
if (item.Modifier != null)
{
dict.Add("ItemInfo.Modifier", $"{item.Modifier.Id} [{item.Modifier.Level}]");
}
var props = item.Params.Properties.ToList().OrderBy(i => { var index = Sorting.IndexOf(i.Id); return index == -1 ? 999 : index; }).ToList();
foreach (var p in props)
{
switch (p.Id)
{
case PropertyId.Damage:
dict.Add($"ItemInfo.{p.Id}", $"{p.Min}-{p.Max}");
break;
case PropertyId.CriticalChance:
case PropertyId.CriticalDamage:
dict.Add($"ItemInfo.{p.Id}", $"+{p.Value}%");
break;
case PropertyId.ChargeTimings:
dict.Add($"ItemInfo.{p.Id}", $"{p.Value.Split(',').Length}");
break;
default:
dict.Add($"ItemInfo.{p.Id}", $"{p.Value}");
break;
}
}
dict.Add("ItemInfo.Weight", $"{item.Params.Weight / 10f:0.##} kg");
if (Price && item.Params.Type != ItemType.Currency)
{
dict.Add("ItemInfo.Price", $"{item.Params.Price} gold");
}
Labels.text = string.Join("\n", dict.Keys);
Values.text = string.Join("\n", dict.Values);
}
public virtual void UpdatePrice(Item item, int price, bool trader)
{
if (!Price) return;
if (item.Params.Type == ItemType.Currency)
{
Price.text = null;
}
else
{
Price.text = trader ? $"Buy price: {price}G" : $"Sell price: {price}G";
}
}
}
using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents item when it was selected. Displays icon, name, price and properties.
/// </summary>
public class ItemInfo : MonoBehaviour
{
public GameObject Selection;
public GameObject Buttons;
public Text Name;
public Text Labels;
public Text Values;
public Text Price;
public Image Icon;
public Image Background;
public Item Item { get; protected set; }
protected static readonly List<PropertyId> Sorting = new List<PropertyId>
{
PropertyId.Damage,
PropertyId.StaminaMax,
PropertyId.Blocking,
PropertyId.Resistance
};
public void OnEnable()
{
if (Item == null)
{
Reset();
}
}
public void Reset()
{
Selection.SetActive(false);
Buttons.SetActive(false);
if (Name) Name.text = null;
if (Labels) Labels.text = null;
if (Values) Values.text = null;
if (Price) Price.text = null;
}
public virtual void Initialize(Item item, int price, bool trader = false)
{
Item = item;
if (item == null)
{
Reset();
return;
}
Selection.SetActive(true);
Buttons.SetActive(true);
Name.text = item.Params.GetLocalizedName(Application.systemLanguage.ToString());
Icon.sprite = ItemCollection.Active.FindIcon(item.Params.IconId);
Background.sprite = ItemCollection.Active.GetBackground(item);
UpdatePrice(item, price, trader);
var main = new List<object> { item.Params.Type };
if (item.Params.Class != ItemClass.Undefined) main.Add(item.Params.Class);
foreach (var t in item.Params.Tags)
{
main.Add(t);
}
var dict = new Dictionary<string, object> { { "ItemInfo.Type", string.Join(" / ", main) } };
if (item.Params.Level >= 0) dict.Add("ItemInfo.Level", item.Params.Level);
if (item.Modifier != null)
{
dict.Add("ItemInfo.Modifier", $"{item.Modifier.Id} [{item.Modifier.Level}]");
}
var props = item.Params.Properties.ToList().OrderBy(i => { var index = Sorting.IndexOf(i.Id); return index == -1 ? 999 : index; }).ToList();
foreach (var p in props)
{
switch (p.Id)
{
case PropertyId.Damage:
dict.Add($"ItemInfo.{p.Id}", $"{p.Min}-{p.Max}");
break;
case PropertyId.CriticalChance:
case PropertyId.CriticalDamage:
dict.Add($"ItemInfo.{p.Id}", $"+{p.Value}%");
break;
case PropertyId.ChargeTimings:
dict.Add($"ItemInfo.{p.Id}", $"{p.Value.Split(',').Length}");
break;
default:
dict.Add($"ItemInfo.{p.Id}", $"{p.Value}");
break;
}
}
dict.Add("ItemInfo.Weight", $"{item.Params.Weight / 10f:0.##} kg");
if (Price && item.Params.Type != ItemType.Currency)
{
dict.Add("ItemInfo.Price", $"{item.Params.Price} gold");
}
Labels.text = string.Join("\n", dict.Keys);
Values.text = string.Join("\n", dict.Values);
}
public virtual void UpdatePrice(Item item, int price, bool trader)
{
if (!Price) return;
if (item.Params.Type == ItemType.Currency)
{
Price.text = null;
}
else
{
Price.text = trader ? $"Buy price: {price}G" : $"Sell price: {price}G";
}
}
}
}

View File

@@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: 71a926fb72b5a4f438891452c4866688
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 71a926fb72b5a4f438891452c4866688
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,36 +1,36 @@
using System.Collections.Generic;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents equipment slot. Inventory items can be placed here.
/// </summary>
public class ItemSlot : MonoBehaviour
{
public Image Icon;
public Image Background;
public Sprite ActiveSprite;
public Sprite LockedSprite;
public List<ItemType> Types;
public List<ItemClass> Classes;
public bool Locked
{
get => Icon.sprite == LockedSprite;
set
{
Icon.sprite = value ? LockedSprite : ActiveSprite;
Background.color = value ? new Color32(150, 150, 150, 255) : new Color32(255, 255, 255, 255);
}
}
public bool Supports(Item item)
{
return Types.Contains(item.Params.Type) && (Classes.Count == 0 || Classes.Contains(item.Params.Class)) && !Locked;
}
}
using System.Collections.Generic;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Represents equipment slot. Inventory items can be placed here.
/// </summary>
public class ItemSlot : MonoBehaviour
{
public Image Icon;
public Image Background;
public Sprite ActiveSprite;
public Sprite LockedSprite;
public List<ItemType> Types;
public List<ItemClass> Classes;
public bool Locked
{
get => Icon.sprite == LockedSprite;
set
{
Icon.sprite = value ? LockedSprite : ActiveSprite;
Background.color = value ? new Color32(150, 150, 150, 255) : new Color32(255, 255, 255, 255);
}
}
public bool Supports(Item item)
{
return Types.Contains(item.Params.Type) && (Classes.Count == 0 || Classes.Contains(item.Params.Class)) && !Locked;
}
}
}

View File

@@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: c75e3a26bedbcb147bcb8f02343721f3
timeCreated: 1508495903
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c75e3a26bedbcb147bcb8f02343721f3
timeCreated: 1508495903
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,95 +1,95 @@
using System;
using System.Linq;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using UnityEngine;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Abstract item workspace. It can be shop or player inventory. Items can be managed here (selected, moved and so on).
/// </summary>
public abstract class ItemWorkspace : MonoBehaviour
{
public ItemCollection ItemCollection;
public ItemInfo ItemInfo;
public static float SfxVolume = 1;
public Item SelectedItem { get; protected set; }
public abstract void Refresh();
protected void Reset()
{
SelectedItem = null;
ItemInfo.Reset();
}
protected void MoveItem(Item item, ItemContainer from, ItemContainer to, int amount = 1, string currencyId = null)
{
MoveItemSilent(item, from, to, amount);
var moved = to.Items.Last(i => i.Hash == item.Hash);
if (from.Stacked)
{
if (item.Count == 0)
{
SelectedItem = currencyId == null ? moved : from.Items.Single(i => i.Id == currencyId);
}
}
else
{
SelectedItem = from.Items.LastOrDefault(i => i.Hash == item.Hash) ?? moved;
}
Refresh();
from.Refresh(SelectedItem);
to.Refresh(SelectedItem);
}
public void MoveItemSilent(Item item, ItemContainer from, ItemContainer to, int amount = 1)
{
if (item.Count <= 0) throw new ArgumentException("item.Count <= 0");
if (amount <= 0) throw new ArgumentException("amount <= 0");
if (item.Count < amount) throw new ArgumentException("item.Count < amount");
if (to.Stacked)
{
var targets = to.Items.Where(i => i.Hash == item.Hash).ToList();
switch (targets.Count)
{
case 0:
to.Items.Add(new Item(item.Id, item.Modifier, amount));
break;
case 1:
targets[0].Count += amount;
break;
default:
throw new Exception($"Unable to move item silently: {item.Id} ({item.Hash}).");
}
}
else
{
to.Items.Add(new Item(item.Id, item.Modifier, amount));
}
var moved = to.Items.Last(i => i.Hash == item.Hash);
if (from.Stacked)
{
item.Count -= amount;
if (item.Count == 0)
{
from.Items.Remove(item);
}
}
else
{
from.Items.Remove(item);
}
}
}
using System;
using System.Linq;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using UnityEngine;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Abstract item workspace. It can be shop or player inventory. Items can be managed here (selected, moved and so on).
/// </summary>
public abstract class ItemWorkspace : MonoBehaviour
{
public ItemCollection ItemCollection;
public ItemInfo ItemInfo;
public static float SfxVolume = 1;
public Item SelectedItem { get; protected set; }
public abstract void Refresh();
protected void Reset()
{
SelectedItem = null;
ItemInfo.Reset();
}
protected void MoveItem(Item item, ItemContainer from, ItemContainer to, int amount = 1, string currencyId = null)
{
MoveItemSilent(item, from, to, amount);
var moved = to.Items.Last(i => i.Hash == item.Hash);
if (from.Stacked)
{
if (item.Count == 0)
{
SelectedItem = currencyId == null ? moved : from.Items.Single(i => i.Id == currencyId);
}
}
else
{
SelectedItem = from.Items.LastOrDefault(i => i.Hash == item.Hash) ?? moved;
}
Refresh();
from.Refresh(SelectedItem);
to.Refresh(SelectedItem);
}
public void MoveItemSilent(Item item, ItemContainer from, ItemContainer to, int amount = 1)
{
if (item.Count <= 0) throw new ArgumentException("item.Count <= 0");
if (amount <= 0) throw new ArgumentException("amount <= 0");
if (item.Count < amount) throw new ArgumentException("item.Count < amount");
if (to.Stacked)
{
var targets = to.Items.Where(i => i.Hash == item.Hash).ToList();
switch (targets.Count)
{
case 0:
to.Items.Add(new Item(item.Id, item.Modifier, amount));
break;
case 1:
targets[0].Count += amount;
break;
default:
throw new Exception($"Unable to move item silently: {item.Id} ({item.Hash}).");
}
}
else
{
to.Items.Add(new Item(item.Id, item.Modifier, amount));
}
var moved = to.Items.Last(i => i.Hash == item.Hash);
if (from.Stacked)
{
item.Count -= amount;
if (item.Count == 0)
{
from.Items.Remove(item);
}
}
else
{
from.Items.Remove(item);
}
}
}
}

View File

@@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: 8bce2241fefb191448ef9c30f3ad750a
timeCreated: 1508495107
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 8bce2241fefb191448ef9c30f3ad750a
timeCreated: 1508495107
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,249 +1,249 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.Common.Scripts.Common;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Scrollable item container that can display item list. Automatic vertical scrolling.
/// </summary>
public class ScrollInventory : ItemContainer
{
[Tooltip("Sort items automatically using SortingFunc (can be redefined).")]
public bool AutoSorting;
[Tooltip("Add an extra empty row or a column at the end.")]
public bool Extend;
[Header("UI")]
public ScrollRect ScrollRect;
public GridLayoutGroup Grid;
public InventoryItem ItemPrefab;
public Func<Item, int> SortingFunc = item => TypePriority.IndexOf(item.Params.Type); // You can override this.
public Func<Item, bool> FilterFunc; // You can override this.
public Action OnRefresh;
#if TAP_HEROES
public TMPro.TextMeshProUGUI Gold;
#endif
private static readonly List<ItemType> TypePriority = new List<ItemType>
{
ItemType.Currency,
ItemType.Container,
ItemType.Booster,
ItemType.Supply,
ItemType.Weapon,
ItemType.Helmet,
ItemType.Armor,
ItemType.Vest,
ItemType.Bracers,
ItemType.Leggings,
ItemType.Shield,
ItemType.Fragment,
ItemType.Backpack,
ItemType.Jewelry,
ItemType.Loot,
ItemType.Recipe,
ItemType.Material
};
private readonly List<InventoryItem> _itemInstances = new List<InventoryItem>(); // Reusing instances to reduce Instantiate() calls.
public void Initialize(ref List<Item> items, Item selected, bool reset = false)
{
base.Initialize(ref items, selected);
}
public void Initialize(ref List<Item> items)
{
base.Initialize(ref items);
ResetNormalizedPosition();
}
public void SelectItem(Item item)
{
_itemInstances.FirstOrDefault(i => i.Item == item)?.Select(true);
}
public bool SelectAny()
{
var any = _itemInstances.FirstOrDefault(i => i.Item != null);
if (any == null) return false;
any.Select(true);
return true;
}
public void SetTypeFilter(string input)
{
var type = input.ToEnum<ItemType>();
SetTypeFilter(new List<ItemType> { type });
}
public void SetTypeFilter(List<ItemType> types)
{
FilterFunc = item => types.Contains(item.Params.Type);
Refresh(null);
}
public void UnsetFilter()
{
FilterFunc = null;
Refresh(null);
}
public override void Refresh(Item selected)
{
if (Items == null) return;
List<Item> items;
if (AutoSorting && SortingFunc != null)
{
items = new List<Item>();
var groups = Items.OrderBy(SortingFunc).ToList().GroupBy(i => i.Params.Type);
foreach (var group in groups)
{
items.AddRange(group.OrderBy(i => i.Params.Class).ThenBy(i => i.Params.Price));
}
}
else
{
items = Items.ToList();
}
if (FilterFunc != null)
{
items.RemoveAll(i => !FilterFunc(i));
}
foreach (var instance in _itemInstances)
{
instance.Reset();
instance.SetActive(false);
}
var toggleGroup = GetComponentInParent<ToggleGroup>(includeInactive: true);
for (var i = 0; i < items.Count; i++)
{
var instance = GetItemInstance();
instance.transform.SetSiblingIndex(i);
instance.Initialize(items[i], toggleGroup);
instance.Count.SetActive(Stacked);
if (AutoSelect) instance.Select(items[i] == selected);
}
var columns = 0;
var rows = 0;
switch (Grid.constraint)
{
case GridLayoutGroup.Constraint.FixedColumnCount:
{
var height = Mathf.FloorToInt((ScrollRect.GetComponent<RectTransform>().rect.height + Grid.spacing.y) / (Grid.cellSize.y + Grid.spacing.y));
columns = Grid.constraintCount;
rows = Mathf.Max(height, Mathf.FloorToInt((float) items.Count / columns));
if (Extend) rows++;
break;
}
case GridLayoutGroup.Constraint.FixedRowCount:
{
var width = Mathf.FloorToInt((ScrollRect.GetComponent<RectTransform>().rect.width + Grid.spacing.x) / (Grid.cellSize.x + Grid.spacing.x));
rows = Grid.constraintCount;
columns = Mathf.Max(width, Mathf.FloorToInt((float) items.Count / rows));
if (Extend) columns++;
break;
}
}
for (var i = items.Count; i < columns * rows; i++)
{
var instance = GetItemInstance();
instance.Initialize(null);
}
OnRefresh?.Invoke();
#if TAP_HEROES
var gold = Items.Where(i => i.Id == "Gold").Sum(i => i.Count);
Gold?.SetText($"{gold} <sprite=0>");
TapHeroes.Scripts.Interface.Elements.ItemComparer.Compare(_itemInstances);
#endif
}
private InventoryItem GetItemInstance()
{
var instance = _itemInstances.FirstOrDefault(i => !i.gameObject.activeSelf);
if (instance == null)
{
instance = Instantiate(ItemPrefab, Grid.transform);
_itemInstances.Add(instance);
}
else
{
instance.gameObject.SetActive(true);
}
return instance;
}
public InventoryItem FindItem(Item item)
{
return _itemInstances.SingleOrDefault(i => i.gameObject.activeSelf && i.Item != null && i.Item.Hash == item.Hash);
}
public InventoryItem FindItem(string itemId)
{
return _itemInstances.SingleOrDefault(i => i.gameObject.activeSelf && i.Item != null && i.Item.Id == itemId);
}
public void ResetNormalizedPosition()
{
if (ScrollRect.horizontal) ScrollRect.horizontalNormalizedPosition = 0;
if (ScrollRect.vertical) ScrollRect.verticalNormalizedPosition = 1;
}
public IEnumerator SnapTo(RectTransform target, bool horizontal = true, bool vertical = true)
{
yield return null;
Canvas.ForceUpdateCanvases();
var pos = (Vector2) ScrollRect.transform.InverseTransformPoint(ScrollRect.content.position) - (Vector2) ScrollRect.transform.InverseTransformPoint(target.position);
if (!horizontal) pos.x = ScrollRect.content.anchoredPosition.x;
if (!vertical) pos.y = ScrollRect.content.anchoredPosition.y;
ScrollRect.content.anchoredPosition = pos;
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Assets.HeroEditor4D.Common.Scripts.Common;
using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
/// <summary>
/// Scrollable item container that can display item list. Automatic vertical scrolling.
/// </summary>
public class ScrollInventory : ItemContainer
{
[Tooltip("Sort items automatically using SortingFunc (can be redefined).")]
public bool AutoSorting;
[Tooltip("Add an extra empty row or a column at the end.")]
public bool Extend;
[Header("UI")]
public ScrollRect ScrollRect;
public GridLayoutGroup Grid;
public InventoryItem ItemPrefab;
public Func<Item, int> SortingFunc = item => TypePriority.IndexOf(item.Params.Type); // You can override this.
public Func<Item, bool> FilterFunc; // You can override this.
public Action OnRefresh;
#if TAP_HEROES
public TMPro.TextMeshProUGUI Gold;
#endif
private static readonly List<ItemType> TypePriority = new List<ItemType>
{
ItemType.Currency,
ItemType.Container,
ItemType.Booster,
ItemType.Supply,
ItemType.Weapon,
ItemType.Helmet,
ItemType.Armor,
ItemType.Vest,
ItemType.Bracers,
ItemType.Leggings,
ItemType.Shield,
ItemType.Fragment,
ItemType.Backpack,
ItemType.Jewelry,
ItemType.Loot,
ItemType.Recipe,
ItemType.Material
};
private readonly List<InventoryItem> _itemInstances = new List<InventoryItem>(); // Reusing instances to reduce Instantiate() calls.
public void Initialize(ref List<Item> items, Item selected, bool reset = false)
{
base.Initialize(ref items, selected);
}
public void Initialize(ref List<Item> items)
{
base.Initialize(ref items);
ResetNormalizedPosition();
}
public void SelectItem(Item item)
{
_itemInstances.FirstOrDefault(i => i.Item == item)?.Select(true);
}
public bool SelectAny()
{
var any = _itemInstances.FirstOrDefault(i => i.Item != null);
if (any == null) return false;
any.Select(true);
return true;
}
public void SetTypeFilter(string input)
{
var type = input.ToEnum<ItemType>();
SetTypeFilter(new List<ItemType> { type });
}
public void SetTypeFilter(List<ItemType> types)
{
FilterFunc = item => types.Contains(item.Params.Type);
Refresh(null);
}
public void UnsetFilter()
{
FilterFunc = null;
Refresh(null);
}
public override void Refresh(Item selected)
{
if (Items == null) return;
List<Item> items;
if (AutoSorting && SortingFunc != null)
{
items = new List<Item>();
var groups = Items.OrderBy(SortingFunc).ToList().GroupBy(i => i.Params.Type);
foreach (var group in groups)
{
items.AddRange(group.OrderBy(i => i.Params.Class).ThenBy(i => i.Params.Price));
}
}
else
{
items = Items.ToList();
}
if (FilterFunc != null)
{
items.RemoveAll(i => !FilterFunc(i));
}
foreach (var instance in _itemInstances)
{
instance.Reset();
instance.SetActive(false);
}
var toggleGroup = GetComponentInParent<ToggleGroup>(includeInactive: true);
for (var i = 0; i < items.Count; i++)
{
var instance = GetItemInstance();
instance.transform.SetSiblingIndex(i);
instance.Initialize(items[i], toggleGroup);
instance.Count.SetActive(Stacked);
if (AutoSelect) instance.Select(items[i] == selected);
}
var columns = 0;
var rows = 0;
switch (Grid.constraint)
{
case GridLayoutGroup.Constraint.FixedColumnCount:
{
var height = Mathf.FloorToInt((ScrollRect.GetComponent<RectTransform>().rect.height + Grid.spacing.y) / (Grid.cellSize.y + Grid.spacing.y));
columns = Grid.constraintCount;
rows = Mathf.Max(height, Mathf.FloorToInt((float) items.Count / columns));
if (Extend) rows++;
break;
}
case GridLayoutGroup.Constraint.FixedRowCount:
{
var width = Mathf.FloorToInt((ScrollRect.GetComponent<RectTransform>().rect.width + Grid.spacing.x) / (Grid.cellSize.x + Grid.spacing.x));
rows = Grid.constraintCount;
columns = Mathf.Max(width, Mathf.FloorToInt((float) items.Count / rows));
if (Extend) columns++;
break;
}
}
for (var i = items.Count; i < columns * rows; i++)
{
var instance = GetItemInstance();
instance.Initialize(null);
}
OnRefresh?.Invoke();
#if TAP_HEROES
var gold = Items.Where(i => i.Id == "Gold").Sum(i => i.Count);
Gold?.SetText($"{gold} <sprite=0>");
TapHeroes.Scripts.Interface.Elements.ItemComparer.Compare(_itemInstances);
#endif
}
private InventoryItem GetItemInstance()
{
var instance = _itemInstances.FirstOrDefault(i => !i.gameObject.activeSelf);
if (instance == null)
{
instance = Instantiate(ItemPrefab, Grid.transform);
_itemInstances.Add(instance);
}
else
{
instance.gameObject.SetActive(true);
}
return instance;
}
public InventoryItem FindItem(Item item)
{
return _itemInstances.SingleOrDefault(i => i.gameObject.activeSelf && i.Item != null && i.Item.Hash == item.Hash);
}
public InventoryItem FindItem(string itemId)
{
return _itemInstances.SingleOrDefault(i => i.gameObject.activeSelf && i.Item != null && i.Item.Id == itemId);
}
public void ResetNormalizedPosition()
{
if (ScrollRect.horizontal) ScrollRect.horizontalNormalizedPosition = 0;
if (ScrollRect.vertical) ScrollRect.verticalNormalizedPosition = 1;
}
public IEnumerator SnapTo(RectTransform target, bool horizontal = true, bool vertical = true)
{
yield return null;
Canvas.ForceUpdateCanvases();
var pos = (Vector2) ScrollRect.transform.InverseTransformPoint(ScrollRect.content.position) - (Vector2) ScrollRect.transform.InverseTransformPoint(target.position);
if (!horizontal) pos.x = ScrollRect.content.anchoredPosition.x;
if (!vertical) pos.y = ScrollRect.content.anchoredPosition.y;
ScrollRect.content.anchoredPosition = pos;
}
}
}

View File

@@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: b1b2694827ea72749bfafba0579e6b8e
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b1b2694827ea72749bfafba0579e6b8e
timeCreated: 1508494765
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,28 +1,28 @@
using System.Collections.Generic;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
public class ScrollInventoryFilter : MonoBehaviour
{
public ScrollInventory ScrollInventory;
public Toggle Weapon;
public Toggle Armor;
public Toggle Helmet;
public Toggle Shield;
public void OnSelect(bool value)
{
var types = new List<ItemType>();
if (Weapon.isOn) types.Add(ItemType.Weapon);
if (Armor.isOn) types.Add(ItemType.Armor);
if (Helmet.isOn) types.Add(ItemType.Helmet);
if (Shield.isOn) types.Add(ItemType.Shield);
ScrollInventory.SetTypeFilter(types);
}
}
using System.Collections.Generic;
using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
{
public class ScrollInventoryFilter : MonoBehaviour
{
public ScrollInventory ScrollInventory;
public Toggle Weapon;
public Toggle Armor;
public Toggle Helmet;
public Toggle Shield;
public void OnSelect(bool value)
{
var types = new List<ItemType>();
if (Weapon.isOn) types.Add(ItemType.Weapon);
if (Armor.isOn) types.Add(ItemType.Armor);
if (Helmet.isOn) types.Add(ItemType.Helmet);
if (Shield.isOn) types.Add(ItemType.Shield);
ScrollInventory.SetTypeFilter(types);
}
}
}

View File

@@ -1,11 +1,11 @@
fileFormatVersion: 2
guid: 4b21edc9891e9b243b69701a0b5656e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4b21edc9891e9b243b69701a0b5656e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: