First commit for private source control. Older commits available on Github.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using BriarQueen.Framework.Coordinators.Events;
|
||||
using BriarQueen.Framework.Events.Input;
|
||||
using BriarQueen.Framework.Managers.Interaction;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using VContainer;
|
||||
|
||||
namespace BriarQueen.Game.Items.Environment.General.Book
|
||||
{
|
||||
public class BookInterface : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private CanvasGroup _canvasGroup;
|
||||
|
||||
[SerializeField]
|
||||
private GraphicRaycaster _graphicRaycaster;
|
||||
|
||||
private BookTrigger _bookTrigger;
|
||||
private EventCoordinator _eventCoordinator;
|
||||
private InteractManager _interactManager;
|
||||
|
||||
internal CanvasGroup CanvasGroup => _canvasGroup;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_interactManager.SetExclusiveRaycaster(_graphicRaycaster);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_eventCoordinator.Unsubscribe<OnRightClickEvent>(OnRightClickPressed);
|
||||
_interactManager.ClearExclusiveRaycaster();
|
||||
}
|
||||
|
||||
[Inject]
|
||||
public void Construct(EventCoordinator eventCoordinator, InteractManager interactManager)
|
||||
{
|
||||
_eventCoordinator = eventCoordinator;
|
||||
_interactManager = interactManager;
|
||||
}
|
||||
|
||||
public void Initialise(BookTrigger trigger)
|
||||
{
|
||||
_bookTrigger = trigger;
|
||||
|
||||
_eventCoordinator.Subscribe<OnRightClickEvent>(OnRightClickPressed);
|
||||
}
|
||||
|
||||
private void OnRightClickPressed(OnRightClickEvent e)
|
||||
{
|
||||
_bookTrigger.CloseBookInterface().Forget();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a73c3f5588834da2a26a77de99f59e3c
|
||||
timeCreated: 1773508324
|
||||
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using BriarQueen.Data.Identifiers;
|
||||
using BriarQueen.Framework.Events.Save;
|
||||
using BriarQueen.Framework.Events.UI;
|
||||
using BriarQueen.Framework.Managers.Levels.Data;
|
||||
using BriarQueen.Framework.Managers.Player.Data;
|
||||
using BriarQueen.Framework.Managers.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using PrimeTween;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BriarQueen.Game.Items.Environment.General.Book
|
||||
{
|
||||
public class BookTrigger : BaseItem
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField]
|
||||
private AssetItemKey _bookAssetID;
|
||||
|
||||
[SerializeField]
|
||||
private BookEntryID _bookEntryID;
|
||||
|
||||
[Header("Book Interface")]
|
||||
[SerializeField]
|
||||
private BookInterface _bookInterface;
|
||||
|
||||
private CancellationTokenSource _displayCts;
|
||||
|
||||
private Sequence _displaySequence;
|
||||
|
||||
public override string InteractableName => "Worn Book";
|
||||
public override UICursorService.CursorStyle ApplicableCursorStyle => UICursorService.CursorStyle.Inspect;
|
||||
|
||||
public override async UniTask OnInteract(ItemDataSo item = null)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
EventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.CantUseItem)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CheckEmptyHands())
|
||||
return;
|
||||
|
||||
await InstantiateBookInterface();
|
||||
}
|
||||
|
||||
private async UniTask InstantiateBookInterface()
|
||||
{
|
||||
Debug.Log($"Instantiating {_bookAssetID}");
|
||||
|
||||
if (!AssetRegistry.TryGetReference(AssetKeyIdentifiers.Get(_bookAssetID), out var assetReference) ||
|
||||
assetReference == null)
|
||||
return;
|
||||
|
||||
var bookObj = await AddressableManager.InstantiateAsync(assetReference);
|
||||
if (bookObj == null) return;
|
||||
|
||||
_bookInterface = bookObj.GetComponent<BookInterface>();
|
||||
if (_bookInterface == null) return;
|
||||
|
||||
_bookInterface.CanvasGroup.alpha = 0f;
|
||||
_bookInterface.CanvasGroup.blocksRaycasts = false;
|
||||
_bookInterface.CanvasGroup.interactable = false;
|
||||
|
||||
_bookInterface.Initialise(this);
|
||||
Debug.Log($"Instantiated {_bookAssetID}");
|
||||
|
||||
CancelTweenIfRunning();
|
||||
_displayCts = new CancellationTokenSource();
|
||||
|
||||
_displaySequence = Sequence.Create(useUnscaledTime: true)
|
||||
.Group(Tween.Alpha(_bookInterface.CanvasGroup, new TweenSettings<float>
|
||||
{
|
||||
endValue = 1f,
|
||||
settings = new TweenSettings { duration = 0.8f }
|
||||
}));
|
||||
|
||||
try
|
||||
{
|
||||
await _displaySequence.ToUniTask(cancellationToken: _displayCts.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
_bookInterface.CanvasGroup.blocksRaycasts = true;
|
||||
_bookInterface.CanvasGroup.interactable = true;
|
||||
|
||||
ShowTutorialIfNeeded();
|
||||
UnlockCodexEntry();
|
||||
}
|
||||
|
||||
private void ShowTutorialIfNeeded()
|
||||
{
|
||||
TutorialService.DisplayTutorial(TutorialPopupID.ExitItems);
|
||||
}
|
||||
|
||||
private void UnlockCodexEntry()
|
||||
{
|
||||
PlayerManager.UnlockCodexEntry(CodexEntryIDs.Get(_bookEntryID));
|
||||
}
|
||||
|
||||
public async UniTask CloseBookInterface()
|
||||
{
|
||||
if (_bookInterface == null) return;
|
||||
|
||||
CancelTweenIfRunning();
|
||||
_displayCts = new CancellationTokenSource();
|
||||
|
||||
_displaySequence = Sequence.Create(useUnscaledTime: true)
|
||||
.Group(Tween.Alpha(_bookInterface.CanvasGroup, new TweenSettings<float>
|
||||
{
|
||||
startValue = _bookInterface.CanvasGroup.alpha,
|
||||
endValue = 0f,
|
||||
settings = new TweenSettings { duration = 0.6f }
|
||||
}));
|
||||
|
||||
try
|
||||
{
|
||||
await _displaySequence.ToUniTask(cancellationToken: _displayCts.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
await DestructionService.Destroy(_bookInterface.gameObject);
|
||||
_bookInterface = null;
|
||||
}
|
||||
|
||||
private void CancelTweenIfRunning()
|
||||
{
|
||||
if (_displaySequence.isAlive) _displaySequence.Complete();
|
||||
DisposeCts();
|
||||
}
|
||||
|
||||
private void DisposeCts()
|
||||
{
|
||||
if (_displayCts == null) return;
|
||||
|
||||
_displayCts.Cancel();
|
||||
_displayCts.Dispose();
|
||||
_displayCts = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca523ca014894287805fea5daba9276c
|
||||
timeCreated: 1773507259
|
||||
Reference in New Issue
Block a user