Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
add template for event channel scriptable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
M4lph authored and ManuelRauber committed Mar 3, 2024
1 parent 0f487f3 commit 778aefc
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 67 deletions.
5 changes: 5 additions & 0 deletions FairyTaleDefender/Assets/_Game/Scripts/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class MenuNames
{
public const string MenuName = "Fairy Tale Defender";
public const string Events = MenuName + "/Events";
public const string EventChannelSuffix = " Event Channel";
public const string SceneManagement = MenuName + "/Scene Management";
public const string UI = MenuName + "/UI";
public const string Input = MenuName + "/Input";
Expand Down Expand Up @@ -61,5 +62,9 @@ public static class Panning
}
}

public static class FileNames
{
public const string EventChannelSuffix = "_EventChannel";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObjects
{
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Audio Cue Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Audio Cue" + Constants.MenuNames.EventChannelSuffix)]
public class AudioCueEventChannelSO : EventChannelSO<AudioCueSO>
{
// Marker Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObje
/// <summary>
/// Event channel with a bool argument.
/// </summary>
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Bool Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Bool" + Constants.MenuNames.EventChannelSuffix)]
public class BoolEventChannelSO : EventChannelSO<bool>
{
// Marker class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObjects
{
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Buildable Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Buildable" + Constants.MenuNames.EventChannelSuffix)]
public class BuildableEventChannelSO : EventChannelSO<BuildableEventChannelSO.EventArgs>
{
public struct EventArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObjects
{
[CreateAssetMenu(fileName = "Enemy_EventChannel", menuName = Constants.MenuNames.Events + "/Enemy Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Enemy" + Constants.MenuNames.EventChannelSuffix)]
public class EnemyEventChannelSO : EventChannelSO<Enemy>
{
// Marker Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObjects
{
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/EnemySO Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/EnemySO" + Constants.MenuNames.EventChannelSuffix)]
public class EnemySOEventChannelSO : EventChannelSO<EnemySO>
{
// Marker Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class EventChannelBaseSO : ScriptableObject
{
#if UNITY_EDITOR
/// <summary>
/// In-Editor description to let developers for what certain event instances are.
/// In-Editor description to let developers know what certain event instances are for.
/// </summary>
[TextArea]
[SerializeField]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObje
/// <summary>
/// Event channel with a float argument.
/// </summary>
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Float Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Float" + Constants.MenuNames.EventChannelSuffix)]
public class FloatEventChannelSO : EventChannelSO<float>
{
// Marker class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObje
/// <summary>
/// Event channel with an int delta argument.
/// </summary>
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Int Delta Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Int Delta" + Constants.MenuNames.EventChannelSuffix)]
public class IntDeltaEventChannelSO : EventChannelSO<IntDeltaEventChannelSO.EventArgs>
{
public struct EventArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObje
/// <summary>
/// Event channel with an int argument.
/// </summary>
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Int Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Int" + Constants.MenuNames.EventChannelSuffix)]
public class IntEventChannelSO : EventChannelSO<int>
{
// Marker class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObjects
{
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Level Finished Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Level Finished" + Constants.MenuNames.EventChannelSuffix)]
public class LevelFinishedEventChannelSO : EventChannelSO<LevelFinishedEventChannelSO.EventArgs>
{
public struct EventArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObje
/// <summary>
/// Event that can be used whenever a scene needs to be loaded, e.g. <see cref="MenuSO"/>.
/// </summary>
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Load Scene Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Load Scene" + Constants.MenuNames.EventChannelSuffix)]
public class LoadSceneEventChannelSO : EventChannelSO<LoadSceneEventChannelSO.EventArgs>
{
public struct EventArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObjects
{
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Tooltip Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Tooltip" + Constants.MenuNames.EventChannelSuffix)]
public class TooltipEventChannelSO : EventChannelSO<TooltipEventChannelSO.EventArgs>
{
public struct EventArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObje
/// <summary>
/// Event channel without any arguments.
/// </summary>
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Void Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Void" + Constants.MenuNames.EventChannelSuffix)]
public class VoidEventChannelSO : EventChannelSO
{
// Marker class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObje
/// <remarks>
/// Indicates if a level has more waves to spawn in <see cref="EventArgs"/>
/// </remarks>
[CreateAssetMenu(fileName = "WaveSpawned_EventChannel", menuName = Constants.MenuNames.Events + "/Wave Spawned Event Channel", order = 0)]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Wave Spawned" + Constants.MenuNames.EventChannelSuffix,
order = 0)]
public class WaveSpawnedEventChannelSO : EventChannelSO<WaveSpawnedEventChannelSO.EventArgs>
{
public struct EventArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace BoundfoxStudios.FairyTaleDefender.Infrastructure.Events.ScriptableObjects
{
[CreateAssetMenu(menuName = Constants.MenuNames.Events + "/Tower Selected Event Channel")]
[CreateAssetMenu(fileName = Constants.FileNames.EventChannelSuffix,
menuName = Constants.MenuNames.Events + "/Tower Selected" + Constants.MenuNames.EventChannelSuffix)]
public class WeaponSelectedEventChannelSO : EventChannelSO<WeaponSelectedEventChannelSO.EventArgs>
{
public struct EventArgs
Expand Down
104 changes: 52 additions & 52 deletions FairyTaleDefender/Assets/_Game/Scripts/Runtime/UI/GameOverUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,70 @@
namespace BoundfoxStudios.FairyTaleDefender.UI
{
[AddComponentMenu(Constants.MenuNames.UI + "/" + nameof(GameOverUI))]
public class GameOverUI : MonoBehaviour
{
[field: Header("References")]
[field: SerializeField]
private GameObject GamePlayCanvas { get; set; } = default!;
public class GameOverUI : MonoBehaviour
{
[field: Header("References")]
[field: SerializeField]
private GameObject GamePlayCanvas { get; set; } = default!;

[field: SerializeField]
private LocalizedString PlayerWonText { get; set; } = default!;
[field: SerializeField]
private LocalizedString PlayerWonText { get; set; } = default!;

[field: SerializeField]
private LocalizedString PlayerLostText { get; set; } = default!;
[field: SerializeField]
private LocalizedString PlayerLostText { get; set; } = default!;

[field: SerializeField]
private TextMeshProUGUI LevelFinishText { get; set; } = default!;
[field: SerializeField]
private TextMeshProUGUI LevelFinishText { get; set; } = default!;

[field: SerializeField]
private SceneLoadRequester NextLevelButton { get; set; } = default!;
[field: SerializeField]
private SceneLoadRequester NextLevelButton { get; set; } = default!;

[field: SerializeField]
private GameObject LevelFinishedPanel { get; set; } = default!;
[field: SerializeField]
private GameObject LevelFinishedPanel { get; set; } = default!;

[field: Header("Listening Channels")]
[field: SerializeField]
private LevelFinishedEventChannelSO LevelFinishedEventChannel { get; set; } = default!;
[field: Header("Listening Channels")]
[field: SerializeField]
private LevelFinishedEventChannelSO LevelFinishedEventChannel { get; set; } = default!;

private void OnEnable()
{
LevelFinishedEventChannel.Raised += InitDisplay;
LevelFinishedPanel.gameObject.SetActive(false);
}
private void OnEnable()
{
LevelFinishedEventChannel.Raised += InitDisplay;
LevelFinishedPanel.gameObject.SetActive(false);
}

private void OnDisable()
{
LevelFinishedEventChannel.Raised -= InitDisplay;
}
private void OnDisable()
{
LevelFinishedEventChannel.Raised -= InitDisplay;
}


private void InitDisplay(LevelFinishedEventChannelSO.EventArgs args)
{
SetLevelFinishedText(args.PlayerHasWon);
SetupButtons();
ActivateCanvases();
}
private void InitDisplay(LevelFinishedEventChannelSO.EventArgs args)
{
SetLevelFinishedText(args.PlayerHasWon);
SetupButtons();
ActivateCanvases();
}

private void SetLevelFinishedText(bool playerWon)
{
LevelFinishText.text = playerWon ? PlayerWonText.GetLocalizedString() : PlayerLostText.GetLocalizedString();
}
private void SetLevelFinishedText(bool playerWon)
{
LevelFinishText.text = playerWon ? PlayerWonText.GetLocalizedString() : PlayerLostText.GetLocalizedString();
}

private void SetupButtons()
{
if (!NextLevelButton.HasNextLevel())
{
return;
}
private void SetupButtons()
{
if (!NextLevelButton.HasNextLevel())
{
return;
}

//TODO: Only display next level button when it is unlocked.
NextLevelButton.gameObject.SetActive(true);
}
//TODO: Only display next level button when it is unlocked.
NextLevelButton.gameObject.SetActive(true);
}

private void ActivateCanvases()
{
LevelFinishedPanel.gameObject.SetActive(true);
GamePlayCanvas.gameObject.SetActive(false);
}
}
private void ActivateCanvases()
{
LevelFinishedPanel.gameObject.SetActive(true);
GamePlayCanvas.gameObject.SetActive(false);
}
}
}
Loading

0 comments on commit 778aefc

Please sign in to comment.