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.
79 lines
2.4 KiB
79 lines
2.4 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;
|
||
|
using UnityEngine.Serialization;
|
||
10 years ago
|
using System;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Attribute class for Fungus event handlers.
|
||
|
/// </summary>
|
||
8 years ago
|
public class EventHandlerInfoAttribute : Attribute
|
||
|
{
|
||
|
public EventHandlerInfoAttribute(string category, string eventHandlerName, string helpText)
|
||
|
{
|
||
|
this.Category = category;
|
||
|
this.EventHandlerName = eventHandlerName;
|
||
|
this.HelpText = helpText;
|
||
|
}
|
||
|
|
||
|
public string Category { get; set; }
|
||
|
public string EventHandlerName { get; set; }
|
||
|
public string HelpText { get; set; }
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// A Block may have an associated Event Handler which starts executing commands when
|
||
|
/// a specific event occurs.
|
||
|
/// To create a custom Event Handler, simply subclass EventHandler and call the ExecuteBlock() method
|
||
|
/// when the event occurs.
|
||
|
/// Add an EventHandlerInfo attibute and your new EventHandler class will automatically appear in the
|
||
|
/// 'Execute On Event' dropdown menu when a block is selected.
|
||
|
/// </summary>
|
||
8 years ago
|
[RequireComponent(typeof(Block))]
|
||
8 years ago
|
[RequireComponent(typeof(Flowchart))]
|
||
|
[AddComponentMenu("")]
|
||
8 years ago
|
public class EventHandler : MonoBehaviour, IEventHandler
|
||
8 years ago
|
{
|
||
|
[HideInInspector]
|
||
|
[FormerlySerializedAs("parentSequence")]
|
||
8 years ago
|
[SerializeField] protected Block parentBlock;
|
||
8 years ago
|
|
||
|
#region IEventHandler
|
||
|
|
||
8 years ago
|
public virtual Block ParentBlock { get { return parentBlock; } set { parentBlock = value; } }
|
||
10 years ago
|
|
||
8 years ago
|
public virtual bool ExecuteBlock()
|
||
|
{
|
||
8 years ago
|
if (ParentBlock == null)
|
||
8 years ago
|
{
|
||
|
return false;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
if (ParentBlock._EventHandler != this)
|
||
8 years ago
|
{
|
||
|
return false;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
var flowchart = ParentBlock.GetFlowchart();
|
||
10 years ago
|
|
||
8 years ago
|
// Auto-follow the executing block if none is currently selected
|
||
8 years ago
|
if (flowchart.SelectedBlock == null)
|
||
8 years ago
|
{
|
||
8 years ago
|
flowchart.SelectedBlock = ParentBlock;
|
||
8 years ago
|
}
|
||
10 years ago
|
|
||
8 years ago
|
return flowchart.ExecuteBlock(ParentBlock);
|
||
8 years ago
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public virtual string GetSummary()
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
8 years ago
|
|
||
|
#endregion
|
||
8 years ago
|
}
|
||
10 years ago
|
}
|