Browse Source

Merged Compare and Jump commands

master
chrisgregan 11 years ago
parent
commit
1f78a48a3b
  1. 138
      Assets/Fungus/Editor/FungusScript/CompareEditor.cs
  2. 8
      Assets/Fungus/Editor/FungusScript/CompareEditor.cs.meta
  3. 2
      Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs
  4. 30
      Assets/Fungus/Editor/FungusScript/JumpEditor.cs
  5. 2
      Assets/Fungus/Editor/FungusScript/JumpEditor.cs.meta
  6. 149
      Assets/Fungus/VisualScripting/Compare.cs
  7. 8
      Assets/Fungus/VisualScripting/Compare.cs.meta
  8. 5
      Assets/Fungus/VisualScripting/FungusCommand.cs
  9. 44
      Assets/Fungus/VisualScripting/Jump.cs
  10. 2
      Assets/Fungus/VisualScripting/Jump.cs.meta
  11. BIN
      Assets/Shuttle/ShuttleGame.unity

138
Assets/Fungus/Editor/FungusScript/CompareEditor.cs

@ -1,138 +0,0 @@
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[CustomEditor (typeof(Compare))]
public class CompareEditor : FungusCommandEditor
{
public override void DrawCommandInspectorGUI()
{
Compare t = target as Compare;
FungusScript sc = t.GetFungusScript();
if (sc == null)
{
return;
}
List<string> keys = new List<string>();
keys.Add("<None>");
int index = 0;
for (int i = 0; i < sc.variables.Count; ++i)
{
Variable v = sc.variables[i];
keys.Add(v.key);
if (v.key == t.variableKey &&
index == 0)
{
index = i + 1;
}
}
int newIndex = EditorGUILayout.Popup("Variable", index, keys.ToArray());
bool keyChanged = (t.variableKey != keys[newIndex]);
if (keyChanged)
{
Undo.RecordObject(t, "Select variable");
t.variableKey = keys[newIndex];
}
if (t.variableKey == "<None>")
{
return;
}
VariableType variableType = sc.variables[newIndex - 1].type;
List<GUIContent> operatorList = new List<GUIContent>();
operatorList.Add(new GUIContent("=="));
operatorList.Add(new GUIContent("!="));
if (variableType == VariableType.Integer ||
variableType == VariableType.Float)
{
operatorList.Add(new GUIContent("<"));
operatorList.Add(new GUIContent(">"));
operatorList.Add(new GUIContent("<="));
operatorList.Add(new GUIContent(">="));
}
CompareOperator compareOperator = (CompareOperator)EditorGUILayout.Popup(new GUIContent("Operator",
"The comparison operator to use when comparing values"),
(int)t.compareOperator,
operatorList.ToArray());
if (compareOperator != t.compareOperator)
{
Undo.RecordObject(t, "Select compare operator");
t.compareOperator = compareOperator;
}
bool booleanValue = t.booleanData.value;
int integerValue = t.integerData.value;
float floatValue = t.floatData.value;
string stringValue = t.stringData.value;
switch (variableType)
{
case VariableType.Boolean:
booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), booleanValue);
break;
case VariableType.Integer:
integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), integerValue);
break;
case VariableType.Float:
floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), floatValue);
break;
case VariableType.String:
stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), stringValue);
break;
}
if (booleanValue != t.booleanData.value)
{
Undo.RecordObject(t, "Set boolean value");
t.booleanData.value = booleanValue;
}
else if (integerValue != t.integerData.value)
{
Undo.RecordObject(t, "Set integer value");
t.integerData.value = integerValue;
}
else if (floatValue != t.floatData.value)
{
Undo.RecordObject(t, "Set float value");
t.floatData.value = floatValue;
}
else if (stringValue != t.stringData.value)
{
Undo.RecordObject(t, "Set string value");
t.stringData.value = stringValue;
}
Sequence onTrue = SequenceEditor.SequenceField(new GUIContent("On True Sequence", "Sequence to execute if comparision is true"),
t.GetFungusScript(),
t.onTrueSequence);
Sequence onFalse = SequenceEditor.SequenceField(new GUIContent("On False Sequence", "Sequence to execute if comparision is false"),
t.GetFungusScript(),
t.onFalseSequence);
if (onTrue != t.onTrueSequence)
{
Undo.RecordObject(t, "Set On True Sequence");
t.onTrueSequence = onTrue;
}
if (onFalse != t.onFalseSequence)
{
Undo.RecordObject(t, "Set On False Sequence");
t.onFalseSequence = onFalse;
}
}
}
}

8
Assets/Fungus/Editor/FungusScript/CompareEditor.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: d0cbb7e4ccb4a41db8ced7c87070df1d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

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

