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.
66 lines
1.3 KiB
66 lines
1.3 KiB
10 years ago
|
using UnityEngine;
|
||
10 years ago
|
using System.Collections;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
|
|
||
10 years ago
|
[AddComponentMenu("")]
|
||
10 years ago
|
public class CommandCopyBuffer : Block
|
||
10 years ago
|
{
|
||
|
protected static CommandCopyBuffer instance;
|
||
|
|
||
|
/**
|
||
|
* Returns the CommandCopyBuffer singleton instance.
|
||
|
* Will create a CommandCopyBuffer game object if none currently exists.
|
||
|
*/
|
||
|
static public CommandCopyBuffer GetInstance()
|
||
|
{
|
||
|
if (instance == null)
|
||
|
{
|
||
|
// Static variables are not serialized (e.g. when playing in the editor)
|
||
|
// We need to reaquire the static reference to the game object in this case
|
||
|
GameObject go = GameObject.Find("_CommandCopyBuffer");
|
||
10 years ago
|
if (go == null)
|
||
10 years ago
|
{
|
||
10 years ago
|
go = new GameObject("_CommandCopyBuffer");
|
||
|
go.hideFlags = HideFlags.HideAndDontSave;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
instance = go.GetComponent<CommandCopyBuffer>();
|
||
|
if (instance == null)
|
||
10 years ago
|
{
|
||
|
instance = go.AddComponent<CommandCopyBuffer>();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return instance;
|
||
|
}
|
||
|
|
||
10 years ago
|
protected virtual void Start()
|
||
10 years ago
|
{
|
||
|
if (Application.isPlaying)
|
||
|
{
|
||
|
Destroy(this.gameObject);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public virtual bool HasCommands()
|
||
|
{
|
||
|
return GetCommands().Length > 0;
|
||
|
}
|
||
|
|
||
|
public virtual Command[] GetCommands()
|
||
|
{
|
||
|
return GetComponents<Command>();
|
||
|
}
|
||
|
|
||
|
public virtual void Clear()
|
||
|
{
|
||
|
foreach (Command command in GetCommands())
|
||
|
{
|
||
|
DestroyImmediate(command);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|