Skip to content

Commit

Permalink
improved documentation and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Healey committed Oct 26, 2018
1 parent 573b1ff commit 771f59d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
28 changes: 23 additions & 5 deletions ActivityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static ActivityManager Instance
}
}
private static ActivityManager instance;

private bool transitionInProgress = false;
private GameObject currentActivity;
private TransitionController transitionController;
Expand All @@ -28,16 +29,33 @@ private void Awake()
DontDestroyOnLoad(gameObject);
}

/// <summary>
/// Switches to a new acitivity, with optional transition.
/// If no transition is specified then InstantActivityTransition will be used.
/// This function will result in the target activity's Init() function being called
/// </summary>
/// <param name="transition">The transition to use</param>
/// <typeparam name="TActivity">The target activity</typeparam>
public void SwitchActivity<TActivity>(IActivityTransition transition = null)
where TActivity : Component, IActivity
{
SwitchActivityInternal<TActivity>(a => a.Init(), transition);
}

public void SwitchActivity<TActivity, TArgs>(TArgs args, IActivityTransition transition = null)
where TActivity : Component, IActivity<TArgs>
/// <summary>
/// Switches to a new acitivity, initialization argument and optional transition.
/// The initialization argument is strongly typed.
/// If no transition is specified then InstantActivityTransition will be used.
/// This function will result in the target activity's Init(TArgs initArgs) function being called with the args passed in here
/// </summary>
/// <param name="initArgs">The initialization argument</param>
/// <param name="transition">The transition to use</param>
/// <typeparam name="TActivity">The target activity</typeparam>
/// <typeparam name="TInitArgs">The type of the initialization argument</typeparam>
public void SwitchActivity<TActivity, TInitArgs>(TInitArgs initArgs, IActivityTransition transition = null)
where TActivity : Component, IActivity<TInitArgs>
{
SwitchActivityInternal<TActivity>(a => a.Init(args), transition);
SwitchActivityInternal<TActivity>(a => a.Init(initArgs), transition);
}

private void SwitchActivityInternal<TActivity>(Action<TActivity> initActivity, IActivityTransition transition)
Expand Down Expand Up @@ -98,9 +116,9 @@ void IActivityTransitionController.StartNewActivity()
StartActivityFunc();
}

void IActivityTransitionController.SendMessage<TSomeType>(Action<TSomeType> executeMessage)
void IActivityTransitionController.SendMessage<TComponentType>(Action<TComponentType> executeMessage)
{
var obj = activityManager.currentActivity.GetComponent<TSomeType>();
var obj = activityManager.currentActivity.GetComponent<TComponentType>();
if (obj != null)
{
executeMessage(obj);
Expand Down
4 changes: 2 additions & 2 deletions IActivity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace UnityActivityManager
{
public interface IActivity<TActivityArgs>
public interface IActivity<TInitArgs>
{
void Init(TActivityArgs levelName);
void Init(TInitArgs initArgs);
}

public interface IActivity
Expand Down
20 changes: 20 additions & 0 deletions IActivityTransitionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@ namespace UnityActivityManager
{
public interface IActivityTransitionController
{
/// <summary>
/// Ends the current Activity.
/// This will result in the current activity's game object being destroyed.
/// </summary>
void EndCurrentActivity();

/// <summary>
/// Starts the new activity.
/// This will result in the creation of a new game object and the new activity component being added
/// </summary>
void StartNewActivity();

/// <summary>
/// Sends a message to any component attached to the current activity.
/// Usually this is done by declaring receiver interfaces.
/// </summary>
/// <param name="execute">The function that should be called on the target component</param>
/// <typeparam name="T">The type of the component that will be retreived and used to send the message to</typeparam>
void SendMessage<T>(Action<T> execute);

/// <summary>
/// Used to notify the system that the transition has completed. This needs to be called in every transition.
/// </summary>
void NotifyTransitionComplete();
}
}

0 comments on commit 771f59d

Please sign in to comment.