@ -195,7 +195,7 @@ namespace Fungus.Script
FungusCommand[] commands = sequence.gameObject.GetComponents<FungusCommand>(); FungusCommand[] commands = sequence.gameObject.GetComponents<FungusCommand>();
foreach (FungusCommand command in commands) foreach (FungusCommand command in commands)
{ {
string commandName = command.GetType().Name; string commandName = command.GetCommandName();
if (command.errorMessage.Length > 0) if (command.errorMessage.Length > 0)
{ {

30
Assets/Fungus/Editor/FungusScript/JumpEditor.cs

@ -1,30 +0,0 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
[CustomEditor (typeof(Jump))]
public class JumpEditor : FungusCommandEditor
{
public override void DrawCommandInspectorGUI()
{
Jump t = target as Jump;
EditorGUI.BeginChangeCheck();
Sequence newSequence = SequenceEditor.SequenceField(new GUIContent("Sequence", "Sequence to jump to"),
t.GetFungusScript(),
t.targetSequence);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Set Jump command");
t.targetSequence = newSequence;
}
}
}
}

2
Assets/Fungus/Editor/FungusScript/JumpEditor.cs.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 970dc31f991bd4b0ba8e3475419f3272 guid: d0cbb7e4ccb4a41db8ced7c87070df1d
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []

149
Assets/Fungus/VisualScripting/Compare.cs

@ -1,149 +0,0 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
public enum CompareOperator
{
Equals, // ==
NotEquals, // !=
LessThan, // <
GreaterThan, // >
LessThanOrEquals, // <=
GreaterThanOrEquals // >=
}
public class Compare : FungusCommand
{
public string variableKey;
public CompareOperator compareOperator;
public BooleanData booleanData;
public IntegerData integerData;
public FloatData floatData;
public StringData stringData;
public Sequence onTrueSequence;
public Sequence onFalseSequence;
public override void OnEnter()
{
Variable v = parentFungusScript.GetVariable(variableKey);
bool condition = false;
switch (v.type)
{
case VariableType.Boolean:
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (v.booleanValue == booleanData.value);
break;
case CompareOperator.NotEquals:
default:
condition = (v.booleanValue != booleanData.value);
break;
}
break;
case VariableType.Integer:
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (v.integerValue == integerData.value);
break;
case CompareOperator.NotEquals:
condition = (v.integerValue != integerData.value);
break;
case CompareOperator.LessThan:
condition = (v.integerValue < integerData.value);
break;
case CompareOperator.GreaterThan:
condition = (v.integerValue > integerData.value);
break;
case CompareOperator.LessThanOrEquals:
condition = (v.integerValue <= integerData.value);
break;
case CompareOperator.GreaterThanOrEquals:
condition = (v.integerValue >= integerData.value);
break;
}
break;
case VariableType.Float:
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (v.floatValue == floatData.value);
break;
case CompareOperator.NotEquals:
condition = (v.floatValue != floatData.value);
break;
case CompareOperator.LessThan:
condition = (v.floatValue < floatData.value);
break;
case CompareOperator.GreaterThan:
condition = (v.floatValue > floatData.value);
break;
case CompareOperator.LessThanOrEquals:
condition = (v.floatValue <= floatData.value);
break;
case CompareOperator.GreaterThanOrEquals:
condition = (v.floatValue >= floatData.value);
break;
}
break;
case VariableType.String:
switch (compareOperator)
{
case CompareOperator.Equals:
condition = (v.stringValue == stringData.value);
break;
case CompareOperator.NotEquals:
default:
condition = (v.stringValue != stringData.value);
break;
}
break;
}
if (condition)
{
if (onTrueSequence != null)
{
ExecuteSequence(onTrueSequence);
return;
}
}
else
{
if (onFalseSequence != null)
{
ExecuteSequence(onFalseSequence);
return;
}
}
Continue();
}
public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
{
if (onTrueSequence != null)
{
connectedSequences.Add(onTrueSequence);
}
if (onFalseSequence != null)
{
connectedSequences.Add(onFalseSequence);
}
}
}
}

8
Assets/Fungus/VisualScripting/Compare.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 050fb9e6e72f442b3b883da8a965bdeb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

5
Assets/Fungus/VisualScripting/FungusCommand.cs

@ -84,6 +84,11 @@ namespace Fungus.Script
public virtual void GetConnectedSequences(ref List<Sequence> connectedSequences) public virtual void GetConnectedSequences(ref List<Sequence> connectedSequences)
{} {}
public virtual string GetCommandName()
{
return GetType().Name;
}
} }
} }

44
Assets/Fungus/VisualScripting/Jump.cs

@ -1,44 +0,0 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
public class Jump : FungusCommand
{
public Sequence targetSequence;
public override void OnEnter()
{
if (targetSequence == null)
{
return;
}
ExecuteSequence(targetSequence);
}
public void OnDrawGizmos()
{
if (targetSequence == null)
{
errorMessage = "Please select a Target Sequence object";
}
else
{
errorMessage = "";
}
}
public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
{
if (targetSequence != null)
{
connectedSequences.Add(targetSequence);
}
}
}
}

2
Assets/Fungus/VisualScripting/Jump.cs.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: c6a48e2d0a0f542d69398d3c180375da guid: 050fb9e6e72f442b3b883da8a965bdeb
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save