public void Trigger() { Fungus.Variable v = null; if (!flowchart) { flowchart = FindFlowchartWithVariable(variableName, out v); } else { v = FindVariable(flowchart, variableName); } if (v.GetType() == typeof(Fungus.StringVariable)) { flowchart.SetStringVariable(variableName, flowchart.GetStringVariable(variableName) + variableValue); } if (v.GetType() == typeof(Fungus.FloatVariable)) { flowchart.SetFloatVariable(variableName, flowchart.GetFloatVariable(variableName) + System.Single.Parse(variableValue)); } if (v.GetType() == typeof(Fungus.IntegerVariable)) { flowchart.SetIntegerVariable(variableName, flowchart.GetIntegerVariable(variableName) + System.Int32.Parse(variableValue)); } if (v.GetType() == typeof(Fungus.BooleanVariable)) { flowchart.SetBooleanVariable(variableName, !flowchart.GetBooleanVariable(variableName)); } }
/// <summary> /// Adds the passed variable to the passed list if it can be cast to the correct type. /// /// TBase: Base type encapsulated by the variable /// /// TSVarType: This save system's serializable container for the variable /// TNSVariableType: Fungus's built-in flowchart-only container for the variable /// </summary> protected virtual void TrySetVariable <TBase, TSVarType, TNSVariableType>(BaseFungus.Variable varToSet, IList <TSVarType> varList) where TSVarType : Var <TBase>, new() where TNSVariableType : BaseFungus.VariableBase <TBase> { var fungusBaseVar = varToSet as TNSVariableType; if (fungusBaseVar != null) { var toAdd = new TSVarType(); toAdd.Key = fungusBaseVar.Key; toAdd.Value = fungusBaseVar.Value; varList.Add(toAdd); } }
public static Fungus.Flowchart FindFlowchartWithVariable(string variableName, out Fungus.Variable foundVariable) { Fungus.Flowchart flowchart = null; Fungus.Flowchart[] flows = GameObject.FindObjectsOfType <Fungus.Flowchart>(); foundVariable = null; for (var f = 0; f < flows.Length && foundVariable == null; ++f) { flowchart = flows[f]; // check to see if the variable in question is in this flowchart foundVariable = FindVariable(flowchart, variableName); } if (!flowchart) { Debug.LogError("Could not find flowchart with variable \"" + variableName + "\""); } return(flowchart); }
public virtual bool HasReference(Variable variable) { return false; }
public override bool HasReference(Variable variable) { return(_amount.vector3Ref == variable || base.HasReference(variable)); }
public override bool HasReference(Variable variable) { return(startLabel.stringRef == variable || base.HasReference(variable)); }
public override bool HasReference(Variable variable) { return clearPrevious.booleanRef == variable || waitForInput.booleanRef == variable || waitForSeconds.floatRef == variable || fadeWhenDone.booleanRef == variable || base.HasReference(variable); }
public override bool HasReference(Variable variable) { return(variable == inValue.floatRef || variable == outValue.integerRef); }
public override bool HasReference(Variable variable) { return (variable == this.variable); }
public override bool HasReference(Variable variable) { return(variable == this.variable); }
public override void DrawCommandGUI() { serializedObject.Update(); If t = target as If; FungusScript fungusScript = t.GetFungusScript(); if (fungusScript == null) { return; } VariableEditor.VariableField(variableProp, new GUIContent("Variable", "Variable to use in operation"), t.GetFungusScript(), null); if (variableProp.objectReferenceValue == null) { serializedObject.ApplyModifiedProperties(); return; } Variable selectedVariable = variableProp.objectReferenceValue as Variable; System.Type variableType = selectedVariable.GetType(); List <GUIContent> operatorList = new List <GUIContent>(); operatorList.Add(new GUIContent("==")); operatorList.Add(new GUIContent("!=")); if (variableType == typeof(IntegerVariable) || variableType == typeof(FloatVariable)) { operatorList.Add(new GUIContent("<")); operatorList.Add(new GUIContent(">")); operatorList.Add(new GUIContent("<=")); operatorList.Add(new GUIContent(">=")); } compareOperatorProp.enumValueIndex = EditorGUILayout.Popup(new GUIContent("Compare", "The comparison operator to use when comparing values"), compareOperatorProp.enumValueIndex, operatorList.ToArray()); if (variableType == typeof(BooleanVariable)) { EditorGUILayout.PropertyField(booleanValueProp); } else if (variableType == typeof(IntegerVariable)) { EditorGUILayout.PropertyField(integerValueProp); } else if (variableType == typeof(FloatVariable)) { EditorGUILayout.PropertyField(floatValueProp); } else if (variableType == typeof(StringVariable)) { EditorGUILayout.PropertyField(stringValueProp); } serializedObject.ApplyModifiedProperties(); }
public override bool HasReference(Variable variable) { return(variable == _amount.vector3Ref); }
public override bool HasReference(Variable variable) { return(variable == integer.integerRef || base.HasReference(variable)); }
static public void VariableField(SerializedProperty property, GUIContent label, Flowchart flowchart, Func <Variable, bool> filter, Func <string, int, string[], int> drawer = null) { List <string> variableKeys = new List <string>(); List <Variable> variableObjects = new List <Variable>(); variableKeys.Add("<None>"); variableObjects.Add(null); List <Variable> variables = flowchart.variables; int index = 0; int selectedIndex = 0; Variable selectedVariable = property.objectReferenceValue as Variable; foreach (Variable v in variables) { if (filter != null) { if (!filter(v)) { continue; } } variableKeys.Add(v.key); variableObjects.Add(v); index++; if (v == selectedVariable) { selectedIndex = index; } } Flowchart[] fsList = GameObject.FindObjectsOfType <Flowchart>(); foreach (Flowchart fs in fsList) { if (fs == flowchart) { continue; } List <Variable> publicVars = fs.GetPublicVariables(); foreach (Variable v in publicVars) { variableKeys.Add(fs.name + " / " + v.key); variableObjects.Add(v); index++; if (v == selectedVariable) { selectedIndex = index; } } } if (drawer == null) { selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray()); } else { selectedIndex = drawer(label.text, selectedIndex, variableKeys.ToArray()); } property.objectReferenceValue = variableObjects[selectedIndex]; }
protected virtual void OnEnable() { Variable t = target as Variable; t.hideFlags = HideFlags.HideInInspector; }
public override bool HasReference(Variable variable) { return(a.floatRef == variable || b.floatRef == variable || percentage.floatRef == variable || outValue.floatRef == variable); }
public override bool HasReference(Variable variable) { return (variable == stringVariable); }
/** * 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) { int suffix = 0; string baseKey = originalKey; // Only letters and digits allowed char[] arr = baseKey.Where(c => (char.IsLetterOrDigit(c) || c == '_')).ToArray(); baseKey = new string(arr); // No leading digits allowed baseKey = baseKey.TrimStart('0','1','2','3','4','5','6','7','8','9'); // No empty keys allowed if (baseKey.Length == 0) { baseKey = "Var"; } string key = baseKey; while (true) { bool collision = false; foreach(Variable variable in variables) { if (variable == ignoreVariable || variable.key == null) { continue; } if (variable.key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) { collision = true; suffix++; key = baseKey + suffix; } } if (!collision) { return key; } } }
public override bool HasReference(Variable variable) { return(frameCount.integerRef == variable || base.HasReference(variable)); }