163 lines
5.9 KiB
C#
163 lines
5.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using PixelCrushers.DialogueSystem;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class KitchenController : MonoBehaviour
|
|
{
|
|
private bool isFoodInSot;
|
|
private bool isCooking;
|
|
public Image cookingProcess;
|
|
public GameObject sotUp;
|
|
private Vector3 sotUpOriginal = new Vector3(4.17999983f, 8.80000019f, 16.5300007f);
|
|
private Vector3 sotUpClose = new Vector3(4.17999983f, 7.05000019f, 14.7799997f);
|
|
public GameObject[] sotSteamEff;
|
|
private Dictionary<GlobalValue.FoodOnHand, int> ingredientsInPot = new();
|
|
private Dictionary<GlobalValue.FoodOnHand, int> kingCrabRecipe = new()
|
|
{
|
|
{ GlobalValue.FoodOnHand.ONION, 1 },
|
|
{ GlobalValue.FoodOnHand.SCALLION, 1 },
|
|
{ GlobalValue.FoodOnHand.TOMATO, 1 }
|
|
};
|
|
|
|
private short maxFood = 20;
|
|
|
|
public void AddIngredient()
|
|
{
|
|
var player = GameManager.Inst.TycoonPlayer;
|
|
if (player.FoodTransform.gameObject.activeSelf)
|
|
{
|
|
var ingredient = player.FoodOnHand;
|
|
if (!ingredientsInPot.ContainsKey(ingredient))
|
|
ingredientsInPot[ingredient] = 0;
|
|
|
|
ingredientsInPot[ingredient]++;
|
|
player.FoodTransform.gameObject.SetActive(false);
|
|
player.FoodOnHand = GlobalValue.FoodOnHand.NONE;
|
|
}
|
|
else if (isFoodInSot)
|
|
{
|
|
player.FoodVisual.sprite = DataManager.Inst.kingCrabMeat;
|
|
player.FoodTransform.gameObject.SetActive(true);
|
|
player.FoodOnHand = GlobalValue.FoodOnHand.KING_CRAB;
|
|
cookingProcess.fillAmount = 0;
|
|
maxFood--;
|
|
if (maxFood <= 0) isFoodInSot = false;
|
|
}
|
|
}
|
|
|
|
public bool CheckRecipe(Dictionary<GlobalValue.FoodOnHand, int> recipe)
|
|
{
|
|
foreach (var ingredient in recipe)
|
|
{
|
|
if (!ingredientsInPot.ContainsKey(ingredient.Key) || ingredientsInPot[ingredient.Key] != ingredient.Value)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void Cook()
|
|
{
|
|
if (CheckRecipe(kingCrabRecipe))
|
|
{
|
|
ingredientsInPot.Clear();
|
|
StartCoroutine(CookingProcess());
|
|
}
|
|
}
|
|
|
|
private IEnumerator CookingProcess()
|
|
{
|
|
isCooking = true;
|
|
float duration = 3.0f; // 조리 시간 3초
|
|
float elapsed = 0; // 경과 시간
|
|
bool steamEffectActivated = false;
|
|
|
|
// 조리 시작 시 sotUp 이미지를 sotUpClose로 이동
|
|
while (elapsed < 0.5f)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
sotUp.transform.position = Vector3.Lerp(sotUpOriginal, sotUpClose, elapsed / 0.5f);
|
|
yield return null;
|
|
}
|
|
|
|
// 중간 조리 과정
|
|
while (elapsed < duration - 0.5f)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
cookingProcess.fillAmount = Mathf.Clamp01((elapsed - 0.5f) / (duration - 1f));
|
|
yield return null;
|
|
}
|
|
|
|
// 조리 종료 0.5초 전에 sotUpOriginal 위치로 되돌리기 시작
|
|
float closeToOriginalTime = 0; // sotUpClose에서 sotUpOriginal로 이동하는 데 걸리는 시간
|
|
while (closeToOriginalTime < 0.5f)
|
|
{
|
|
closeToOriginalTime += Time.deltaTime;
|
|
sotUp.transform.position = Vector3.Lerp(sotUpClose, sotUpOriginal, closeToOriginalTime / 0.5f);
|
|
if (closeToOriginalTime < 0.25f)
|
|
{
|
|
foreach (var steamEffect in sotSteamEff)
|
|
{
|
|
steamEffect.SetActive(true);
|
|
}
|
|
}
|
|
yield return null;
|
|
}
|
|
|
|
// 조리 완료 후 처리
|
|
StartCoroutine(SotUpEffOff());
|
|
isCooking = false;
|
|
isFoodInSot = true;
|
|
}
|
|
|
|
private IEnumerator SotUpEffOff()
|
|
{
|
|
yield return new WaitForSeconds(2f);
|
|
foreach (var steamEffect in sotSteamEff)
|
|
{
|
|
steamEffect.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void ScallionBox()
|
|
{
|
|
var player = GameManager.Inst.TycoonPlayer;
|
|
if (player.FoodTransform.gameObject.activeSelf) return;
|
|
player.FoodVisual.sprite = DataManager.Inst.scallion;
|
|
player.FoodTransform.gameObject.SetActive(true);
|
|
player.FoodOnHand = GlobalValue.FoodOnHand.SCALLION;
|
|
}
|
|
|
|
public void OnionBox()
|
|
{
|
|
var player = GameManager.Inst.TycoonPlayer;
|
|
if (player.FoodTransform.gameObject.activeSelf) return;
|
|
player.FoodVisual.sprite = DataManager.Inst.onion;
|
|
player.FoodTransform.gameObject.SetActive(true);
|
|
player.FoodOnHand = GlobalValue.FoodOnHand.ONION;
|
|
}
|
|
|
|
public void TomatoBox()
|
|
{
|
|
var player = GameManager.Inst.TycoonPlayer;
|
|
if (player.FoodTransform.gameObject.activeSelf) return;
|
|
player.FoodVisual.sprite = DataManager.Inst.tomato;
|
|
player.FoodTransform.gameObject.SetActive(true);
|
|
player.FoodOnHand = GlobalValue.FoodOnHand.TOMATO;
|
|
}
|
|
|
|
public void KingCrab()
|
|
{
|
|
var player = GameManager.Inst.TycoonPlayer;
|
|
if (player.FoodTransform.gameObject.activeSelf) return;
|
|
player.FoodVisual.sprite = DataManager.Inst.kingCrabMeat;
|
|
player.FoodTransform.gameObject.SetActive(true);
|
|
player.FoodOnHand = GlobalValue.FoodOnHand.KING_CRAB;
|
|
}
|
|
}
|
|
} |