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.
121 lines
2.3 KiB
121 lines
2.3 KiB
11 years ago
|
using UnityEngine;
|
||
11 years ago
|
using System;
|
||
11 years ago
|
using System.Linq;
|
||
11 years ago
|
using System.Collections;
|
||
11 years ago
|
using System.Collections.Generic;
|
||
11 years ago
|
|
||
11 years ago
|
namespace Fungus.Script
|
||
11 years ago
|
{
|
||
|
|
||
11 years ago
|
public class FungusScript : MonoBehaviour
|
||
|
{
|
||
|
[System.NonSerialized]
|
||
11 years ago
|
public Sequence executingSequence;
|
||
11 years ago
|
|
||
11 years ago
|
[System.NonSerialized]
|
||
|
public FungusCommand copyCommand;
|
||
|
|
||
11 years ago
|
[HideInInspector]
|
||
|
public int selectedCommandIndex;
|
||
|
|
||
11 years ago
|
[HideInInspector]
|
||
|
public Vector2 scrollPos;
|
||
|
|
||
11 years ago
|
public float stepTime;
|
||
|
|
||
|
public Sequence startSequence;
|
||
|
|
||
11 years ago
|
public Sequence selectedSequence;
|
||
|
|
||
11 years ago
|
public bool startAutomatically = false;
|
||
|
|
||
11 years ago
|
public List<FungusVariable> variables = new List<FungusVariable>();
|
||
11 years ago
|
|
||
11 years ago
|
void Start()
|
||
|
{
|
||
|
if (startAutomatically)
|
||
|
{
|
||
|
Execute();
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
public Sequence CreateSequence(Vector2 position)
|
||
|
{
|
||
|
GameObject go = new GameObject("Sequence");
|
||
|
go.transform.parent = transform;
|
||
|
go.transform.hideFlags = HideFlags.HideInHierarchy;
|
||
|
Sequence s = go.AddComponent<Sequence>();
|
||
|
s.nodeRect.x = position.x;
|
||
|
s.nodeRect.y = position.y;
|
||
|
return s;
|
||
|
}
|
||
|
|
||
11 years ago
|
public void Execute()
|
||
11 years ago
|
{
|
||
11 years ago
|
if (startSequence == null)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
ExecuteSequence(startSequence);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
public void ExecuteSequence(Sequence sequence)
|
||
11 years ago
|
{
|
||
11 years ago
|
if (sequence == null)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
executingSequence = sequence;
|
||
11 years ago
|
selectedSequence = sequence;
|
||
11 years ago
|
sequence.ExecuteNextCommand();
|
||
|
}
|
||
11 years ago
|
|
||
|
public string GetUniqueVariableKey(string originalKey, FungusVariable ignoreVariable = null)
|
||
|
{
|
||
|
int suffix = 0;
|
||
|
string baseKey = originalKey;
|
||
|
|
||
|
// Only letters and digits allowed
|
||
|
char[] arr = baseKey.Where(c => (char.IsLetterOrDigit(c) || c == '_')).ToArray();
|
||
|
baseKey = new string(arr);
|
||
|
|
||
|
// No leading digits allowed
|
||
|
baseKey = baseKey.TrimStart('0','1','2','3','4','5','6','7','8','9');
|
||
|
|
||
|
// No empty keys allowed
|
||
|
if (baseKey.Length == 0)
|
||
|
{
|
||
|
baseKey = "Var";
|
||
|
}
|
||
|
|
||
|
string key = baseKey;
|
||
|
while (true)
|
||
|
{
|
||
|
bool collision = false;
|
||
|
foreach(FungusVariable variable in GetComponents<FungusVariable>())
|
||
|
{
|
||
11 years ago
|
if (variable == ignoreVariable ||
|
||
|
variable.key == null)
|
||
11 years ago
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (variable.key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
|
||
|
{
|
||
|
collision = true;
|
||
|
suffix++;
|
||
|
key = baseKey + suffix;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!collision)
|
||
|
{
|
||
|
return key;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
}
|