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.
200 lines
4.0 KiB
200 lines
4.0 KiB
10 years ago
|
using UnityEngine;
|
||
10 years ago
|
using System;
|
||
10 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
10 years ago
|
|
||
10 years ago
|
public class CommandInfoAttribute : Attribute
|
||
10 years ago
|
{
|
||
10 years ago
|
/**
|
||
|
* Metadata atribute for the Command class.
|
||
|
* @param category The category to place this command in.
|
||
|
* @param commandName The display name of the command.
|
||
|
* @param helpText Help information to display in the inspector.
|
||
|
* @param priority If two command classes have the same name, the one with highest priority is listed. Negative priority removess the command from the list.
|
||
|
*/
|
||
10 years ago
|
public CommandInfoAttribute(string category, string commandName, string helpText, int priority = 0)
|
||
10 years ago
|
{
|
||
10 years ago
|
this.Category = category;
|
||
|
this.CommandName = commandName;
|
||
10 years ago
|
this.HelpText = helpText;
|
||
10 years ago
|
this.Priority = priority;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public string Category { get; set; }
|
||
10 years ago
|
public string CommandName { get; set; }
|
||
|
public string HelpText { get; set; }
|
||
10 years ago
|
public int Priority { get; set; }
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public class Command : MonoBehaviour
|
||
10 years ago
|
{
|
||
10 years ago
|
[HideInInspector]
|
||
|
public int commandId = -1; // Invalid command id
|
||
|
|
||
10 years ago
|
[HideInInspector]
|
||
10 years ago
|
public string errorMessage = "";
|
||
|
|
||
10 years ago
|
[HideInInspector]
|
||
10 years ago
|
public int indentLevel;
|
||
|
|
||
10 years ago
|
[NonSerialized]
|
||
|
public int commandIndex;
|
||
|
|
||
10 years ago
|
/**
|
||
10 years ago
|
* Reference to the Block object that this command belongs to.
|
||
10 years ago
|
* This reference is only populated at runtime and in the editor when the
|
||
10 years ago
|
* block is selected.
|
||
10 years ago
|
*/
|
||
|
[NonSerialized]
|
||
10 years ago
|
public Block parentBlock;
|
||
10 years ago
|
|
||
10 years ago
|
public virtual Flowchart GetFlowchart()
|
||
10 years ago
|
{
|
||
10 years ago
|
Flowchart flowchart = GetComponent<Flowchart>();
|
||
|
if (flowchart == null &&
|
||
10 years ago
|
transform.parent != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
flowchart = transform.parent.GetComponent<Flowchart>();
|
||
10 years ago
|
}
|
||
10 years ago
|
return flowchart;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public virtual bool IsExecuting()
|
||
10 years ago
|
{
|
||
10 years ago
|
if (parentBlock == null)
|
||
10 years ago
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
10 years ago
|
return (parentBlock.activeCommand == this);
|
||
10 years ago
|
}
|
||
|
|
||
|
public virtual void Execute()
|
||
|
{
|
||
|
OnEnter();
|
||
|
}
|
||
|
|
||
10 years ago
|
public virtual void Continue()
|
||
10 years ago
|
{
|
||
10 years ago
|
Continue(commandIndex + 1);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public virtual void Continue(int nextCommandIndex)
|
||
10 years ago
|
{
|
||
|
OnExit();
|
||
10 years ago
|
if (parentBlock != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
parentBlock.ExecuteCommand(nextCommandIndex);
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public virtual void Stop()
|
||
|
{
|
||
|
OnExit();
|
||
10 years ago
|
if (parentBlock != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
parentBlock.Stop();
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public virtual void ExecuteBlock(Block s)
|
||
10 years ago
|
{
|
||
|
OnExit();
|
||
10 years ago
|
if (parentBlock != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
Flowchart flowchart = parentBlock.GetFlowchart();
|
||
10 years ago
|
|
||
10 years ago
|
// Record the currently selected block because Stop() will clear it.
|
||
|
Block selectedBlock = flowchart.selectedBlock;
|
||
10 years ago
|
|
||
10 years ago
|
parentBlock.Stop();
|
||
|
if (flowchart != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
// If the executing block is currently selected then follow the execution
|
||
|
// onto the next block in the inspector.
|
||
|
if (selectedBlock == parentBlock)
|
||
10 years ago
|
{
|
||
10 years ago
|
flowchart.selectedBlock = s;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
flowchart.ExecuteBlock(s);
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
/**
|
||
10 years ago
|
* Called when the new command is added to a block in the editor.
|
||
10 years ago
|
*/
|
||
10 years ago
|
public virtual void OnCommandAdded(Block parentBlock)
|
||
10 years ago
|
{}
|
||
|
|
||
10 years ago
|
/**
|
||
10 years ago
|
* Called when the command is deleted from a block in the editor.
|
||
10 years ago
|
*/
|
||
10 years ago
|
public virtual void OnCommandRemoved(Block parentBlock)
|
||
10 years ago
|
{}
|
||
|
|
||
10 years ago
|
public virtual void OnEnter()
|
||
|
{}
|
||
|
|
||
|
public virtual void OnExit()
|
||
|
{}
|
||
|
|
||
10 years ago
|
public virtual void OnReset()
|
||
|
{}
|
||
|
|
||
10 years ago
|
public virtual void GetConnectedBlocks(ref List<Block> connectedBlocks)
|
||
10 years ago
|
{}
|
||
10 years ago
|
|
||
10 years ago
|
public virtual bool HasReference(Variable variable)
|
||
10 years ago
|
{
|
||
|
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
|
|
||
|
/**
|
||
10 years ago
|
* This command starts a block of commands.
|
||
10 years ago
|
*/
|
||
10 years ago
|
public virtual bool OpenBlock()
|
||
10 years ago
|
{
|
||
10 years ago
|
return false;
|
||
10 years ago
|
}
|
||
|
|
||
|
/**
|
||
10 years ago
|
* This command ends a block of commands.
|
||
10 years ago
|
*/
|
||
10 years ago
|
public virtual bool CloseBlock()
|
||
10 years ago
|
{
|
||
10 years ago
|
return false;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
|
* Return the color for the command background in inspector.
|
||
|
*/
|
||
10 years ago
|
public virtual Color GetButtonColor()
|
||
|
{
|
||
|
return Color.white;
|
||
|
}
|
||
10 years ago
|
|
||
|
/**
|
||
10 years ago
|
* Adds a delay between commands if the 'Run Slow In Editor' option is enabled.
|
||
10 years ago
|
*/
|
||
|
public virtual bool RunSlowInEditor()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|