An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
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.

97 lines
1.6 KiB

#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[RequireComponent(typeof(Sequence))]
public class FungusCommand : MonoBehaviour
{
[HideInInspector]
public string errorMessage = "";
[HideInInspector]
public FungusScript parentFungusScript;
[HideInInspector]
public Sequence parentSequence;
[HideInInspector]
public bool expanded;
public virtual void Start()
{
parentSequence = GetComponent<Sequence>();
parentFungusScript = GetFungusScript();
}
public FungusScript GetFungusScript()
{
FungusScript sc = null;
Transform parent = transform.parent;
while (parent != null)
{
sc = parent.gameObject.GetComponent<FungusScript>();
if (sc != null)
{
break;
}
parent = parent.transform.parent;
}
return sc;
}
public bool IsExecuting()
{
if (parentSequence == null)
{
return false;
}
return (parentSequence.activeCommand == this);
}
public virtual void Execute()
{
OnEnter();
}
public virtual void Continue()
{
OnExit();
parentSequence.ExecuteNextCommand(this);
}
public virtual void Stop()
{
OnExit();
parentSequence.Stop();
}
public virtual void ExecuteSequence(Sequence s)
{
OnExit();
parentSequence.Stop();
parentFungusScript.ExecuteSequence(s);
}
public virtual void OnEnter()
{}
public virtual void OnExit()
{}
public virtual void GetConnectedSequences(ref List<Sequence> connectedSequences)
{}
public virtual string GetDescription()
{
return "";
}
}
}