Implemented dungeon selector
This commit is contained in:
parent
514d985ddb
commit
aeeb15cb12
46 changed files with 26355 additions and 32 deletions
|
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace DungeonSelection
|
||||
{
|
||||
public class DungeonSelector : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private DungeonData[] dungeons;
|
||||
private DungeonData _currentlySelectedDungeonData;
|
||||
private int _currentlySelectedDungeonIndex = 0;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
UIEvents.NextDungeonClicked += SelectNextDungeon;
|
||||
UIEvents.PreviousDungeonClicked += SelectPreviousDungeon;
|
||||
UIEvents.EnterDungeonClicked += LoadDungeon;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
UIEvents.NextDungeonClicked -= SelectNextDungeon;
|
||||
UIEvents.PreviousDungeonClicked -= SelectPreviousDungeon;
|
||||
UIEvents.EnterDungeonClicked -= LoadDungeon;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GameEvents.DungeonSelectionStarted?.Invoke();
|
||||
|
||||
_currentlySelectedDungeonData = dungeons[_currentlySelectedDungeonIndex];
|
||||
GameEvents.ShowingDungeon?.Invoke(_currentlySelectedDungeonData);
|
||||
if (_currentlySelectedDungeonIndex == 0)
|
||||
{
|
||||
GameEvents.ShowingFirstDugeon?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDungeon(DungeonData dungeon)
|
||||
{
|
||||
GameEvents.LoadDungeon?.Invoke(dungeon);
|
||||
}
|
||||
|
||||
private void SelectNextDungeon()
|
||||
{
|
||||
if (_currentlySelectedDungeonIndex + 1 >= dungeons.Length) return;
|
||||
_currentlySelectedDungeonIndex++;
|
||||
_currentlySelectedDungeonData = dungeons[_currentlySelectedDungeonIndex];
|
||||
GameEvents.ShowingDungeon?.Invoke(_currentlySelectedDungeonData);
|
||||
if (_currentlySelectedDungeonIndex == dungeons.Length - 1)
|
||||
{
|
||||
GameEvents.ShowingLastDungeon?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectPreviousDungeon()
|
||||
{
|
||||
if (_currentlySelectedDungeonIndex - 1 < 0) return;
|
||||
_currentlySelectedDungeonIndex--;
|
||||
_currentlySelectedDungeonData = dungeons[_currentlySelectedDungeonIndex];
|
||||
GameEvents.ShowingDungeon?.Invoke(_currentlySelectedDungeonData);
|
||||
if (_currentlySelectedDungeonIndex == 0)
|
||||
{
|
||||
GameEvents.ShowingFirstDugeon?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue