|
|
@ -9,45 +9,88 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
public class FungusScript : MonoBehaviour |
|
|
|
public class FungusScript : MonoBehaviour |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Currently executing sequence. |
|
|
|
|
|
|
|
*/ |
|
|
|
[System.NonSerialized] |
|
|
|
[System.NonSerialized] |
|
|
|
public Sequence executingSequence; |
|
|
|
public Sequence executingSequence; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Copy and paste buffer for command objects. |
|
|
|
|
|
|
|
*/ |
|
|
|
[System.NonSerialized] |
|
|
|
[System.NonSerialized] |
|
|
|
public Command copyCommand; |
|
|
|
public Command copyCommand; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Scroll position of Fungus Script editor window (map view). |
|
|
|
|
|
|
|
*/ |
|
|
|
[HideInInspector] |
|
|
|
[HideInInspector] |
|
|
|
public Vector2 scriptScrollPos; |
|
|
|
public Vector2 scriptScrollPos; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Scroll position of Fungus Script editor window (command view). |
|
|
|
|
|
|
|
*/ |
|
|
|
[HideInInspector] |
|
|
|
[HideInInspector] |
|
|
|
public Vector2 commandScrollPos; |
|
|
|
public Vector2 commandScrollPos; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Current width of command view |
|
|
|
|
|
|
|
*/ |
|
|
|
[HideInInspector] |
|
|
|
[HideInInspector] |
|
|
|
public float commandViewWidth = 300; |
|
|
|
public float commandViewWidth = 350; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Execution speed when running the script in the editor. Pauses on each command to help visualise execution order. |
|
|
|
|
|
|
|
*/ |
|
|
|
public float stepTime; |
|
|
|
public float stepTime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* First sequence to execute when the Fungus Script executes. |
|
|
|
|
|
|
|
*/ |
|
|
|
public Sequence startSequence; |
|
|
|
public Sequence startSequence; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Currently selected sequence in the Fungus Script editor. |
|
|
|
|
|
|
|
*/ |
|
|
|
public Sequence selectedSequence; |
|
|
|
public Sequence selectedSequence; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Currently selected command in the Fungus Script editor. |
|
|
|
|
|
|
|
*/ |
|
|
|
public Command selectedCommand; |
|
|
|
public Command selectedCommand; |
|
|
|
|
|
|
|
|
|
|
|
public bool startAutomatically = true; |
|
|
|
/** |
|
|
|
|
|
|
|
* Execute this Fungus Script when the scene starts. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public bool executeOnStart = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Use command color when displaying command list in Fungus Editor window. |
|
|
|
|
|
|
|
*/ |
|
|
|
public bool colorCommands = true; |
|
|
|
public bool colorCommands = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Show the sequence game objects in the Hierarchy view. |
|
|
|
|
|
|
|
* This can be useful if you want to inspect the child gameobjects and components that make up the Fungus Script. |
|
|
|
|
|
|
|
*/ |
|
|
|
public bool showSequenceObjects = false; |
|
|
|
public bool showSequenceObjects = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The list of variables that can be accessed by the Fungus Script. |
|
|
|
|
|
|
|
*/ |
|
|
|
public List<Variable> variables = new List<Variable>(); |
|
|
|
public List<Variable> variables = new List<Variable>(); |
|
|
|
|
|
|
|
|
|
|
|
void Start() |
|
|
|
void Start() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (startAutomatically) |
|
|
|
if (executeOnStart) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Execute(); |
|
|
|
Execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a new sequence node which you can then add commands to. |
|
|
|
|
|
|
|
*/ |
|
|
|
public Sequence CreateSequence(Vector2 position) |
|
|
|
public Sequence CreateSequence(Vector2 position) |
|
|
|
{ |
|
|
|
{ |
|
|
|
GameObject go = new GameObject("Sequence"); |
|
|
|
GameObject go = new GameObject("Sequence"); |
|
|
@ -59,6 +102,9 @@ namespace Fungus |
|
|
|
return s; |
|
|
|
return s; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Start running the Fungus Script by executing the startSequence. |
|
|
|
|
|
|
|
*/ |
|
|
|
public void Execute() |
|
|
|
public void Execute() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (startSequence == null) |
|
|
|
if (startSequence == null) |
|
|
@ -69,9 +115,14 @@ namespace Fungus |
|
|
|
ExecuteSequence(startSequence); |
|
|
|
ExecuteSequence(startSequence); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Start running the Fungus Script by executing a specific child sequence. |
|
|
|
|
|
|
|
*/ |
|
|
|
public void ExecuteSequence(Sequence sequence) |
|
|
|
public void ExecuteSequence(Sequence sequence) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (sequence == null) |
|
|
|
// Sequence must be a child of the parent Fungus Script |
|
|
|
|
|
|
|
if (sequence == null || |
|
|
|
|
|
|
|
sequence.transform.parent != transform) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -81,6 +132,9 @@ namespace Fungus |
|
|
|
sequence.ExecuteNextCommand(); |
|
|
|
sequence.ExecuteNextCommand(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Returns a new variable key that is guaranteed not to clash with any existing variable in the list. |
|
|
|
|
|
|
|
*/ |
|
|
|
public string GetUniqueVariableKey(string originalKey, Variable ignoreVariable = null) |
|
|
|
public string GetUniqueVariableKey(string originalKey, Variable ignoreVariable = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int suffix = 0; |
|
|
|
int suffix = 0; |
|
|
@ -126,6 +180,9 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set the sequence objects to be hidden or visible depending on the showSequenceObjects property. |
|
|
|
|
|
|
|
*/ |
|
|
|
public void UpdateHideFlags() |
|
|
|
public void UpdateHideFlags() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Sequence[] sequences = GetComponentsInChildren<Sequence>(); |
|
|
|
Sequence[] sequences = GetComponentsInChildren<Sequence>(); |
|
|
|