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.
104 lines
2.8 KiB
104 lines
2.8 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
|
using System;
|
||
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Scope types for Variables.
|
||
|
/// </summary>
|
||
8 years ago
|
public enum VariableScope
|
||
|
{
|
||
|
Private,
|
||
|
Public
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Attribute class for variables.
|
||
|
/// </summary>
|
||
8 years ago
|
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; }
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Attribute class for variable properties.
|
||
|
/// </summary>
|
||
8 years ago
|
public class VariablePropertyAttribute : PropertyAttribute
|
||
|
{
|
||
|
public VariablePropertyAttribute (params System.Type[] variableTypes)
|
||
|
{
|
||
|
this.VariableTypes = variableTypes;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public VariablePropertyAttribute (string defaultText, params System.Type[] variableTypes)
|
||
|
{
|
||
|
this.defaultText = defaultText;
|
||
|
this.VariableTypes = variableTypes;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public String defaultText = "<None>";
|
||
9 years ago
|
|
||
8 years ago
|
public Type[] VariableTypes { get; set; }
|
||
8 years ago
|
}
|
||
10 years ago
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Abstract base class for variables.
|
||
|
/// </summary>
|
||
8 years ago
|
[RequireComponent(typeof(Flowchart))]
|
||
8 years ago
|
public abstract class Variable : MonoBehaviour, IVariable
|
||
8 years ago
|
{
|
||
8 years ago
|
[SerializeField] protected VariableScope scope;
|
||
|
|
||
|
[SerializeField] protected string key = "";
|
||
8 years ago
|
|
||
|
#region IVariable implementation
|
||
|
|
||
|
public virtual VariableScope Scope { get { return scope; } }
|
||
|
|
||
8 years ago
|
public virtual string Key { get { return key; } set { key = value; } }
|
||
10 years ago
|
|
||
8 years ago
|
public abstract void OnReset();
|
||
8 years ago
|
|
||
|
#endregion
|
||
8 years ago
|
}
|
||
10 years ago
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Generic concrete base class for variables.
|
||
|
/// </summary>
|
||
8 years ago
|
public abstract class VariableBase<T> : Variable
|
||
|
{
|
||
8 years ago
|
[SerializeField] protected T value;
|
||
8 years ago
|
public virtual T Value { get { return this.value; } set { this.value = value; } }
|
||
8 years ago
|
|
||
|
protected T startValue;
|
||
10 years ago
|
|
||
8 years ago
|
public override void OnReset()
|
||
|
{
|
||
8 years ago
|
Value = startValue;
|
||
8 years ago
|
}
|
||
|
|
||
|
public override string ToString()
|
||
|
{
|
||
8 years ago
|
return Value.ToString();
|
||
8 years ago
|
}
|
||
|
|
||
|
protected virtual void Start()
|
||
|
{
|
||
|
// Remember the initial value so we can reset later on
|
||
8 years ago
|
startValue = Value;
|
||
8 years ago
|
}
|
||
|
}
|
||
10 years ago
|
}
|