Skip to content

Commit

Permalink
chore: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 committed Sep 30, 2024
1 parent 12dd5c3 commit 79c01c0
Show file tree
Hide file tree
Showing 290 changed files with 24,284 additions and 8,776 deletions.
2 changes: 1 addition & 1 deletion Assets/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Unity.Hypercasual.Tutorials.Editor")]
[assembly: InternalsVisibleTo("Unity.Hypercasual.Tutorials.Editor")]
4 changes: 1 addition & 3 deletions Assets/Core/Scripts/Data/AbstractLevelData.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HyperCasual.Core
{
/// <summary>
/// A scriptable object as a base class for data containers that encapsulate level(gameplay) data
/// A scriptable object as a base class for data containers that encapsulate level(gameplay) data
/// </summary>
public abstract class AbstractLevelData : ScriptableObject
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Core/Scripts/Data/AudioSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace HyperCasual.Core
{
/// <summary>
/// Encapsulates audio settings parameters
/// Encapsulates audio settings parameters
/// </summary>
public class AudioSettings
{
Expand Down
9 changes: 3 additions & 6 deletions Assets/Core/Scripts/Data/SceneRef.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HyperCasual.Core
{
/// <summary>
/// A scriptable object that encapsulates a reference to a scene
/// A scriptable object that encapsulates a reference to a scene
/// </summary>
[CreateAssetMenu(fileName = nameof(SceneRef),
menuName = "Runner/" + nameof(SceneRef))]
public class SceneRef : AbstractLevelData
{
[SerializeField]
public string m_ScenePath;
[SerializeField] public string m_ScenePath;
}
}
}
41 changes: 17 additions & 24 deletions Assets/Core/Scripts/EventSystem/AbstractGameEvent.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HyperCasual.Core
{
/// <summary>
/// A base class which provides basic event functionalities.
/// Events facilitate the communication between different scopes of the game.
/// Each event is a scriptable object instance that has a list of listeners that are notified when the event is triggered.
/// A base class which provides basic event functionalities.
/// Events facilitate the communication between different scopes of the game.
/// Each event is a scriptable object instance that has a list of listeners that are notified when the event is
/// triggered.
/// </summary>
public abstract class AbstractGameEvent : ScriptableObject
{
readonly List<IGameEventListener> m_EventListeners = new();
private readonly List<IGameEventListener> m_EventListeners = new();

/// <summary>
/// Triggers the current event instance and notifies the subscribers
/// Each event resets immediately after it's triggered.
/// This method contains the reset logic for the derived classes.
/// </summary>
public abstract void Reset();

/// <summary>
/// Triggers the current event instance and notifies the subscribers
/// </summary>
public void Raise()
{
for (int i = m_EventListeners.Count - 1; i >= 0; i--)
for (var i = m_EventListeners.Count - 1; i >= 0; i--)
m_EventListeners[i].OnEventRaised();
Reset();
}

/// <summary>
/// Adds a class to the list of observers for this event
/// Adds a class to the list of observers for this event
/// </summary>
/// <param name="listener">The class that wants to observe this event</param>
public void AddListener(IGameEventListener listener)
{
if (!m_EventListeners.Contains(listener))
{
m_EventListeners.Add(listener);
}
if (!m_EventListeners.Contains(listener)) m_EventListeners.Add(listener);
}

/// <summary>
/// Removes a class from the list of observers for this event
/// Removes a class from the list of observers for this event
/// </summary>
/// <param name="listener">The class that doesn't want to observe this event anymore</param>
public void RemoveListener(IGameEventListener listener)
{
if (m_EventListeners.Contains(listener))
{
m_EventListeners.Remove(listener);
}
if (m_EventListeners.Contains(listener)) m_EventListeners.Remove(listener);
}

/// <summary>
/// Each event resets immediately after it's triggered.
/// This method contains the reset logic for the derived classes.
/// </summary>
public abstract void Reset();
}
}
15 changes: 6 additions & 9 deletions Assets/Core/Scripts/EventSystem/AppPauseDetector.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HyperCasual.Core
{
/// <summary>
/// Overrides unity event methods to determine if the game is paused or lost focus by external(OS) sources
/// and triggers an event.
/// Overrides unity event methods to determine if the game is paused or lost focus by external(OS) sources
/// and triggers an event.
/// </summary>
public class AppPauseDetector : MonoBehaviour
{
[SerializeField]
AbstractGameEvent m_PauseEvent;
[SerializeField] private AbstractGameEvent m_PauseEvent;

/// <summary>
/// Returns the current pause state of the application
/// Returns the current pause state of the application
/// </summary>
public bool IsPaused { get; private set; }

void OnApplicationFocus(bool hasFocus)
private void OnApplicationFocus(bool hasFocus)
{
IsPaused = !hasFocus;

if (IsPaused)
m_PauseEvent.Raise();
}

void OnApplicationPause(bool pauseStatus)
private void OnApplicationPause(bool pauseStatus)
{
IsPaused = pauseStatus;

Expand Down
16 changes: 5 additions & 11 deletions Assets/Core/Scripts/EventSystem/GameEvent.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using HyperCasual.Core;
using UnityEngine;
using HyperCasual.Runner;

namespace HyperCasual.Core
{
/// <summary>
/// Generic game event
/// Generic game event
/// </summary>
public class GameEvent<T> : AbstractGameEvent
{
public T m_Data { get; private set; }

public void Raise(T data)
public override void Reset()
{
m_Data = data;
base.Raise();
}

public override void Reset()
public void Raise(T data)
{
m_Data = data;
base.Raise();
}
}
}
4 changes: 2 additions & 2 deletions Assets/Core/Scripts/EventSystem/IGameEventListener.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace HyperCasual.Core
{
/// <summary>
/// All classes that want to subscribe to an event must implement this interface
/// All classes that want to subscribe to an event must implement this interface
/// </summary>
public interface IGameEventListener
{
/// <summary>
/// The event handler that is called when the subscribed event is triggered
/// The event handler that is called when the subscribed event is triggered
/// </summary>
void OnEventRaised();
}
Expand Down
17 changes: 5 additions & 12 deletions Assets/Core/Scripts/EventSystem/TriggerEvent.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HyperCasual.Core
{
/// <summary>
/// Raises an event on trigger collision
/// Raises an event on trigger collision
/// </summary>
[RequireComponent(typeof(Collider))]
public class TriggerEvent : MonoBehaviour
{
const string k_PlayerTag = "Player";
private const string k_PlayerTag = "Player";

[SerializeField]
AbstractGameEvent m_Event;
[SerializeField] private AbstractGameEvent m_Event;

void OnTriggerEnter(Collider col)
private void OnTriggerEnter(Collider col)
{
if (col.CompareTag(k_PlayerTag))
{
if (m_Event != null)
{
m_Event.Raise();
}
}
}
}
}
}
14 changes: 4 additions & 10 deletions Assets/Core/Scripts/Singleton/AbstractSingleton.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HyperCasual.Core
{
/// <summary>
/// An abstract class that provides base functionalities of a singleton for its derived classes
/// An abstract class that provides base functionalities of a singleton for its derived classes
/// </summary>
/// <typeparam name="T">The type of singleton instance</typeparam>
public abstract class AbstractSingleton<T> : MonoBehaviour where T : Component
{
static T s_Instance;
private static T s_Instance;

/// <summary>
/// static Singleton instance
/// static Singleton instance
/// </summary>
public static T Instance
{
Expand All @@ -24,7 +22,7 @@ public static T Instance
s_Instance = FindObjectOfType<T>();
if (s_Instance == null)
{
GameObject obj = new GameObject();
var obj = new GameObject();
obj.name = typeof(T).Name;
s_Instance = obj.AddComponent<T>();
}
Expand All @@ -37,13 +35,9 @@ public static T Instance
protected virtual void Awake()
{
if (s_Instance == null)
{
s_Instance = this as T;
}
else
{
Destroy(gameObject);
}
}
}
}
37 changes: 9 additions & 28 deletions Assets/Core/Scripts/StateMachine/AbstractState.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HyperCasual.Core
{
/// <summary>
/// An abstract class that provides common functionalities for the states of state machines
/// An abstract class that provides common functionalities for the states of state machines
/// </summary>
public abstract class AbstractState : IState
{
private readonly List<ILink> m_Links = new();

/// <summary>
/// The name of the state used for debugging purposes
/// The name of the state used for debugging purposes
/// </summary>
public virtual string Name { get; set; }

readonly List<ILink> m_Links = new();

public virtual void Enter()
{
}
Expand All @@ -29,18 +27,12 @@ public virtual void Exit()

public virtual void AddLink(ILink link)
{
if (!m_Links.Contains(link))
{
m_Links.Add(link);
}
if (!m_Links.Contains(link)) m_Links.Add(link);
}

public virtual void RemoveLink(ILink link)
{
if (m_Links.Contains(link))
{
m_Links.Remove(link);
}
if (m_Links.Contains(link)) m_Links.Remove(link);
}

public virtual void RemoveAllLinks()
Expand All @@ -51,16 +43,11 @@ public virtual void RemoveAllLinks()
public virtual bool ValidateLinks(out IState nextState)
{
if (m_Links != null && m_Links.Count > 0)
{
foreach (var link in m_Links)
{
var result = link.Validate(out nextState);
if (result)
{
return true;
}
if (result) return true;
}
}

//default
nextState = null;
Expand All @@ -69,18 +56,12 @@ public virtual bool ValidateLinks(out IState nextState)

public void EnableLinks()
{
foreach (var link in m_Links)
{
link.Enable();
}
foreach (var link in m_Links) link.Enable();
}

public void DisableLinks()
{
foreach (var link in m_Links)
{
link.Disable();
}
foreach (var link in m_Links) link.Disable();
}
}
}
Loading

0 comments on commit 79c01c0

Please sign in to comment.