2022-11-15 22:58:54 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace SimpleInventorySystem
|
|
|
|
|
{
|
|
|
|
|
[RequireComponent(typeof(Collider), typeof(Inventory))]
|
|
|
|
|
public class Player_IS : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
//public bool CanPickupItem { get; private set; }
|
|
|
|
|
//public PickUp storedPickUp;
|
|
|
|
|
public List<PickUp> pickUpsInRange = new List<PickUp>();
|
|
|
|
|
[HideInInspector] public Inventory inventory;
|
2023-01-25 07:14:16 +00:00
|
|
|
|
public TargetAttachment[] targetAttachments;
|
|
|
|
|
[HideInInspector] public PickUp SPU;
|
2022-11-15 22:58:54 +00:00
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2023-01-15 11:39:47 +00:00
|
|
|
|
inventory = GetComponent<Inventory>();
|
2022-11-15 22:58:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AttachItemGameObject(GameObject go, ItemTags itemTag, ItemUI itemUI)
|
|
|
|
|
{
|
|
|
|
|
foreach (TargetAttachment ta in targetAttachments)
|
|
|
|
|
{
|
|
|
|
|
if(ta != null && ta.AttachItemGameObject(go, itemTag, itemUI.pickUp))
|
|
|
|
|
{
|
|
|
|
|
itemUI.targetAttachment = ta;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-31 02:12:08 +00:00
|
|
|
|
//Debug.Log("FAIL");
|
2022-11-15 22:58:54 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DetachItemGameObject(GameObject go, ItemUI itemUI)
|
|
|
|
|
{
|
2023-01-30 02:35:04 +00:00
|
|
|
|
if(itemUI.targetAttachment != null)
|
|
|
|
|
{
|
|
|
|
|
itemUI.targetAttachment.DetachItemGameObject(go);
|
|
|
|
|
}
|
2022-11-15 22:58:54 +00:00
|
|
|
|
itemUI.pickUp.DropDownHandler();
|
|
|
|
|
itemUI.targetAttachment = null;
|
|
|
|
|
itemUI.gameObject.transform.SetParent(go.transform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HandlePickup(PickUp storedPickUp)
|
|
|
|
|
{
|
2022-12-23 03:50:16 +00:00
|
|
|
|
SPU = storedPickUp;
|
2023-01-15 11:39:47 +00:00
|
|
|
|
//Debug.Log("Handling Pickup");
|
2022-12-23 03:50:16 +00:00
|
|
|
|
if (storedPickUp != null && pickUpsInRange.Contains(storedPickUp))
|
2022-11-15 22:58:54 +00:00
|
|
|
|
{
|
2023-01-15 11:39:47 +00:00
|
|
|
|
//Debug.Log("Picking up" + storedPickUp.name);
|
2022-11-15 22:58:54 +00:00
|
|
|
|
storedPickUp.PickUpHandler();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
|
{
|
|
|
|
|
PickUpRange pickUpRange = other.GetComponent<PickUpRange>();
|
|
|
|
|
if (pickUpRange != null && !pickUpsInRange.Contains(pickUpRange.pickUp))
|
|
|
|
|
{
|
2023-01-31 02:12:08 +00:00
|
|
|
|
//Debug.Log("Collided");
|
2022-11-15 22:58:54 +00:00
|
|
|
|
pickUpsInRange.Add(pickUpRange.pickUp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
|
|
|
{
|
|
|
|
|
PickUpRange pickUpRange = other.GetComponent<PickUpRange>();
|
|
|
|
|
if (pickUpRange != null)
|
|
|
|
|
{
|
|
|
|
|
//CanPickupItem = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
|
|
|
{
|
|
|
|
|
PickUpRange pickUpRange = other.GetComponent<PickUpRange>();
|
|
|
|
|
if (pickUpRange != null && pickUpsInRange.Contains(pickUpRange.pickUp))
|
|
|
|
|
{
|
|
|
|
|
//CanPickupItem = false;
|
|
|
|
|
|
|
|
|
|
pickUpsInRange.Remove(pickUpRange.pickUp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|