Browse Source

Added protected & virtual to core classes for easier inheritance

master
chrisgregan 10 years ago
parent
commit
53d2fd1aab
  1. 4
      Assets/Fungus/FungusScript/Editor/CallEditor.cs
  2. 4
      Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs
  3. 19
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  4. 26
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  5. 14
      Assets/Fungus/FungusScript/Editor/IfEditor.cs
  6. 10
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  7. 16
      Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs
  8. 2
      Assets/Fungus/FungusScript/Editor/VariableEditor.cs
  9. 2
      Assets/Fungus/FungusScript/Editor/VariableListAdaptor.cs
  10. 8
      Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs
  11. 9
      Assets/Fungus/FungusScript/Scripts/Command.cs
  12. 8
      Assets/Fungus/FungusScript/Scripts/FloatVariable.cs
  13. 28
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  14. 8
      Assets/Fungus/FungusScript/Scripts/GlobalVariables.cs
  15. 8
      Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs
  16. 10
      Assets/Fungus/FungusScript/Scripts/SceneLoader.cs
  17. 16
      Assets/Fungus/FungusScript/Scripts/Sequence.cs
  18. 8
      Assets/Fungus/FungusScript/Scripts/StringVariable.cs
  19. 4
      Assets/Fungus/FungusScript/Scripts/StringsParser.cs

4
Assets/Fungus/FungusScript/Editor/CallEditor.cs

