You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.6 KiB
98 lines
2.6 KiB
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UltraCombos;
|
|
|
|
namespace uc
|
|
{
|
|
public class ActivityManager : MonoBehaviour
|
|
{
|
|
[Header("General")]
|
|
public Activity initialActivity;
|
|
Stack<Activity> activity_history = new Stack<Activity>();
|
|
public virtual Activity current_activity { get { return (activity_history.Count > 0) ? activity_history.Peek() : null; } }
|
|
public bool isIdleMode = false;
|
|
|
|
protected const string module = "<color=maroon>Activity Manager</color>";
|
|
|
|
void Start()
|
|
{
|
|
PushActivity(initialActivity);
|
|
Misc.Verbose(module, string.Format("init with activity: {0}", current_activity.name));
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
CheckIdle();
|
|
}
|
|
|
|
protected void CheckIdle()
|
|
{
|
|
if (current_activity != null && isIdleMode)
|
|
{
|
|
if (current_activity.isIdle)
|
|
PopToInitial();
|
|
}
|
|
}
|
|
|
|
|
|
#region PUSH
|
|
public virtual void PushActivity(Activity newActivity)
|
|
{
|
|
if (newActivity == null)
|
|
return;
|
|
|
|
if (current_activity != null)
|
|
{
|
|
current_activity.Leave();
|
|
}
|
|
activity_history.Push(Clone(newActivity));
|
|
current_activity.Enter();
|
|
}
|
|
#endregion
|
|
|
|
#region POP
|
|
public virtual void PopToActivity(Activity targetActivity)
|
|
{
|
|
if (targetActivity != null)
|
|
{
|
|
while (current_activity.source != targetActivity && activity_history.Count > 1)
|
|
{
|
|
current_activity.Killed();
|
|
activity_history.Pop();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (activity_history.Count > 1)
|
|
{
|
|
current_activity.Killed();
|
|
activity_history.Pop();
|
|
}
|
|
}
|
|
current_activity.Enter();
|
|
}
|
|
|
|
public virtual void PopActivity()
|
|
{
|
|
PopToActivity(null);
|
|
}
|
|
|
|
public virtual void PopToInitial()
|
|
{
|
|
PopToActivity(initialActivity);
|
|
}
|
|
#endregion
|
|
|
|
Activity Clone(Activity newActivity)
|
|
{
|
|
var obj = Instantiate(newActivity.gameObject);
|
|
obj.transform.SetParent(transform, false);
|
|
Activity act = obj.GetComponent<Activity>();
|
|
act.source = newActivity;
|
|
return act;
|
|
}
|
|
}
|
|
} |