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.
69 lines
2.1 KiB
69 lines
2.1 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
10 years ago
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Temporary buffer object used when copying and pasting commands.
|
||
|
/// </summary>
|
||
8 years ago
|
[AddComponentMenu("")]
|
||
|
public class CommandCopyBuffer : Block
|
||
|
{
|
||
|
protected static CommandCopyBuffer instance;
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Returns the CommandCopyBuffer singleton instance.
|
||
|
/// Will create a CommandCopyBuffer game object if none currently exists.
|
||
|
/// </summary>
|
||
8 years ago
|
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");
|
||
|
if (go == null)
|
||
|
{
|
||
|
go = new GameObject("_CommandCopyBuffer");
|
||
|
go.hideFlags = HideFlags.HideAndDontSave;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
instance = go.GetComponent<CommandCopyBuffer>();
|
||
|
if (instance == null)
|
||
|
{
|
||
|
instance = go.AddComponent<CommandCopyBuffer>();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return instance;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
protected virtual void Start()
|
||
|
{
|
||
|
if (Application.isPlaying)
|
||
|
{
|
||
|
Destroy(this.gameObject);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public virtual bool HasCommands()
|
||
|
{
|
||
|
return GetCommands().Length > 0;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public virtual Command[] GetCommands()
|
||
|
{
|
||
|
return GetComponents<Command>();
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public virtual void Clear()
|
||
|
{
|
||
|
foreach (Command command in GetCommands())
|
||
|
{
|
||
|
DestroyImmediate(command);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|