@ -8,9 +8,9 @@ namespace Fungus
[CustomEditor (typeof(Call))]
public class CallEditor : CommandEditor
{
SerializedProperty targetSequenceProp;
protected SerializedProperty targetSequenceProp;
void OnEnable()
protected virtual void OnEnable()
{
targetSequenceProp = serializedObject.FindProperty("targetSequence");
}

4
Assets/Fungus/FungusScript/Editor/CommandListAdaptor.cs

@ -13,14 +13,14 @@ namespace Fungus
{
public class CommandListAdaptor : IReorderableListAdaptor {
private class SetCommandOperation
protected class SetCommandOperation
{
public Sequence sequence;
public Type commandType;
public int index;
}
private SerializedProperty _arrayProperty;
protected SerializedProperty _arrayProperty;
public float fixedItemHeight;

19
Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs

@ -10,12 +10,12 @@ namespace Fungus
[CustomEditor (typeof(FungusScript))]
public class FungusScriptEditor : Editor
{
SerializedProperty startSequenceProp;
SerializedProperty executeOnStartProp;
SerializedProperty settingsProp;
SerializedProperty variablesProp;
protected SerializedProperty startSequenceProp;
protected SerializedProperty executeOnStartProp;
protected SerializedProperty settingsProp;
protected SerializedProperty variablesProp;
void OnEnable()
protected virtual void OnEnable()
{
startSequenceProp = serializedObject.FindProperty("startSequence");
executeOnStartProp = serializedObject.FindProperty("executeOnStart");
@ -23,11 +23,6 @@ namespace Fungus
variablesProp = serializedObject.FindProperty("variables");
}
public void OnInspectorUpdate()
{
Repaint();
}
public override void OnInspectorGUI()
{
serializedObject.Update();
@ -91,7 +86,7 @@ namespace Fungus
serializedObject.ApplyModifiedProperties();
}
public void DrawVariablesGUI()
public virtual void DrawVariablesGUI()
{
FungusScript t = target as FungusScript;
@ -117,7 +112,7 @@ namespace Fungus
GUILayout.EndHorizontal();
}
void AddVariable<T>(object obj) where T : Variable
protected virtual void AddVariable<T>(object obj) where T : Variable
{
FungusScript fungusScript = obj as FungusScript;
if (fungusScript == null)

26
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -8,15 +8,15 @@ namespace Fungus
{
public class FungusScriptWindow : EditorWindow
{
bool resize = false;
Rect cursorChangeRect;
protected bool resize = false;
protected Rect cursorChangeRect;
public const float minViewWidth = 350;
static bool locked = false;
static GUIStyle lockButtonStyle;
static FungusScript activeFungusScript;
private List<Sequence> windowSequenceMap = new List<Sequence>();
protected List<Sequence> windowSequenceMap = new List<Sequence>();
[MenuItem("Window/Fungus Script")]
static void Init()
@ -41,7 +41,7 @@ namespace Fungus
// Implementing this method causes the padlock image to display on the window
// https://leahayes.wordpress.com/2013/04/30/adding-the-little-padlock-button-to-your-editorwindow/#more-455
void ShowButton(Rect position) {
protected virtual void ShowButton(Rect position) {
if (lockButtonStyle == null)
{
lockButtonStyle = "IN LockButton";
@ -49,7 +49,7 @@ namespace Fungus
locked = GUI.Toggle(position, locked, GUIContent.none, lockButtonStyle);
}
public void OnInspectorUpdate()
public virtual void OnInspectorUpdate()
{
Repaint();
}
@ -72,7 +72,7 @@ namespace Fungus
return null;
}
void OnGUI()
protected virtual void OnGUI()
{
FungusScript fungusScript = GetFungusScript();
if (fungusScript == null)
@ -94,7 +94,7 @@ namespace Fungus
GUILayout.EndHorizontal();
}
void DrawScriptView(FungusScript fungusScript)
protected virtual void DrawScriptView(FungusScript fungusScript)
{
EditorUtility.SetDirty(fungusScript);
@ -184,7 +184,7 @@ namespace Fungus
GLDraw.EndScrollView();
}
void ResizeViews(FungusScript fungusScript)
protected virtual void ResizeViews(FungusScript fungusScript)
{
cursorChangeRect = new Rect(this.position.width - fungusScript.commandViewWidth, 0, 4f, this.position.height);
@ -209,7 +209,7 @@ namespace Fungus
}
}
void DrawSequenceView(FungusScript fungusScript)
protected virtual void DrawSequenceView(FungusScript fungusScript)
{
GUILayout.Space(5);
@ -282,7 +282,7 @@ namespace Fungus
GUILayout.EndScrollView();
}
void CreateSequenceCallback(object item)
protected virtual void CreateSequenceCallback(object item)
{
FungusScript fungusScript = GetFungusScript();
if (fungusScript != null)
@ -295,7 +295,7 @@ namespace Fungus
}
}
void DrawWindow(int windowId)
protected virtual void DrawWindow(int windowId)
{
// Select sequence when node is clicked
if (!Application.isPlaying &&
@ -333,7 +333,7 @@ namespace Fungus
GUI.DragWindow();
}
void DrawConnections(FungusScript fungusScript, Sequence sequence, bool highlightedOnly)
protected virtual void DrawConnections(FungusScript fungusScript, Sequence sequence, bool highlightedOnly)
{
if (sequence == null)
{
@ -372,7 +372,7 @@ namespace Fungus
}
}
void DrawRectConnection(Rect rectA, Rect rectB, bool highlight)
protected virtual void DrawRectConnection(Rect rectA, Rect rectB, bool highlight)
{
Vector2 pointA;
Vector2 pointB;

14
Assets/Fungus/FungusScript/Editor/IfEditor.cs

@ -10,14 +10,14 @@ namespace Fungus
[CustomEditor (typeof(If))]
public class IfEditor : CommandEditor
{
SerializedProperty variableProp;
SerializedProperty compareOperatorProp;
SerializedProperty booleanValueProp;
SerializedProperty integerValueProp;
SerializedProperty floatValueProp;
SerializedProperty stringValueProp;
protected SerializedProperty variableProp;
protected SerializedProperty compareOperatorProp;
protected SerializedProperty booleanValueProp;
protected SerializedProperty integerValueProp;
protected SerializedProperty floatValueProp;
protected SerializedProperty stringValueProp;
void OnEnable()
protected virtual void OnEnable()
{
variableProp = serializedObject.FindProperty("variable");
compareOperatorProp = serializedObject.FindProperty("compareOperator");

10
Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

@ -12,15 +12,15 @@ namespace Fungus
[CustomEditor (typeof(Sequence))]
public class SequenceEditor : Editor
{
SerializedProperty sequenceNameProp;
SerializedProperty descriptionProp;
protected SerializedProperty sequenceNameProp;
protected SerializedProperty descriptionProp;
void OnEnable()
public virtual void OnEnable()
{
descriptionProp = serializedObject.FindProperty("description");
}
public void DrawSequenceGUI(FungusScript fungusScript)
public virtual void DrawSequenceGUI(FungusScript fungusScript)
{
if (fungusScript.selectedSequence == null)
{
@ -82,7 +82,7 @@ namespace Fungus
serializedObject.ApplyModifiedProperties();
}
void UpdateIndentLevels(Sequence sequence)
protected virtual void UpdateIndentLevels(Sequence sequence)
{
int indentLevel = 0;
foreach(Command command in sequence.commandList)

16
Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs

@ -9,14 +9,14 @@ namespace Fungus
[CustomEditor (typeof(SetVariable))]
public class SetVariableEditor : CommandEditor
{
SerializedProperty variableProp;
SerializedProperty setOperatorProp;
SerializedProperty booleanDataProp;
SerializedProperty integerDataProp;
SerializedProperty floatDataProp;
SerializedProperty stringDataProp;
void OnEnable()
protected SerializedProperty variableProp;
protected SerializedProperty setOperatorProp;
protected SerializedProperty booleanDataProp;
protected SerializedProperty integerDataProp;
protected SerializedProperty floatDataProp;
protected SerializedProperty stringDataProp;
protected virtual void OnEnable()
{
variableProp = serializedObject.FindProperty("variable");
setOperatorProp = serializedObject.FindProperty("setOperator");

2
Assets/Fungus/FungusScript/Editor/VariableEditor.cs

@ -11,7 +11,7 @@ namespace Fungus
[CustomEditor (typeof(Variable), true)]
public class VariableEditor : CommandEditor
{
void OnEnable()
protected virtual void OnEnable()
{
Variable t = target as Variable;
t.hideFlags = HideFlags.HideInInspector;

2
Assets/Fungus/FungusScript/Editor/VariableListAdaptor.cs

@ -11,7 +11,7 @@ namespace Fungus
{
public class VariableListAdaptor : IReorderableListAdaptor {
private SerializedProperty _arrayProperty;
protected SerializedProperty _arrayProperty;
public float fixedItemHeight;

8
Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs

@ -7,7 +7,7 @@ namespace Fungus
public class BooleanVariable : Variable
{
bool booleanValue;
protected bool booleanValue;
public bool Value
{
@ -20,10 +20,10 @@ namespace Fungus
public class BooleanData
{
[SerializeField]
BooleanVariable booleanReference;
protected BooleanVariable booleanReference;
[SerializeField]
bool booleanValue;
protected bool booleanValue;
public bool Value
{
@ -31,7 +31,7 @@ namespace Fungus
set { if (booleanReference == null) { booleanValue = value; } else { booleanReference.Value = value; } }
}
public string GetDescription()
public virtual string GetDescription()
{
if (booleanReference == null)
{

9
Assets/Fungus/FungusScript/Scripts/Command.cs

@ -1,6 +1,3 @@
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using System;
using System.Collections;
@ -32,12 +29,12 @@ namespace Fungus
[HideInInspector]
public int indentLevel;
public Sequence GetSequence()
public virtual Sequence GetSequence()
{
return gameObject.GetComponent<Sequence>();
}
public FungusScript GetFungusScript()
public virtual FungusScript GetFungusScript()
{
Sequence s = GetSequence();
if (s == null)
@ -48,7 +45,7 @@ namespace Fungus
return s.GetFungusScript();
}
public bool IsExecuting()
public virtual bool IsExecuting()
{
Sequence sequence = GetSequence();
if (sequence == null)

8
Assets/Fungus/FungusScript/Scripts/FloatVariable.cs

@ -6,7 +6,7 @@ namespace Fungus
public class FloatVariable : Variable
{
float floatValue;
protected float floatValue;
public float Value
{
@ -19,10 +19,10 @@ namespace Fungus
public class FloatData
{
[SerializeField]
FloatVariable floatReference;
protected FloatVariable floatReference;
[SerializeField]
float floatValue;
protected float floatValue;
public float Value
{
@ -30,7 +30,7 @@ namespace Fungus
set { if (floatReference == null) { floatValue = value; } else { floatReference.Value = value; } }
}
public string GetDescription()
public virtual string GetDescription()
{
if (floatReference == null)
{

28
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -109,7 +109,7 @@ namespace Fungus
[Tooltip("Advanced configuration options for the Fungus Script")]
public Settings settings;
void Start()
protected virtual void Start()
{
if (executeOnStart)
{
@ -120,7 +120,7 @@ namespace Fungus
/**
* Create a new sequence node which you can then add commands to.
*/
public Sequence CreateSequence(Vector2 position)
public virtual Sequence CreateSequence(Vector2 position)
{
GameObject go = new GameObject("Sequence");
go.transform.parent = transform;
@ -134,7 +134,7 @@ namespace Fungus
/**
* Start running the Fungus Script by executing the startSequence.
*/
public void Execute()
public virtual void Execute()
{
if (startSequence == null)
{
@ -147,7 +147,7 @@ namespace Fungus
/**
* Start running the Fungus Script by executing a specific child sequence.
*/
public void ExecuteSequence(Sequence sequence)
public virtual void ExecuteSequence(Sequence sequence)
{
// Sequence must be a child of the parent Fungus Script
if (sequence == null ||
@ -164,7 +164,7 @@ namespace Fungus
/**
* Returns a new variable key that is guaranteed not to clash with any existing variable in the list.
*/
public string GetUniqueVariableKey(string originalKey, Variable ignoreVariable = null)
public virtual string GetUniqueVariableKey(string originalKey, Variable ignoreVariable = null)
{
int suffix = 0;
string baseKey = originalKey;
@ -213,7 +213,7 @@ namespace Fungus
* Gets the value of a boolean variable.
* Returns false if the variable key does not exist.
*/
public bool GetBooleanVariable(string key)
public virtual bool GetBooleanVariable(string key)
{
foreach (Variable v in variables)
{
@ -234,7 +234,7 @@ namespace Fungus
* Sets the value of a boolean variable.
* The variable must already be added to the list of variables for this Fungus Script.
*/
public void SetBooleanVariable(string key, bool value)
public virtual void SetBooleanVariable(string key, bool value)
{
foreach (Variable v in variables)
{
@ -255,7 +255,7 @@ namespace Fungus
* Gets the value of an integer variable.
* Returns false if the variable key does not exist.
*/
public int GetIntegerVariable(string key)
public virtual int GetIntegerVariable(string key)
{
foreach (Variable v in variables)
{
@ -276,7 +276,7 @@ namespace Fungus
* Sets the value of an integer variable.
* The variable must already be added to the list of variables for this Fungus Script.
*/
public void SetIntegerVariable(string key, int value)
public virtual void SetIntegerVariable(string key, int value)
{
foreach (Variable v in variables)
{
@ -297,7 +297,7 @@ namespace Fungus
* Gets the value of a float variable.
* Returns false if the variable key does not exist.
*/
public float GetFloatVariable(string key)
public virtual float GetFloatVariable(string key)
{
foreach (Variable v in variables)
{
@ -318,7 +318,7 @@ namespace Fungus
* Sets the value of a float variable.
* The variable must already be added to the list of variables for this Fungus Script.
*/
public void SetFloatVariable(string key, float value)
public virtual void SetFloatVariable(string key, float value)
{
foreach (Variable v in variables)
{
@ -339,7 +339,7 @@ namespace Fungus
* Gets the value of a string variable.
* Returns false if the variable key does not exist.
*/
public string GetStringVariable(string key)
public virtual string GetStringVariable(string key)
{
foreach (Variable v in variables)
{
@ -360,7 +360,7 @@ namespace Fungus
* Sets the value of a string variable.
* The variable must already be added to the list of variables for this Fungus Script.
*/
public void SetStringVariable(string key, string value)
public virtual void SetStringVariable(string key, string value)
{
foreach (Variable v in variables)
{
@ -380,7 +380,7 @@ namespace Fungus
/**
* Set the sequence objects to be hidden or visible depending on the showSequenceObjects property.
*/
public void UpdateHideFlags()
public virtual void UpdateHideFlags()
{
Sequence[] sequences = GetComponentsInChildren<Sequence>();
foreach (Sequence sequence in sequences)

8
Assets/Fungus/FungusScript/Scripts/GlobalVariables.cs

@ -16,10 +16,10 @@ namespace Fungus
*/
public class GlobalVariables
{
static Dictionary<string, string> stringDict = new Dictionary<string, string>();
static Dictionary<string, int> intDict = new Dictionary<string, int>();
static Dictionary<string, float> floatDict = new Dictionary<string, float>();
static Dictionary<string, bool> boolDict = new Dictionary<string, bool>();
protected static Dictionary<string, string> stringDict = new Dictionary<string, string>();
protected static Dictionary<string, int> intDict = new Dictionary<string, int>();
protected static Dictionary<string, float> floatDict = new Dictionary<string, float>();
protected static Dictionary<string, bool> boolDict = new Dictionary<string, bool>();
/**
* Save the variable dictionaries to persistent storage using a name tag.

8
Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs

@ -6,7 +6,7 @@ namespace Fungus
public class IntegerVariable : Variable
{
int integerValue;
protected int integerValue;
public int Value
{
@ -19,10 +19,10 @@ namespace Fungus
public class IntegerData
{
[SerializeField]
IntegerVariable integerReference;
protected IntegerVariable integerReference;
[SerializeField]
int integerValue;
protected int integerValue;
public int Value
{
@ -30,7 +30,7 @@ namespace Fungus
set { if (integerReference == null) { integerValue = value; } else { integerReference.Value = value; } }
}
public string GetDescription()
public virtual string GetDescription()
{
if (integerReference == null)
{

10
Assets/Fungus/FungusScript/Scripts/SceneLoader.cs

@ -12,9 +12,9 @@ namespace Fungus
*/
public class SceneLoader : MonoBehaviour
{
Texture2D loadingTexture;
string sceneToLoad;
bool displayedImage;
protected Texture2D loadingTexture;
protected string sceneToLoad;
protected bool displayedImage;
/**
* Asynchronously load a new scene.
@ -32,7 +32,7 @@ namespace Fungus
sceneLoader.loadingTexture = _loadingTexture;
}
void Start()
protected virtual void Start()
{
StartCoroutine(DoLoadSequence());
}
@ -77,7 +77,7 @@ namespace Fungus
Destroy(gameObject);
}
void OnGUI()
protected virtual void OnGUI()
{
if (loadingTexture == null)
{

16
Assets/Fungus/FungusScript/Scripts/Sequence.cs

@ -21,14 +21,14 @@ namespace Fungus
public List<Command> commandList = new List<Command>();
int executionCount;
protected int executionCount;
public FungusScript GetFungusScript()
public virtual FungusScript GetFungusScript()
{
return GetComponentInParent<FungusScript>();
}
public bool HasError()
public virtual bool HasError()
{
foreach (Command command in commandList)
{
@ -41,7 +41,7 @@ namespace Fungus
return false;
}
public bool IsRunning()
public virtual bool IsRunning()
{
FungusScript fungusScript = GetFungusScript();
@ -54,12 +54,12 @@ namespace Fungus
return (fungusScript.executingSequence == this);
}
public int GetExecutionCount()
public virtual int GetExecutionCount()
{
return executionCount;
}
public void ExecuteNextCommand(Command currentCommand = null)
public virtual void ExecuteNextCommand(Command currentCommand = null)
{
if (currentCommand == null)
{
@ -114,7 +114,7 @@ namespace Fungus
command.Execute();
}
public void Stop()
public virtual void Stop()
{
FungusScript fungusScript = GetFungusScript();
if (fungusScript == null)
@ -128,7 +128,7 @@ namespace Fungus
fungusScript.selectedCommand = null;
}
public List<Sequence> GetConnectedSequences()
public virtual List<Sequence> GetConnectedSequences()
{
List<Sequence> connectedSequences = new List<Sequence>();
foreach (Command command in commandList)

8
Assets/Fungus/FungusScript/Scripts/StringVariable.cs

@ -6,7 +6,7 @@ namespace Fungus
public class StringVariable : Variable
{
string stringValue;
protected string stringValue;
public string Value
{
@ -19,10 +19,10 @@ namespace Fungus
public class StringData
{
[SerializeField]
StringVariable stringReference;
protected StringVariable stringReference;
[SerializeField]
string stringValue;
protected string stringValue;
public string Value
{
@ -30,7 +30,7 @@ namespace Fungus
set { if (stringReference == null) { stringValue = value; } else { stringReference.Value = value; } }
}
public string GetDescription()
public virtual string GetDescription()
{
if (stringReference == null)
{

4
Assets/Fungus/FungusScript/Scripts/StringsParser.cs

@ -25,12 +25,12 @@ namespace Fungus
Text,
};
void Start()
public virtual void Start()
{
ProcessText(stringsFile.text);
}
void ProcessText(string text)
protected virtual void ProcessText(string text)
{
// Split text into lines. Add a newline at end to ensure last command is always parsed
string[] lines = Regex.Split(text + "\n", "(?<=\n)");

Loading…
Cancel
Save