first commit
This commit is contained in:
commit
aa44d3ad70
1585 changed files with 277994 additions and 0 deletions
211
Assets/Resources/Scripts/StepsLink/StepOrchestrator.cs
Normal file
211
Assets/Resources/Scripts/StepsLink/StepOrchestrator.cs
Normal file
|
@ -0,0 +1,211 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class StepOrchestrator : MonoBehaviour
|
||||
{
|
||||
// Const strings
|
||||
private const string LOG_START_INIT = "Started Loading initializing the steps Link System";
|
||||
|
||||
[Header("Disclaimer")]
|
||||
[InfoBox("It needs to be a parent of StepsList objects. Or manually add the lists. Not both.", EInfoBoxType.Normal)]
|
||||
|
||||
[HorizontalLine(color: EColor.Blue)]
|
||||
|
||||
|
||||
[Header("Callbacks")]
|
||||
|
||||
[Tooltip("Event called when the system is initialized")]
|
||||
[SerializeField]
|
||||
private UnityEvent OnSystemInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the lists will be loaded from the children of the game object that have the StepsList script attached
|
||||
/// </summary>
|
||||
[Tooltip("If true, the lists will be loaded from the children of the game object that have the StepsList script attached")]
|
||||
[SerializeField]
|
||||
private bool loadsListsFromChildren = true;
|
||||
|
||||
/// <summary>
|
||||
/// List of all the StepsList that are part of the game. Order is respected.
|
||||
/// </summary>
|
||||
[HideIf("loadsListsFromChildren")]
|
||||
[Tooltip("List of all the StepsList that are part of the game. Order is respected.")]
|
||||
[SerializeField]
|
||||
private List<StepsListScript> stepsLists = new();
|
||||
|
||||
/// <summary>
|
||||
/// Flag to check if the step link finished initializing all lists
|
||||
/// </summary>
|
||||
private bool isInitialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Flag to check if the steps link system is running the lists
|
||||
/// </summary>
|
||||
private bool isRunning = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Debug.Log(LOG_START_INIT);
|
||||
StartCoroutine(InitStepLinkSystem());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the step link system, getting all the children lists and initialize them, too
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private IEnumerator InitStepLinkSystem()
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
if (loadsListsFromChildren)
|
||||
{
|
||||
stepsLists.Clear();
|
||||
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
if (child.GetComponent<StepsListScript>() != null)
|
||||
{
|
||||
Debug.Log("Found StepsList: " + child.name);
|
||||
stepsLists.Add(child.GetComponent<StepsListScript>());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (StepsListScript list in stepsLists)
|
||||
{
|
||||
if (list.GetComponent<StepsListScript>() == null)
|
||||
{
|
||||
stepsLists.Remove(list);
|
||||
Debug.LogWarning("The list: " + list.name + " has not the StepsList attached. And has been removed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stepsLists.Count == 0)
|
||||
{
|
||||
Debug.LogWarning("No Valid StepsList found");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (StepsListScript list in stepsLists)
|
||||
{
|
||||
yield return StartCoroutine(list.InitListSteps());
|
||||
}
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("This step link system is already initialized");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run all the lists in order
|
||||
/// </summary>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void RunAllLists()
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
throw new Exception("The step link system is not initialized");
|
||||
}
|
||||
else if (isRunning)
|
||||
{
|
||||
throw new Exception("The step link system is already running a list");
|
||||
}
|
||||
else if (isInitialized && !isRunning)
|
||||
{
|
||||
StartCoroutine(RunAll());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run a list by index
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void RunListByIndex(int index)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
throw new Exception("The step link system is not initialized");
|
||||
}
|
||||
else if (isRunning)
|
||||
{
|
||||
throw new Exception("The step link system is already running a list");
|
||||
}
|
||||
else if (isInitialized && !isRunning)
|
||||
{
|
||||
if (index < stepsLists.Count && index >= 0)
|
||||
{
|
||||
StartCoroutine(stepsLists[index].StartSteps());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Invalid index of list, list has " + stepsLists.Count + " elements");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run a list by name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void RunListByName(String name)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
throw new Exception("The step link system is not initialized");
|
||||
}
|
||||
else if (isRunning)
|
||||
{
|
||||
throw new Exception("The step link system is already running a list");
|
||||
}
|
||||
else if (isInitialized && !isRunning)
|
||||
{
|
||||
foreach (StepsListScript list in stepsLists)
|
||||
{
|
||||
if (list.name == name)
|
||||
{
|
||||
StartCoroutine(list.StartSteps());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("No list found with the name: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run all the lists in order
|
||||
/// </summary>
|
||||
private IEnumerator RunAll()
|
||||
{
|
||||
if (isRunning)
|
||||
{
|
||||
throw new Exception("The step link system is already running a list");
|
||||
}
|
||||
else
|
||||
{
|
||||
isRunning = true;
|
||||
|
||||
for (int index = 0; index < stepsLists.Count; index++)
|
||||
{
|
||||
yield return StartCoroutine(stepsLists[index].StartSteps());
|
||||
}
|
||||
|
||||
isRunning = false;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue