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.
137 lines
2.4 KiB
137 lines
2.4 KiB
10 years ago
|
#if UNITY_EDITOR
|
||
|
using UnityEditor;
|
||
|
#endif
|
||
|
using UnityEngine;
|
||
10 years ago
|
using System;
|
||
10 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
10 years ago
|
namespace Fungus.Script
|
||
10 years ago
|
{
|
||
|
|
||
|
public class Sequence : MonoBehaviour
|
||
|
{
|
||
|
[HideInInspector]
|
||
10 years ago
|
public Rect nodeRect = new Rect(10, 10, 100, 40);
|
||
10 years ago
|
|
||
10 years ago
|
[HideInInspector]
|
||
|
public string description = "";
|
||
|
|
||
10 years ago
|
[System.NonSerialized]
|
||
10 years ago
|
public FungusScript fungusScript;
|
||
10 years ago
|
|
||
10 years ago
|
[System.NonSerialized]
|
||
10 years ago
|
public FungusCommand activeCommand;
|
||
|
|
||
10 years ago
|
int executionCount;
|
||
10 years ago
|
|
||
10 years ago
|
public virtual void Start()
|
||
|
{
|
||
10 years ago
|
fungusScript = GetFungusScript();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public FungusScript GetFungusScript()
|
||
10 years ago
|
{
|
||
10 years ago
|
FungusScript sc = null;
|
||
10 years ago
|
Transform parent = transform.parent;
|
||
|
while (parent != null)
|
||
|
{
|
||
10 years ago
|
sc = parent.gameObject.GetComponent<FungusScript>();
|
||
10 years ago
|
|
||
10 years ago
|
if (sc != null)
|
||
10 years ago
|
{
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
return sc;
|
||
10 years ago
|
}
|
||
|
|
||
|
public bool HasError()
|
||
|
{
|
||
|
FungusCommand[] commands = GetComponents<FungusCommand>();
|
||
|
foreach (FungusCommand command in commands)
|
||
|
{
|
||
|
if (command.errorMessage.Length > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public bool IsRunning()
|
||
|
{
|
||
10 years ago
|
if (fungusScript == null ||
|
||
10 years ago
|
fungusScript.executingSequence == null)
|
||
10 years ago
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
10 years ago
|
return (fungusScript.executingSequence == this);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public int GetExecutionCount()
|
||
|
{
|
||
|
return executionCount;
|
||
|
}
|
||
|
|
||
10 years ago
|
public void ExecuteNextCommand(FungusCommand currentCommand = null)
|
||
|
{
|
||
10 years ago
|
if (currentCommand == null)
|
||
|
{
|
||
|
executionCount++;
|
||
|
}
|
||
|
|
||
10 years ago
|
activeCommand = null;
|
||
|
FungusCommand nextCommand = null;
|
||
|
|
||
|
bool executeNext = (currentCommand == null);
|
||
|
FungusCommand[] commands = GetComponents<FungusCommand>();
|
||
|
foreach (FungusCommand command in commands)
|
||
|
{
|
||
|
if (command == currentCommand)
|
||
|
{
|
||
|
executeNext = true;
|
||
|
}
|
||
|
else if (executeNext)
|
||
|
{
|
||
|
nextCommand = command;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (nextCommand == null)
|
||
|
{
|
||
10 years ago
|
Stop();
|
||
10 years ago
|
}
|
||
|
else
|
||
|
{
|
||
10 years ago
|
if (GetFungusScript().stepTime == 0f)
|
||
10 years ago
|
{
|
||
|
activeCommand = nextCommand;
|
||
|
nextCommand.Execute();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
10 years ago
|
StartCoroutine(ExecuteAfterDelay(nextCommand, GetFungusScript().stepTime));
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
IEnumerator ExecuteAfterDelay(FungusCommand command, float delay)
|
||
|
{
|
||
|
activeCommand = command;
|
||
|
yield return new WaitForSeconds(delay);
|
||
|
command.Execute();
|
||
|
}
|
||
|
|
||
10 years ago
|
public void Stop()
|
||
10 years ago
|
{
|
||
|
activeCommand = null;
|
||
10 years ago
|
fungusScript.executingSequence = null;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|