evershade/Assets/Data/ScriptableObjects/World/Interactable.cs

47 lines
1.2 KiB
C#

using System.Linq;
using UnityEngine;
using UnityEngine.Serialization;
public abstract class Interactable : ScriptableObject
{
public enum InteractableType
{
Crop,
Tree,
Rock,
Box,
Door,
Npc,
Sign
}
public int id;
public string objectName;
[FormerlySerializedAs("icon")] public Sprite display;
public InteractableType type;
//default interact range
public float interactRange = 1.5f;
public ToolItem.ToolType[] validToolTypes;
public abstract void OnEnter2D(Collider2D collider);
public abstract void OnExit2D(Collider2D collider);
public abstract void OnInteract();
public bool IsPlayerInInteractRange(Vector2 playerPosition, Vector2 itemPosition)
{
return Vector2.Distance(playerPosition, itemPosition) < interactRange;
}
public bool IsToolRequired()
{
// if there are not valid tools
if (validToolTypes == null || validToolTypes.Length == 0)
return false;
// also if one of the valid tool types is none then we dont need a tool
return !validToolTypes.Contains(ToolItem.ToolType.None);
}
public abstract void Interact();
}