// 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) using UnityEngine; using System; namespace Fungus { /// /// Standard comparison operators. /// public enum CompareOperator { /// == mathematical operator. Equals, /// != mathematical operator. NotEquals, /// < mathematical operator. LessThan, /// > mathematical operator. GreaterThan, /// <= mathematical operator. LessThanOrEquals, /// >= mathematical operator. GreaterThanOrEquals } /// /// Scope types for Variables. /// public enum VariableScope { /// Can only be accessed by commands in the same Flowchart. Private, /// Can be accessed from any command in any Flowchart. Public } /// /// Attribute class for variables. /// public class VariableInfoAttribute : Attribute { public VariableInfoAttribute(string category, string variableType, int order = 0) { this.Category = category; this.VariableType = variableType; this.Order = order; } public string Category { get; set; } public string VariableType { get; set; } public int Order { get; set; } } /// /// Attribute class for variable properties. /// public class VariablePropertyAttribute : PropertyAttribute { public VariablePropertyAttribute (params System.Type[] variableTypes) { this.VariableTypes = variableTypes; } public VariablePropertyAttribute (string defaultText, params System.Type[] variableTypes) { this.defaultText = defaultText; this.VariableTypes = variableTypes; } public String defaultText = ""; public Type[] VariableTypes { get; set; } } /// /// Abstract base class for variables. /// [RequireComponent(typeof(Flowchart))] public abstract class Variable : MonoBehaviour { [SerializeField] protected VariableScope scope; [SerializeField] protected string key = ""; #region Public methods /// /// Visibility scope for the variable. /// public virtual VariableScope Scope { get { return scope; } } /// /// String identifier for the variable. /// public virtual string Key { get { return key; } set { key = value; } } /// /// Callback to reset the variable if the Flowchart is reset. /// public abstract void OnReset(); #endregion } /// /// Generic concrete base class for variables. /// public abstract class VariableBase : Variable { [SerializeField] protected T value; public virtual T Value { get { return this.value; } set { this.value = value; } } protected T startValue; public override void OnReset() { Value = startValue; } public override string ToString() { return Value.ToString(); } protected virtual void Start() { // Remember the initial value so we can reset later on startValue = Value; } } }