First commit for private source control. Older commits available on Github.
This commit is contained in:
243
Assets/Scripts/Framework/Managers/Levels/Data/BaseItem.cs
Normal file
243
Assets/Scripts/Framework/Managers/Levels/Data/BaseItem.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using BriarQueen.Data.Identifiers;
|
||||
using BriarQueen.Data.IO.Saves;
|
||||
using BriarQueen.Framework.Assets;
|
||||
using BriarQueen.Framework.Coordinators.Events;
|
||||
using BriarQueen.Framework.Events.Save;
|
||||
using BriarQueen.Framework.Events.UI;
|
||||
using BriarQueen.Framework.Managers.Audio;
|
||||
using BriarQueen.Framework.Managers.Interaction.Data;
|
||||
using BriarQueen.Framework.Managers.IO;
|
||||
using BriarQueen.Framework.Managers.Player;
|
||||
using BriarQueen.Framework.Managers.Player.Data;
|
||||
using BriarQueen.Framework.Managers.UI;
|
||||
using BriarQueen.Framework.Registries;
|
||||
using BriarQueen.Framework.Services.Destruction;
|
||||
using BriarQueen.Framework.Services.Settings;
|
||||
using BriarQueen.Framework.Services.Tutorials;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using PrimeTween;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace BriarQueen.Framework.Managers.Levels.Data
|
||||
{
|
||||
public class BaseItem : MonoBehaviour, IInteractable
|
||||
{
|
||||
[Header("Item Details")]
|
||||
[SerializeField]
|
||||
private ItemDataSo _itemData;
|
||||
|
||||
[Tooltip("Used for custom tooltip. Defaults to Item Name")]
|
||||
[SerializeField]
|
||||
private string _interactableTooltip = string.Empty;
|
||||
|
||||
[Header("Object Setup")]
|
||||
[SerializeField]
|
||||
protected CanvasGroup _canvasGroup;
|
||||
|
||||
protected AddressableManager AddressableManager;
|
||||
protected AssetRegistry AssetRegistry;
|
||||
protected DestructionService DestructionService;
|
||||
|
||||
protected EventCoordinator EventCoordinator;
|
||||
protected CancellationTokenSource PickupCts;
|
||||
|
||||
protected Sequence PickupSequence;
|
||||
protected PlayerManager PlayerManager;
|
||||
protected SaveManager SaveManager;
|
||||
protected SettingsService SettingsService;
|
||||
|
||||
protected TutorialService TutorialService;
|
||||
protected AudioManager AudioManager;
|
||||
|
||||
public ItemDataSo ItemData => _itemData;
|
||||
|
||||
public CanvasGroup CanvasGroup => _canvasGroup;
|
||||
|
||||
protected string InteractableTooltip => _interactableTooltip;
|
||||
|
||||
public GameObject GameObject => gameObject;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_canvasGroup == null)
|
||||
_canvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
public virtual UICursorService.CursorStyle ApplicableCursorStyle => UICursorService.CursorStyle.Pickup;
|
||||
|
||||
public virtual string InteractableName =>
|
||||
!string.IsNullOrWhiteSpace(_interactableTooltip) ? _interactableTooltip : _itemData.ItemName;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the item is interacted with. Defaults to Pickup.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public virtual async UniTask OnInteract(ItemDataSo item = null)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
EventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.CantUseItem)));
|
||||
return;
|
||||
}
|
||||
|
||||
CheckCyclingTutorial();
|
||||
|
||||
if (!CheckEmptyHands())
|
||||
return;
|
||||
|
||||
await Pickup();
|
||||
await OnInteracted();
|
||||
}
|
||||
|
||||
public virtual UniTask EnterHover()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual UniTask ExitHover()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when item is interacted with.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual UniTask OnInteracted()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
protected virtual bool CheckEmptyHands()
|
||||
{
|
||||
if (PlayerManager.GetEquippedTool() != ToolID.None)
|
||||
{
|
||||
EventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.EmptyHands)));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckCyclingTutorial()
|
||||
{
|
||||
TutorialService.DisplayTutorial(TutorialPopupID.ItemCycling);
|
||||
}
|
||||
|
||||
[Inject]
|
||||
public void Construct(EventCoordinator eventCoordinator, SaveManager saveManager, PlayerManager playerManager,
|
||||
DestructionService destructionService, SettingsService settingsService,
|
||||
AddressableManager addressableManager, AssetRegistry assetRegistry, TutorialService tutorialService,
|
||||
AudioManager audioManager)
|
||||
{
|
||||
EventCoordinator = eventCoordinator;
|
||||
SaveManager = saveManager;
|
||||
PlayerManager = playerManager;
|
||||
DestructionService = destructionService;
|
||||
SettingsService = settingsService;
|
||||
AddressableManager = addressableManager;
|
||||
AssetRegistry = assetRegistry;
|
||||
TutorialService = tutorialService;
|
||||
AudioManager = audioManager;
|
||||
}
|
||||
|
||||
protected virtual async UniTask Remove()
|
||||
{
|
||||
// TODO - Play Cut Vines SFX
|
||||
if (_canvasGroup == null) _canvasGroup = GetComponent<CanvasGroup>();
|
||||
|
||||
if (PickupSequence.isAlive)
|
||||
{
|
||||
PickupSequence.Complete();
|
||||
PickupCts?.Cancel();
|
||||
PickupCts?.Dispose();
|
||||
}
|
||||
|
||||
PickupCts = new CancellationTokenSource();
|
||||
|
||||
PickupSequence = Sequence.Create().Group(Tween.Alpha(_canvasGroup, new TweenSettings<float>
|
||||
{
|
||||
startValue = _canvasGroup.alpha,
|
||||
endValue = 0,
|
||||
settings = new TweenSettings
|
||||
{
|
||||
duration = 0.5f
|
||||
}
|
||||
}));
|
||||
|
||||
try
|
||||
{
|
||||
await PickupSequence.ToUniTask(cancellationToken: PickupCts.Token);
|
||||
await OnRemoved();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
UpdateSaveGameOnRemoval();
|
||||
await DestructionService.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSaveGameOnRemoval()
|
||||
{
|
||||
var save = SaveManager.CurrentSave;
|
||||
Debug.Log($"[Base Item] Found save - {save.SaveFileName}");
|
||||
|
||||
save.RemovedItems ??= new List<ItemSaveData>();
|
||||
|
||||
save.RemovedItems.Add(new ItemSaveData
|
||||
{
|
||||
UniqueIdentifier = _itemData.UniqueID
|
||||
});
|
||||
|
||||
EventCoordinator.PublishImmediate(new RequestGameSaveEvent());
|
||||
}
|
||||
|
||||
protected virtual UniTask OnRemoved()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
protected virtual async UniTask Pickup()
|
||||
{
|
||||
if (_canvasGroup == null) _canvasGroup = GetComponent<CanvasGroup>();
|
||||
|
||||
if (PickupSequence.isAlive)
|
||||
{
|
||||
PickupSequence.Complete();
|
||||
PickupCts?.Cancel();
|
||||
PickupCts?.Dispose();
|
||||
}
|
||||
|
||||
PickupCts = new CancellationTokenSource();
|
||||
|
||||
PickupSequence = Sequence.Create().Group(Tween.Alpha(_canvasGroup, new TweenSettings<float>
|
||||
{
|
||||
startValue = _canvasGroup.alpha,
|
||||
endValue = 0,
|
||||
settings = new TweenSettings
|
||||
{
|
||||
duration = 0.5f
|
||||
}
|
||||
}));
|
||||
|
||||
try
|
||||
{
|
||||
await PickupSequence.ToUniTask(cancellationToken: PickupCts.Token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
PlayerManager.CollectItem(_itemData);
|
||||
await DestructionService.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 529a2a922f6f48a982159e2dbc41c542
|
||||
timeCreated: 1770918505
|
||||
116
Assets/Scripts/Framework/Managers/Levels/Data/BaseLevel.cs
Normal file
116
Assets/Scripts/Framework/Managers/Levels/Data/BaseLevel.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System.Collections.Generic;
|
||||
using BriarQueen.Data.Identifiers;
|
||||
using BriarQueen.Framework.Coordinators.Events;
|
||||
using BriarQueen.Framework.Events.UI;
|
||||
using BriarQueen.Framework.Managers.Hints.Data;
|
||||
using BriarQueen.Framework.Managers.Interaction;
|
||||
using BriarQueen.Framework.Managers.IO;
|
||||
using BriarQueen.Framework.Managers.Player;
|
||||
using BriarQueen.Framework.Managers.Player.Data.Codex;
|
||||
using BriarQueen.Framework.Services.Destruction;
|
||||
using BriarQueen.Framework.Services.Settings;
|
||||
using BriarQueen.Framework.Services.Tutorials;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using VContainer;
|
||||
|
||||
namespace BriarQueen.Framework.Managers.Levels.Data
|
||||
{
|
||||
public class BaseLevel : MonoBehaviour
|
||||
{
|
||||
[Header("General")]
|
||||
[SerializeField]
|
||||
private LevelKey _levelKey;
|
||||
[SerializeField]
|
||||
private string _levelName;
|
||||
[Header("Items")]
|
||||
[SerializeField]
|
||||
public List<BaseItem> Pickups;
|
||||
|
||||
public List<CodexTrigger> CodexTriggers;
|
||||
|
||||
[Header("Setup")]
|
||||
[SerializeField]
|
||||
protected GraphicRaycaster _raycaster;
|
||||
|
||||
protected DestructionService DestructionService;
|
||||
|
||||
protected EventCoordinator EventCoordinator;
|
||||
protected InteractManager InteractManager;
|
||||
protected PlayerManager PlayerManager;
|
||||
protected SaveManager SaveManager;
|
||||
protected SettingsService SettingsService;
|
||||
protected TutorialService TutorialService;
|
||||
public virtual string SceneID => AssetKeyIdentifiers.Get(SceneKey.GameScene);
|
||||
public string LevelID => AssetKeyIdentifiers.Get(_levelKey);
|
||||
|
||||
public virtual string LevelName => _levelName;
|
||||
|
||||
public virtual bool IsPuzzleLevel { get; }
|
||||
|
||||
public virtual int CurrentLevelHintStage { get; set; }
|
||||
|
||||
public virtual Dictionary<int, BaseHint> Hints { get; }
|
||||
|
||||
[Inject]
|
||||
public void Construct(EventCoordinator eventCoordinator, InteractManager interactManager, SaveManager saveManager,
|
||||
DestructionService destructionService, SettingsService settingsService, PlayerManager playerManager,
|
||||
TutorialService tutorialService)
|
||||
{
|
||||
EventCoordinator = eventCoordinator;
|
||||
InteractManager = interactManager;
|
||||
SaveManager = saveManager;
|
||||
DestructionService = destructionService;
|
||||
SettingsService = settingsService;
|
||||
PlayerManager = playerManager;
|
||||
TutorialService = tutorialService;
|
||||
}
|
||||
|
||||
public async UniTask PostLoad()
|
||||
{
|
||||
InteractManager.AddUIRaycaster(_raycaster);
|
||||
EventCoordinator.Publish(new UIToggleHudEvent(true));
|
||||
|
||||
await PostLoadInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after Level Load, but before activating. Override for Implementations
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual UniTask PostLoadInternal()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public async UniTask PostActivate()
|
||||
{
|
||||
await PostActivateInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after a level is activated. Override for implementations.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual UniTask PostActivateInternal()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public async UniTask PreUnload()
|
||||
{
|
||||
InteractManager.RemoveUIRaycaster(_raycaster);
|
||||
await PreUnloadInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before the level is destroyed. Override for cleanup, etc.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual UniTask PreUnloadInternal()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ccd49cd2f5c4e8b9cfd394f7844bdf8
|
||||
timeCreated: 1769725044
|
||||
Reference in New Issue
Block a user