public void BooleanEvaluationTest() { FsmParameter bool1 = FsmParameter.NewBoolean("bool1"); FsmCondition condition = FsmCondition.NewSmallerThan(bool1, 0); Assert.Throws <NotSupportedException>(() => condition.Evaluate()); }
private static Rect DrawConstant(Rect rect, SerializedProperty property, Context context) { FsmParameter parameter = context.fsm.GetParameter(property.FindPropertyRelative("_parameterName").stringValue); rect.yMin += EditorGUIUtility.singleLineHeight; rect.yMax += EditorGUIUtility.singleLineHeight; switch (parameter.type) { case FsmParameter.Type.BOOLEAN: EditorGUI.PropertyField(rect, property.FindPropertyRelative("_boolValue")); break; case FsmParameter.Type.INTEGER: EditorGUI.PropertyField(rect, property.FindPropertyRelative("_intValue")); break; case FsmParameter.Type.FLOAT: EditorGUI.PropertyField(rect, property.FindPropertyRelative("_floatValue")); break; default: throw new NotSupportedException("Parameter type unknown: " + parameter.type); } return(rect); }
public void SmallerThanTest() { FsmParameter bool1 = FsmParameter.NewBoolean("bool1"); Assert.Throws <NotSupportedException>(() => bool1.SmallerThan(1)); Assert.Throws <NotSupportedException>(() => bool1.SmallerThan(1f)); }
public void SmallerThanTest() { FsmParameter int1 = FsmParameter.NewInteger("int1", 1); Assert.IsFalse(int1.SmallerThan(0)); Assert.IsFalse(int1.SmallerThan(1)); Assert.IsTrue(int1.SmallerThan(2)); }
public void SmallerThanTest() { FsmParameter float1 = FsmParameter.NewFloat("float1", 1f); Assert.IsFalse(float1.SmallerThan(0f)); Assert.IsFalse(float1.SmallerThan(1f)); Assert.IsTrue(float1.SmallerThan(2f)); }
public void BooleanContainsTest() { FsmParameter bool1 = FsmParameter.NewBoolean("bool1"); FsmParameter bool2 = FsmParameter.NewBoolean("bool2"); FsmCondition condition = FsmCondition.NewEquals(bool1, false); Assert.IsTrue(condition.Contains("bool1")); Assert.IsFalse(condition.Contains("bool2")); }
public void FloatContainsTest() { FsmParameter float1 = FsmParameter.NewFloat("float1"); FsmParameter float2 = FsmParameter.NewFloat("float2"); FsmCondition condition = FsmCondition.NewEquals(float1, 0f); Assert.IsTrue(condition.Contains("float1")); Assert.IsFalse(condition.Contains("float2")); }
public void IntegerContainsTest() { FsmParameter int1 = FsmParameter.NewInteger("int1"); FsmParameter int2 = FsmParameter.NewInteger("int2"); FsmCondition condition = FsmCondition.NewEquals(int1, 0); Assert.IsTrue(condition.Contains("int1")); Assert.IsFalse(condition.Contains("int2")); }
public void SetUp() { fsm = ScriptableObject.CreateInstance <FiniteStateMachine>(); LoggerFsmState state1 = ScriptableObject.CreateInstance <LoggerFsmState>(); state1.name = "State1"; AssetDatabase.CreateAsset(state1, ASSET_PATH + "State1.asset"); LoggerFsmState state2 = ScriptableObject.CreateInstance <LoggerFsmState>(); state2.name = "State2"; AssetDatabase.CreateAsset(state2, ASSET_PATH + "State2.asset"); AssetDatabase.SaveAssets(); fsm.AddStateInstance("One", state1); fsm.AddStateInstance("Two", state2); fsm.AddStateInstance("Three", state1); fsm.AddStateInstance("Four", state2); FsmParameter triggerParameter = FsmParameter.NewBoolean("testTrigger"); FsmParameter booleanParameter = FsmParameter.NewBoolean("testBool"); FsmParameter integerParameter = FsmParameter.NewInteger("testInt"); FsmParameter floatParameter = FsmParameter.NewFloat("testFloat"); fsm.AddParameter(triggerParameter); fsm.AddParameter(booleanParameter); fsm.AddParameter(integerParameter); fsm.AddParameter(floatParameter); FsmTransition transition1to2 = new FsmTransition(); transition1to2.AddCondition(FsmCondition.NewTrigger(triggerParameter)); FsmTransition transition2to3 = new FsmTransition(); transition2to3.AddCondition(FsmCondition.NewEquals(booleanParameter, true)); FsmTransition transition3to4 = new FsmTransition(); transition3to4.AddCondition(FsmCondition.NewGreaterThan(integerParameter, 3)); FsmTransition transition4to1 = new FsmTransition(); transition4to1.AddCondition(FsmCondition.NewSmallerThan(floatParameter, -1f)); fsm.AddTransition("One", "Two", transition1to2); fsm.AddTransition("Two", "Three", transition2to3); fsm.AddTransition("Three", "Four", transition3to4); fsm.AddTransition("Four", "One", transition4to1); // Clean up if asset already exists AssetDatabase.DeleteAsset(ASSET_PATH); }
public void EqualsTest() { FsmParameter int1 = FsmParameter.NewInteger("int1", 1); Assert.IsTrue(int1.Equals(1)); Assert.IsFalse(int1.Equals(2)); int1.intValue = 2; Assert.IsFalse(int1.Equals(1)); Assert.IsTrue(int1.Equals(2)); }
public void BooleanEvaluationTest() { FsmParameter t1 = FsmParameter.NewBoolean("t1"); FsmCondition tc = FsmCondition.NewTrigger(t1); Assert.IsFalse(tc.Evaluate()); t1.boolValue = true; Assert.IsTrue(tc.Evaluate()); Assert.IsFalse(tc.Evaluate()); }
public void EqualsTest() { FsmParameter bool1 = FsmParameter.NewBoolean("bool1"); Assert.IsTrue(bool1.Equals(false)); Assert.IsFalse(bool1.Equals(true)); bool1.boolValue = true; Assert.IsFalse(bool1.Equals(false)); Assert.IsTrue(bool1.Equals(true)); }
public void EqualsTest() { FsmParameter float1 = FsmParameter.NewFloat("float1", 1f); Assert.IsFalse(float1.Equals(0f)); Assert.IsTrue(float1.Equals(1f)); Assert.IsFalse(float1.Equals(2f)); float1.floatValue = 2f; Assert.IsFalse(float1.Equals(0f)); Assert.IsFalse(float1.Equals(1f)); Assert.IsTrue(float1.Equals(2f)); }
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { rect.height = EditorGUIUtility.singleLineHeight; FiniteStateMachine fsm = (property.serializedObject.targetObject as FiniteStateMachine); // Draw name and propagate renames to the whole FSM EditorGUI.BeginProperty(rect, label, property); string oldName = property.FindPropertyRelative("_name").stringValue; string newName = EditorGUI.DelayedTextField(rect, "Name", property.FindPropertyRelative("_name").stringValue); if (!oldName.Equals(newName)) { fsm.RenameParameter(oldName, newName); property.serializedObject.Update(); } // Draw type rect.yMin += EditorGUIUtility.singleLineHeight; rect.yMax += EditorGUIUtility.singleLineHeight; EditorGUI.PropertyField(rect, property.FindPropertyRelative("_type")); // Draw value rect.yMin += EditorGUIUtility.singleLineHeight; rect.yMax += EditorGUIUtility.singleLineHeight; string valuePropertyName; FsmParameter parameter = fsm.GetParameter(property.FindPropertyRelative("_name").stringValue); switch (parameter.type) { case FsmParameter.Type.BOOLEAN: valuePropertyName = "_boolValue"; break; case FsmParameter.Type.INTEGER: valuePropertyName = "_intValue"; break; case FsmParameter.Type.FLOAT: valuePropertyName = "_floatValue"; break; default: throw new InvalidOperationException("Unkown parameter type " + parameter.type); } EditorGUI.PropertyField(rect, property.FindPropertyRelative(valuePropertyName)); EditorGUI.EndProperty(); }
public void SetUp() { fsm = ScriptableObject.CreateInstance <FiniteStateMachine>(); state1 = ScriptableObject.CreateInstance <TestFsmState>(); state1.name = "State1"; state2 = ScriptableObject.CreateInstance <TestFsmState>(); state2.name = "State2"; fsm.AddStateInstance("One", state1); fsm.AddStateInstance("Two", state2); fsm.AddStateInstance("Three", state1); fsm.AddStateInstance("Four", state2); triggerParameter = FsmParameter.NewBoolean("testTrig"); booleanParameter = FsmParameter.NewBoolean("testBool"); integerParameter = FsmParameter.NewInteger("testInt"); floatParameter = FsmParameter.NewFloat("testFloat"); fsm.AddParameter(triggerParameter); fsm.AddParameter(booleanParameter); fsm.AddParameter(integerParameter); fsm.AddParameter(floatParameter); transition1to2 = new FsmTransition(); transition1to2.AddCondition(FsmCondition.NewTrigger(triggerParameter)); transition2to3 = new FsmTransition(); FsmCondition equalsCondition = FsmCondition.NewEquals(booleanParameter, true); transition2to3.AddCondition(equalsCondition); transition3to4 = new FsmTransition(); FsmCondition greaterCondition = FsmCondition.NewGreaterThan(integerParameter, 3); transition3to4.AddCondition(greaterCondition); transition4to1 = new FsmTransition(); FsmCondition smallerCondition = FsmCondition.NewSmallerThan(floatParameter, -1f); transition4to1.AddCondition(smallerCondition); fsm.AddTransition("One", "Two", transition1to2); fsm.AddTransition("Two", "Three", transition2to3); fsm.AddTransition("Three", "Four", transition3to4); fsm.AddTransition("Four", "One", transition4to1); }
public void FloatEvaluationTest() { FsmParameter float1 = FsmParameter.NewFloat("float1"); FsmCondition condition = FsmCondition.NewSmallerThan(float1, 0); float1.floatValue = 0; condition.floatValue = 0; Assert.IsFalse(condition.Evaluate()); float1.floatValue = 0; condition.floatValue = 1; Assert.IsTrue(condition.Evaluate()); float1.floatValue = 1; condition.floatValue = 0; Assert.IsFalse(condition.Evaluate()); }
public void IntegerEvaluationTest() { FsmParameter int1 = FsmParameter.NewInteger("int1"); FsmCondition condition = FsmCondition.NewSmallerThan(int1, 0); int1.intValue = 0; condition.intValue = 0; Assert.IsFalse(condition.Evaluate()); int1.intValue = 0; condition.intValue = 1; Assert.IsTrue(condition.Evaluate()); int1.intValue = 1; condition.intValue = 0; Assert.IsFalse(condition.Evaluate()); }
private static bool IsAllowedConditionType(Enum t, SerializedProperty property, Context context) { FsmParameter parameter = context.fsm.GetParameter(property.FindPropertyRelative("_parameterName").stringValue); FsmCondition.Type type = (FsmCondition.Type)t; switch (parameter.type) { case FsmParameter.Type.BOOLEAN: return(type == FsmCondition.Type.TRIGGER || type == FsmCondition.Type.EQUALS); case FsmParameter.Type.INTEGER: case FsmParameter.Type.FLOAT: return(type == FsmCondition.Type.EQUALS || type == FsmCondition.Type.GREATER_THAN || type == FsmCondition.Type.SMALLER_THAN); default: throw new NotSupportedException("Parameter type unknown: " + parameter.type); } }
public void BooleanEvaluationTest() { FsmParameter bool1 = FsmParameter.NewBoolean("bool1"); FsmCondition condition = FsmCondition.NewEquals(bool1, false); bool1.boolValue = false; condition.boolValue = false; Assert.IsTrue(condition.Evaluate()); bool1.boolValue = false; condition.boolValue = true; Assert.IsFalse(condition.Evaluate()); bool1.boolValue = true; condition.boolValue = false; Assert.IsFalse(condition.Evaluate()); bool1.boolValue = true; condition.boolValue = true; Assert.IsTrue(condition.Evaluate()); }
public void FloatEvaluationTest() { FsmParameter float1 = FsmParameter.NewFloat("float1"); FsmCondition condition = FsmCondition.NewEquals(float1, 1f); float1.floatValue = 0f; condition.floatValue = 0f; Assert.IsTrue(condition.Evaluate()); float1.floatValue = 0f; condition.floatValue = 1f; Assert.IsFalse(condition.Evaluate()); float1.floatValue = 1f; condition.floatValue = 0f; Assert.IsFalse(condition.Evaluate()); float1.floatValue = 1f; condition.floatValue = 1f; Assert.IsTrue(condition.Evaluate()); }