93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class PayController : MonoBehaviour
|
|
{
|
|
private Queue<TycoonNpc> npcQueue = new (100);
|
|
private Transform payLinePoint;
|
|
public List<GameObject> coinParticle = new(5);
|
|
private float spaceBetweenNpcs; // NPC 간의 간격
|
|
|
|
private void Awake()
|
|
{
|
|
payLinePoint = transform.Find("PayLinePoint");
|
|
spaceBetweenNpcs = 0.5f;
|
|
}
|
|
|
|
public void AddNpcToQueue(TycoonNpc npc)
|
|
{
|
|
npcQueue.Enqueue(npc);
|
|
}
|
|
|
|
public bool IsNpcNext(TycoonNpc npc)
|
|
{
|
|
return npcQueue.Peek() == npc;
|
|
}
|
|
|
|
public void RemoveNpcFromQueue(TycoonNpc npc)
|
|
{
|
|
if (npcQueue.Count > 0)
|
|
{
|
|
npcQueue.Dequeue();
|
|
}
|
|
}
|
|
|
|
// public bool IsNpcNext(TycoonNpc npc)
|
|
// {
|
|
// return npcQueue.Peek() == npc;
|
|
// }
|
|
|
|
public Vector3 GetNextPositionInLine(TycoonNpc npc)
|
|
{
|
|
var indexInLine = Array.IndexOf(npcQueue.ToArray(), npc);
|
|
if (indexInLine == -1) return payLinePoint.position; // NPC가 줄에 없으면 기본 위치로
|
|
|
|
var lineStartPoint = payLinePoint.position;
|
|
var positionInLine = lineStartPoint - new Vector3(0, 0, spaceBetweenNpcs * indexInLine);
|
|
return positionInLine;
|
|
}
|
|
|
|
// 유저 상호작용 처리
|
|
public void Interact()
|
|
{
|
|
if (npcQueue.Count > 0)
|
|
{
|
|
var currentNpc = npcQueue.Dequeue();
|
|
// 결제 처리
|
|
ProcessPaymentForNpc(currentNpc);
|
|
// NPC 상태 변경
|
|
currentNpc.StateMachine.ChangeState(new WalkOutSate(currentNpc)); // 다음 상태로 변경
|
|
}
|
|
}
|
|
|
|
private void ProcessPaymentForNpc(TycoonNpc npc)
|
|
{
|
|
var gold = Random.Range(100, 300);
|
|
DataManager.Inst.Gold += gold;
|
|
npc.PayText.text = "$ " + gold;
|
|
npc.PayTextObj.SetActive(true);
|
|
|
|
foreach (var coin in coinParticle)
|
|
{
|
|
if (!coin.activeInHierarchy)
|
|
{
|
|
coin.SetActive(true);
|
|
StartCoroutine(DeactivateCoinParticle(coin));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator DeactivateCoinParticle(GameObject coin)
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
coin.SetActive(false);
|
|
}
|
|
}
|
|
} |