projectEli/Assets/Inventory System/ICWM Assets/Inventory/Scripts/Loot/LootBase.cs

115 lines
3.5 KiB
C#

//********************************************************//
// //
// Copyright © All rights reserved. MyNameIsVoo. 2020. //
// //
// COPYING FORBIDEN //
// //
//********************************************************//
using UnityEngine;
/// <summary>
/// Keeps in itself all the things that can appear in a box with a loot
/// </summary>
namespace ICWM
{
namespace Loot
{
public class LootBase : MonoBehaviour
{
public enum LootIcon
{
PERCENT,
ARROW
}
[Header("Attributes")]
[SerializeField] private GameObject[] lootGridSprites;
[SerializeField] private LootIcon lootIcon = LootIcon.ARROW;
[SerializeField] private GameObject lootArrowIconPrefab; // for seaching imitation - Arrow
[SerializeField] private GameObject lootPercentIconPrefab; // for seaching imitation - Percent
[Header("All loot that the player can find in the lootbox")]
[SerializeField] private GameObject[] lootItems = new GameObject[1];
[HideInInspector] public bool isActiveLoot;
[HideInInspector] public bool isLootWindow = false;
[HideInInspector] public bool isLootWindowMode = false;
private float deltaTime = 0f;
public static LootBase instance;
private void Start()
{
instance = this;
}
#region PUBLIC
#region Set, Get, etc ...
public GameObject GetNewLootIcon(Transform rootSpawn)
{
if (lootIcon == LootIcon.ARROW)
return Instantiate(lootArrowIconPrefab, rootSpawn);
else //if (lootIcon == LootIcon.PERCENT)
return Instantiate(lootPercentIconPrefab, rootSpawn);
}
public GameObject GetNewLootGridSprite(Transform rootSpawn, int indexGrid)
{
if (indexGrid < 0 || indexGrid > lootGridSprites.Length || lootGridSprites[indexGrid] == null)
return null;
return Instantiate(lootGridSprites[indexGrid], rootSpawn);
}
public int GetLootItemsLenght()
{
return lootItems != null ? lootItems.Length : 0;
}
public GameObject GetNewItem(Transform rootSpawn, int indexItem)
{
if (indexItem < 0 || lootItems == null || indexItem > lootItems.Length || lootItems[indexItem] == null)
return null;
return (GameObject)Instantiate(LootBase.instance.lootItems[indexItem], rootSpawn);
}
public float GetDeltaTimeLootSearching()
{
return deltaTime;
}
#endregion
#region Helper
public void IncrementDeltaTime()
{
deltaTime += Time.deltaTime;
}
#endregion
#region Close, Reset, Destroy, ...
public void CloseLoot()
{
isLootWindow = false;
isActiveLoot = false;
}
public void ResetDeltaTimeLootSearching()
{
deltaTime = 0f;
}
#endregion
#endregion
}
}
}