+ 물고기를 잡으면 드랍 가능한 형태의 오브젝트와 아이콘이 생성되게 변경되었습니다. + 플레이어(배)와 아이콘의 위치가 가까워지면 플레이어는 아이콘을 흡수하면서 아이템을 얻게됩니다. + 아이템 획득 시에 효과음을 추가하였습니다. + 아이템 획득 시에 좌측 중단에 UI를 통해서 어떠한 아이템을 얻었는지 확인할 수 있게 표시합니다. + 물고기 스팟 이펙트를 2가지 합치는 방식으로 변경하였습니다. + 물고기 스팟을 기준으로 플레이어와의 거리를 체크해 물고기 스팟이 도망치는 방식으로 변경되었습니다. (기존에는 Bound의 중심) + 물고기 스팟의 크기를 원하는 크기로 변경할 수 있도록 변경했습니다. + 인터페이스 IItem을 추가하였습니다. + Item,FishItem 로직을 변경했습니다.
114 lines
3.6 KiB
C#
114 lines
3.6 KiB
C#
using System.Collections;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class ItemController : MonoBehaviour
|
|
{
|
|
[Title("아이템")]
|
|
[SerializeField] private Item item;
|
|
[SerializeField] private ItemUiController itemUiPrefab;
|
|
|
|
[Title("자동 파괴")]
|
|
[SerializeField] private bool useAutoDestroy = true;
|
|
[ShowIf("@useAutoDestroy")]
|
|
[SerializeField] private float autoDestroyTime = 30f;
|
|
|
|
[Title("획득")]
|
|
[SerializeField] private bool drawGizmos = true;
|
|
[SerializeField] private float radius = 5f;
|
|
[SerializeField] private float acquisitionTime = 1f;
|
|
[SerializeField] private LayerMask targetLayer;
|
|
|
|
private Collider[] hitColliders = new Collider[1];
|
|
private Collider targetCollider;
|
|
private WaitForSeconds lootCoroutineTime = new(0.5f);
|
|
private AudioSource audioSource;
|
|
private Transform itemsLoot;
|
|
private ItemUiController itemLootUi;
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
if (!drawGizmos) return;
|
|
|
|
Gizmos.DrawWireSphere(transform.position, radius);
|
|
}
|
|
|
|
public void Init(Item newItem)
|
|
{
|
|
item = newItem;
|
|
|
|
if (!itemsLoot)
|
|
{
|
|
itemsLoot = UiManager.Inst.OceanUi.MainCanvas.transform.Find("ItemsLoot");
|
|
}
|
|
|
|
var myPos = transform.position;
|
|
var screenPos = CameraManager.Inst.MainCam.WorldToScreenPoint(myPos);
|
|
itemLootUi = Instantiate(itemUiPrefab, screenPos, Quaternion.identity, itemsLoot);
|
|
itemLootUi.Init(transform);
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
audioSource = transform.parent.Find("Audio").GetComponent<AudioSource>();
|
|
itemsLoot = UiManager.Inst.OceanUi.MainCanvas.transform.Find("ItemsLoot");
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (useAutoDestroy)
|
|
{
|
|
Destroy(transform.parent.gameObject, autoDestroyTime);
|
|
Destroy(itemLootUi.gameObject, autoDestroyTime);
|
|
}
|
|
|
|
StartCoroutine(LootCoroutine());
|
|
}
|
|
|
|
private IEnumerator LootCoroutine()
|
|
{
|
|
while (true)
|
|
{
|
|
var maxSize = Physics.OverlapSphereNonAlloc(transform.position, radius, hitColliders, targetLayer);
|
|
if (maxSize > 0)
|
|
{
|
|
targetCollider = hitColliders[0];
|
|
itemLootUi.ItemAcquisition();
|
|
break;
|
|
}
|
|
|
|
yield return lootCoroutineTime;
|
|
}
|
|
|
|
var startPosition = transform.position;
|
|
var elapsedTime = 0f;
|
|
|
|
while (elapsedTime < acquisitionTime)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
var t = elapsedTime / acquisitionTime;
|
|
t = Mathf.SmoothStep(0f, 1f, t);
|
|
|
|
transform.position = Vector3.Lerp(startPosition, targetCollider.transform.position, t);
|
|
yield return null;
|
|
}
|
|
|
|
item.Acquire();
|
|
itemLootUi.gameObject.SetActive(false);
|
|
UiManager.Inst.OceanUi.DropItemGroupController.ShowDropItemInfoUi(item);
|
|
|
|
if (audioSource && audioSource.resource)
|
|
{
|
|
audioSource.Play();
|
|
}
|
|
|
|
yield return new WaitForSeconds(audioSource.clip.length);
|
|
|
|
Destroy(transform.parent.gameObject);
|
|
Destroy(itemLootUi.gameObject);
|
|
}
|
|
}
|
|
} |