94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using System;
|
|
using BriarQueen.Data.Identifiers;
|
|
using BriarQueen.Data.IO.Saves;
|
|
using BriarQueen.Framework.Events.UI;
|
|
using BriarQueen.Framework.Managers.Levels.Data;
|
|
using BriarQueen.Game.Items.Environment.ChapterOne.VillageStreet;
|
|
using BriarQueen.Game.Items.HoverZones;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BriarQueen.Game.Levels.ChapterOne.VillageStreet
|
|
{
|
|
public class Street : BaseLevel
|
|
{
|
|
[Header("Level Setup")]
|
|
[SerializeField]
|
|
private Image _background;
|
|
|
|
[SerializeField]
|
|
private Sprite _vinesCutSprite;
|
|
|
|
[SerializeField]
|
|
private Sprite _gateOpenSprite;
|
|
|
|
[Header("Zones")]
|
|
[SerializeField]
|
|
private StreetVines _vinesZone;
|
|
|
|
[SerializeField]
|
|
private InteractZone _plaqueZone;
|
|
|
|
[SerializeField]
|
|
private InteractZone _gateZone;
|
|
|
|
|
|
protected override UniTask PostLoadInternal()
|
|
{
|
|
bool gateOpen = SaveManager.GetLevelFlag(LevelFlag.VillageStreetGateOpen);
|
|
bool vinesCut = SaveManager.GetLevelFlag(LevelFlag.VillageStreetVinesCut) || gateOpen;
|
|
|
|
if (gateOpen)
|
|
{
|
|
_background.sprite = _gateOpenSprite;
|
|
}
|
|
else if (vinesCut)
|
|
{
|
|
_background.sprite = _vinesCutSprite;
|
|
}
|
|
|
|
ApplyZones(vinesCut, gateOpen);
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
public async UniTask CutVines()
|
|
{
|
|
EventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(EnvironmentInteractKey.UsingKnife)));
|
|
await UniTask.Delay(TimeSpan.FromSeconds(1));
|
|
EventCoordinator.Publish(new FadeEvent(false, 0.8f));
|
|
await UniTask.Delay(TimeSpan.FromSeconds(0.8f));
|
|
|
|
_background.sprite = _vinesCutSprite;
|
|
SetZoneState(_plaqueZone, true);
|
|
await DeactivateVines();
|
|
|
|
SaveManager.SetLevelFlag(LevelFlag.VillageStreetVinesCut, true);
|
|
EventCoordinator.Publish(new FadeEvent(true, 0.8f));
|
|
}
|
|
|
|
private void ApplyZones(bool vinesCut, bool gateOpen)
|
|
{
|
|
SetZoneState(_plaqueZone, vinesCut);
|
|
SetZoneState(_gateZone, gateOpen);
|
|
|
|
if (vinesCut)
|
|
DeactivateVines().Forget();
|
|
}
|
|
|
|
private void SetZoneState(InteractZone zone, bool active)
|
|
{
|
|
if (zone == null || zone.CanvasGroup == null)
|
|
return;
|
|
|
|
zone.CanvasGroup.alpha = active ? 1 : 0;
|
|
zone.CanvasGroup.blocksRaycasts = active;
|
|
zone.CanvasGroup.interactable = active;
|
|
}
|
|
|
|
private async UniTask DeactivateVines()
|
|
{
|
|
await DestructionService.Destroy(_vinesZone.gameObject);
|
|
}
|
|
}
|
|
} |