First commit for private source control. Older commits available on Github.
This commit is contained in:
112
Assets/Scripts/Game/Items/HoverZones/InteractZone.cs
Normal file
112
Assets/Scripts/Game/Items/HoverZones/InteractZone.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using BriarQueen.Data.Identifiers;
|
||||
using BriarQueen.Framework.Coordinators.Events;
|
||||
using BriarQueen.Framework.Events.UI;
|
||||
using BriarQueen.Framework.Managers.Interaction.Data;
|
||||
using BriarQueen.Framework.Managers.IO;
|
||||
using BriarQueen.Framework.Managers.Levels;
|
||||
using BriarQueen.Framework.Managers.Player.Data;
|
||||
using BriarQueen.Framework.Managers.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace BriarQueen.Game.Items.HoverZones
|
||||
{
|
||||
public class InteractZone : MonoBehaviour, IInteractable
|
||||
{
|
||||
[Header("Level Setup")]
|
||||
[SerializeField]
|
||||
private LevelKey _levelToLoad;
|
||||
|
||||
[SerializeField]
|
||||
private string _levelName;
|
||||
|
||||
[SerializeField]
|
||||
private string _lockedTooltipText = string.Empty;
|
||||
[SerializeField]
|
||||
private string _lockedInteractText = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
private bool _locked;
|
||||
|
||||
[Header("UI Setup")]
|
||||
[SerializeField]
|
||||
private UICursorService.CursorStyle _cursorStyle = UICursorService.CursorStyle.Travel;
|
||||
|
||||
protected EventCoordinator EventCoordinator;
|
||||
protected LevelManager LevelManager;
|
||||
protected SaveManager SaveManager;
|
||||
|
||||
public CanvasGroup CanvasGroup;
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
if(CanvasGroup == null)
|
||||
CanvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
if (_locked && CheckUnlockStatus())
|
||||
Unlock();
|
||||
}
|
||||
|
||||
public UICursorService.CursorStyle ApplicableCursorStyle => _cursorStyle;
|
||||
|
||||
public virtual string InteractableName => _locked ? _lockedTooltipText : _levelName;
|
||||
|
||||
public virtual async UniTask OnInteract(ItemDataSo item = null)
|
||||
{
|
||||
if (_locked)
|
||||
{
|
||||
var message = !string.IsNullOrEmpty(_lockedInteractText) ? _lockedInteractText
|
||||
: InteractEventIDs.Get(EnvironmentInteractKey.Locked);
|
||||
|
||||
EventCoordinator.Publish(new DisplayInteractEvent(message));
|
||||
return;
|
||||
}
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
EventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.CantUseItem)));
|
||||
return;
|
||||
}
|
||||
|
||||
var levelId = AssetKeyIdentifiers.Get(_levelToLoad);
|
||||
var loaded = await LevelManager.LoadLevel(levelId);
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
EventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(EnvironmentInteractKey.CantGoThere)));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual UniTask EnterHover()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual UniTask ExitHover()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
_locked = false;
|
||||
}
|
||||
|
||||
protected virtual bool CheckUnlockStatus()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
[Inject]
|
||||
public void Construct(LevelManager levelManager, EventCoordinator eventCoordinator, SaveManager saveManager)
|
||||
{
|
||||
LevelManager = levelManager;
|
||||
EventCoordinator = eventCoordinator;
|
||||
SaveManager = saveManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user