103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
using System;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Players.Tycoons;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public abstract class InteractionFurniture : MonoBehaviour, IPlayerInteraction
|
|
{
|
|
[field: SerializeField]
|
|
public Transform Transform { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public Canvas InteractionCanvas { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public Transform InteractionUi { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public bool EnableInteraction { get; private set; } = true;
|
|
|
|
[field: SerializeField]
|
|
public float InteractionRadius { get; private set; } = 2f;
|
|
|
|
protected TycoonPlayer CurrentTycoonPlayer;
|
|
private bool _isQuitting;
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
Gizmos.color = Color.blue;
|
|
Gizmos.DrawWireSphere(transform.position, InteractionRadius);
|
|
}
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
InitializeComponents();
|
|
}
|
|
|
|
protected virtual void OnEnable()
|
|
{
|
|
RegisterPlayerInteraction();
|
|
}
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
_isQuitting = true;
|
|
}
|
|
|
|
protected virtual void OnDisable()
|
|
{
|
|
if (_isQuitting) return;
|
|
|
|
UnregisterPlayerInteraction();
|
|
}
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
protected virtual void InitializeComponents()
|
|
{
|
|
Transform = transform;
|
|
InteractionCanvas = transform.Find("InteractionCanvas").GetComponent<Canvas>();
|
|
InteractionCanvas.GetComponent<Canvas>().worldCamera = Camera.main;
|
|
InteractionUi = InteractionCanvas.transform.Find("InteractionUi");
|
|
InteractionUi.localScale = Vector3.one * (1 / transform.localScale.x);
|
|
|
|
CurrentTycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
|
}
|
|
|
|
public abstract void Interaction();
|
|
|
|
public virtual bool CanInteraction() => true;
|
|
|
|
public virtual void ShowInteractionUi()
|
|
{
|
|
if (!InteractionCanvas) return;
|
|
|
|
InteractionCanvas.gameObject.SetActive(true);
|
|
}
|
|
|
|
public virtual void HideInteractionUi()
|
|
{
|
|
if (!InteractionCanvas) return;
|
|
|
|
InteractionCanvas.gameObject.SetActive(false);
|
|
}
|
|
|
|
protected void RegisterPlayerInteraction()
|
|
{
|
|
if (EnableInteraction)
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.TycoonInput.RegisterPlayerInteraction(this);
|
|
}
|
|
}
|
|
|
|
protected void UnregisterPlayerInteraction()
|
|
{
|
|
if (EnableInteraction)
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.TycoonInput.UnregisterPlayerInteraction(this);
|
|
}
|
|
}
|
|
}
|
|
} |