2024-12-19 14:27:01 +00:00
|
|
|
using System;
|
2024-11-11 02:02:24 +00:00
|
|
|
using System.Collections;
|
2024-07-02 18:27:56 +00:00
|
|
|
using BlueWater.Interfaces;
|
2024-07-08 20:06:22 +00:00
|
|
|
using BlueWater.Players.Tycoons;
|
2024-09-26 11:50:39 +00:00
|
|
|
using BlueWater.Uis;
|
2024-07-02 18:27:56 +00:00
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
2024-11-11 02:02:24 +00:00
|
|
|
using UnityEngine.Localization.Components;
|
2024-07-02 18:27:56 +00:00
|
|
|
|
|
|
|
namespace BlueWater.Tycoons
|
|
|
|
{
|
|
|
|
public abstract class InteractionFurniture : MonoBehaviour, IPlayerInteraction
|
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
[BoxGroup("컴포넌트")]
|
|
|
|
[field: SerializeField, BoxGroup("컴포넌트")]
|
|
|
|
public Transform CenterTransform { get; private set; }
|
2024-07-02 18:27:56 +00:00
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
[field: SerializeField, BoxGroup("컴포넌트")]
|
|
|
|
public SpriteRenderer VisualLook { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField, BoxGroup("컴포넌트")]
|
2024-09-26 11:50:39 +00:00
|
|
|
public InteractionCanvas InteractionCanvas { get; private set; }
|
2024-07-02 18:27:56 +00:00
|
|
|
|
2024-11-11 12:23:27 +00:00
|
|
|
[field: SerializeField, BoxGroup("컴포넌트")]
|
2024-07-20 11:32:54 +00:00
|
|
|
public Material OutlineMaterial { get; private set; }
|
|
|
|
|
2024-11-11 02:02:24 +00:00
|
|
|
[field: SerializeField, BoxGroup("컴포넌트")]
|
|
|
|
public LocalizeStringEvent LocalizeStringEvent { get; protected set; }
|
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
[BoxGroup("변수")]
|
|
|
|
[field: SerializeField, BoxGroup("변수")]
|
2024-07-02 18:27:56 +00:00
|
|
|
public bool EnableInteraction { get; private set; } = true;
|
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
[field: SerializeField, BoxGroup("변수")]
|
2024-07-16 16:05:53 +00:00
|
|
|
public float InteractionRadius { get; private set; } = 2f;
|
2024-09-24 10:35:49 +00:00
|
|
|
|
|
|
|
[field: SerializeField, BoxGroup("변수")]
|
2024-11-11 02:02:24 +00:00
|
|
|
public string InteractionMessage { get; set; }
|
2024-09-24 10:35:49 +00:00
|
|
|
|
2024-07-22 00:42:29 +00:00
|
|
|
[Title("실시간 데이터")]
|
|
|
|
[SerializeField]
|
|
|
|
protected bool IsOpened;
|
2024-07-16 16:05:53 +00:00
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
protected TycoonPlayer CurrentTycoonPlayer;
|
2024-10-27 09:44:22 +00:00
|
|
|
protected Material OriginalMaterial;
|
2024-07-20 11:32:54 +00:00
|
|
|
protected bool IsQuitting;
|
2024-10-24 08:05:32 +00:00
|
|
|
protected bool IsShowing;
|
2024-10-27 09:44:22 +00:00
|
|
|
protected float HoldingElapsedTime;
|
2024-07-02 18:27:56 +00:00
|
|
|
|
2024-07-16 16:05:53 +00:00
|
|
|
private void OnDrawGizmosSelected()
|
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
if (!CenterTransform) return;
|
|
|
|
|
2024-07-16 16:05:53 +00:00
|
|
|
Gizmos.color = Color.blue;
|
2024-07-20 11:32:54 +00:00
|
|
|
Gizmos.DrawWireSphere(CenterTransform.position, InteractionRadius);
|
2024-07-16 16:05:53 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 18:27:56 +00:00
|
|
|
protected virtual void Awake()
|
|
|
|
{
|
|
|
|
InitializeComponents();
|
2024-11-11 12:23:27 +00:00
|
|
|
|
|
|
|
if (VisualLook)
|
|
|
|
{
|
|
|
|
OriginalMaterial = VisualLook.material;
|
|
|
|
}
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
protected virtual void OnEnable()
|
2024-07-02 18:27:56 +00:00
|
|
|
{
|
2024-09-30 09:41:55 +00:00
|
|
|
EventManager.OnTycoonGameStarted += OpenTycoonSwitch;
|
|
|
|
EventManager.OnTycoonGameOvered += ClosedTycoonSwitch;
|
2024-07-22 00:42:29 +00:00
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
RegisterPlayerInteraction();
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
2024-10-27 09:44:22 +00:00
|
|
|
|
|
|
|
protected virtual void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2024-07-02 18:27:56 +00:00
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
protected virtual void OnDisable()
|
2024-07-02 18:27:56 +00:00
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
if (IsQuitting) return;
|
2024-07-02 18:27:56 +00:00
|
|
|
|
2024-09-30 09:41:55 +00:00
|
|
|
EventManager.OnTycoonGameStarted -= OpenTycoonSwitch;
|
|
|
|
EventManager.OnTycoonGameOvered -= ClosedTycoonSwitch;
|
2024-07-22 00:42:29 +00:00
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
UnregisterPlayerInteraction();
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
2024-12-19 14:27:01 +00:00
|
|
|
|
|
|
|
protected virtual void OnDestroy()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-07-22 00:42:29 +00:00
|
|
|
private void OnApplicationQuit()
|
|
|
|
{
|
|
|
|
IsQuitting = true;
|
|
|
|
}
|
2024-07-02 18:27:56 +00:00
|
|
|
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
|
|
protected virtual void InitializeComponents()
|
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
if (!CenterTransform)
|
|
|
|
{
|
|
|
|
CenterTransform = transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualLook = transform.Find("VisualLook").GetComponent<SpriteRenderer>();
|
2024-11-11 02:02:24 +00:00
|
|
|
InteractionCanvas = transform.Find("InteractionCanvas").GetComponent<InteractionCanvas>();
|
|
|
|
LocalizeStringEvent = transform.GetComponent<LocalizeStringEvent>();
|
2024-07-08 20:06:22 +00:00
|
|
|
|
|
|
|
CurrentTycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void Interaction();
|
2024-09-09 12:27:15 +00:00
|
|
|
|
|
|
|
public virtual void CancelInteraction() { }
|
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
public virtual bool CanInteraction() => true;
|
2024-07-02 18:27:56 +00:00
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
public virtual void ShowInteractionUi()
|
2024-07-02 18:27:56 +00:00
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
VisualLook.material = OutlineMaterial;
|
2024-10-10 09:32:18 +00:00
|
|
|
EventManager.InvokeShowInteractionUi(InteractionMessage);
|
2024-10-27 09:44:22 +00:00
|
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
2024-10-24 08:05:32 +00:00
|
|
|
IsShowing = true;
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
|
|
|
|
2024-07-08 20:06:22 +00:00
|
|
|
public virtual void HideInteractionUi()
|
2024-07-02 18:27:56 +00:00
|
|
|
{
|
2024-10-06 23:41:09 +00:00
|
|
|
if (VisualLook)
|
|
|
|
{
|
|
|
|
VisualLook.material = OriginalMaterial;
|
|
|
|
}
|
2024-10-10 09:32:18 +00:00
|
|
|
EventManager.InvokeHideInteractionUi();
|
2024-10-24 08:05:32 +00:00
|
|
|
IsShowing = false;
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
2024-07-08 20:06:22 +00:00
|
|
|
|
|
|
|
protected void RegisterPlayerInteraction()
|
|
|
|
{
|
|
|
|
if (EnableInteraction)
|
|
|
|
{
|
|
|
|
GameManager.Instance.CurrentTycoonPlayer.TycoonInput.RegisterPlayerInteraction(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void UnregisterPlayerInteraction()
|
|
|
|
{
|
|
|
|
if (EnableInteraction)
|
|
|
|
{
|
|
|
|
GameManager.Instance.CurrentTycoonPlayer.TycoonInput.UnregisterPlayerInteraction(this);
|
|
|
|
}
|
|
|
|
}
|
2024-07-22 00:42:29 +00:00
|
|
|
|
|
|
|
protected virtual void OpenTycoonSwitch()
|
|
|
|
{
|
|
|
|
IsOpened = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void ClosedTycoonSwitch()
|
|
|
|
{
|
|
|
|
IsOpened = false;
|
|
|
|
}
|
2024-11-11 02:02:24 +00:00
|
|
|
|
|
|
|
protected void UpdateLocalizedString(string entryName)
|
|
|
|
{
|
|
|
|
if (!LocalizeStringEvent) return;
|
|
|
|
|
|
|
|
LocalizeStringEvent.StringReference.TableReference = "StringDataTable";
|
|
|
|
LocalizeStringEvent.StringReference.TableEntryReference = entryName;
|
|
|
|
|
|
|
|
StartCoroutine(LoadLocalizedString());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected IEnumerator LoadLocalizedString()
|
|
|
|
{
|
|
|
|
var getLocalizedStringOperation = LocalizeStringEvent.StringReference.GetLocalizedStringAsync();
|
|
|
|
yield return getLocalizedStringOperation;
|
|
|
|
|
|
|
|
if (getLocalizedStringOperation.IsDone)
|
|
|
|
{
|
|
|
|
InteractionMessage = getLocalizedStringOperation.Result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogError("Failed to load localized string.");
|
|
|
|
}
|
|
|
|
}
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
|
|
|
}
|