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.
149 lines
2.5 KiB
149 lines
2.5 KiB
10 years ago
|
#if UNITY_EDITOR
|
||
10 years ago
|
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
|
{
|
||
10 years ago
|
|
||
10 years ago
|
public class CommandInfoAttribute : Attribute
|
||
10 years ago
|
{
|
||
10 years ago
|
public CommandInfoAttribute(string category, string commandName, string helpText)
|
||
10 years ago
|
{
|
||
10 years ago
|
this.Category = category;
|
||
|
this.CommandName = commandName;
|
||
10 years ago
|
this.HelpText = helpText;
|
||
|
}
|
||
|
|
||
10 years ago
|
public string Category { get; set; }
|
||
10 years ago
|
public string CommandName { get; set; }
|
||
|
public string HelpText { get; set; }
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
[RequireComponent(typeof(Sequence))]
|
||
10 years ago
|
public class Command : MonoBehaviour
|
||
10 years ago
|
{
|
||
|
[HideInInspector]
|
||
|
public string errorMessage = "";
|
||
|
|
||
|
[HideInInspector]
|
||
10 years ago
|
public FungusScript parentFungusScript;
|
||
10 years ago
|
|
||
|
[HideInInspector]
|
||
|
public Sequence parentSequence;
|
||
|
|
||
10 years ago
|
[HideInInspector]
|
||
|
public int indentLevel;
|
||
|
|
||
10 years ago
|
public virtual void Start()
|
||
|
{
|
||
|
parentSequence = GetComponent<Sequence>();
|
||
10 years ago
|
parentFungusScript = 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
|
if (sc != null)
|
||
10 years ago
|
{
|
||
|
break;
|
||
|
}
|
||
10 years ago
|
parent = parent.transform.parent;
|
||
10 years ago
|
}
|
||
10 years ago
|
return sc;
|
||
10 years ago
|
}
|
||
|
|
||
|
public bool IsExecuting()
|
||
|
{
|
||
|
if (parentSequence == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return (parentSequence.activeCommand == this);
|
||
|
}
|
||
|
|
||
|
public virtual void Execute()
|
||
|
{
|
||
|
OnEnter();
|
||
|
}
|
||
|
|
||
10 years ago
|
public virtual void Continue()
|
||
10 years ago
|
{
|
||
|
Continue(this);
|
||
|
}
|
||
|
|
||
10 years ago
|
public virtual void Continue(Command currentCommand)
|
||
10 years ago
|
{
|
||
|
OnExit();
|
||
10 years ago
|
parentSequence.ExecuteNextCommand(currentCommand);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public virtual void Stop()
|
||
|
{
|
||
|
OnExit();
|
||
|
parentSequence.Stop();
|
||
|
}
|
||
|
|
||
10 years ago
|
public virtual void ExecuteSequence(Sequence s)
|
||
|
{
|
||
|
OnExit();
|
||
10 years ago
|
parentSequence.Stop();
|
||
10 years ago
|
parentFungusScript.ExecuteSequence(s);
|
||
10 years ago
|
}
|
||
|
|
||
|
public virtual void OnEnter()
|
||
|
{}
|
||
|
|
||
|
public virtual void OnExit()
|
||
|
{}
|
||
|
|
||
|
public virtual void GetConnectedSequences(ref List<Sequence> connectedSequences)
|
||
|
{}
|
||
10 years ago
|
|
||
|
public virtual bool HasReference(FungusVariable variable)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public virtual string GetSummary()
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
public virtual string GetHelpText()
|
||
10 years ago
|
{
|
||
10 years ago
|
return "";
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
/**
|
||
|
* Indent offset for this command.
|
||
|
*/
|
||
|
public virtual int GetPreIndent()
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Indent offset for subsequent commands.
|
||
|
*/
|
||
|
public virtual int GetPostIndent()
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
10 years ago
|
|
||
|
public virtual Color GetButtonColor()
|
||
|
{
|
||
|
return Color.white;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|