//Displays the SpeechBubble according to number of emojis and sets the WaitTime -variable in Fungus to match delayBetweenBubbles private IEnumerator DisplayBubble(SpeechBubbleDisplay character, SpeechBubble speechBubble, Flowchart flowchart) { switch (speechBubble.emojiSprites.Count) { case 1: flowchart.SetFloatVariable("WaitTime", delayBetweenBubbles); //character.SetBubbleScale(1); yield return(StartCoroutine(character.ShowBubble(speechBubble.bubbleSprites[0].sprite, speechBubble.emojiSprites[0].sprite, 1))); break; case 2: flowchart.SetFloatVariable("WaitTime", delayBetweenBubbles * 2); //character.SetBubbleScale(2); yield return(StartCoroutine(character.ShowBubble(speechBubble.bubbleSprites[0].sprite, speechBubble.emojiSprites[0].sprite, 1))); yield return(new WaitForSeconds(delayBetweenEmojis)); yield return(StartCoroutine(character.ShowBubble(speechBubble.bubbleSprites[0].sprite, speechBubble.emojiSprites[1].sprite, 2))); break; case 3: flowchart.SetFloatVariable("WaitTime", delayBetweenBubbles * 3); //character.SetBubbleScale(3); yield return(StartCoroutine(character.ShowBubble(speechBubble.bubbleSprites[0].sprite, speechBubble.emojiSprites[0].sprite, 1))); yield return(new WaitForSeconds(delayBetweenEmojis)); yield return(StartCoroutine(character.ShowBubble(speechBubble.bubbleSprites[0].sprite, speechBubble.emojiSprites[1].sprite, 2))); yield return(new WaitForSeconds(delayBetweenEmojis)); yield return(StartCoroutine(character.ShowBubble(speechBubble.bubbleSprites[0].sprite, speechBubble.emojiSprites[2].sprite, 3))); break; default: break; } }
private void Initialize() { gameManager.GameStateObservable .Subscribe(state => { flowchart.SetStringVariable("GameState", state.ToString()); ExecuteNarrative(state); }); gameManager.IsPlayable.Where(x => x) .SelectMany(gameManager.PowerGauge.CurrentPower) .TakeUntil(gameManager.GameStateObservable.Where(state => state != GameState.InGame)) .Subscribe(power => { flowchart.SetFloatVariable("Power", power); }); gameManager.Rocket.Height .TakeUntil(gameManager.GameStateObservable.Where(state => state != GameState.Ending)) .Subscribe(height => { flowchart.SetFloatVariable("Height", height); }); }
//If a block is activated by the user, then this is not needed in the flowchart //Copies the variables in the list from the GM flowcharts to the activated flowchart public void CopyGameMasterToFlowchart() { gm = GameObject.Find("GameMaster").GetComponent <GameMaster>(); Flowchart gmQuest = gm.GetQuestFlowchart(); Flowchart target = this.GetComponent <Flowchart>(); Variable sourceVar = null; for (int i = 0; i < varNames.Length; i++) { sourceVar = gmQuest.GetVariable(varNames[i]); StringVariable tempstr = sourceVar as StringVariable; if (tempstr != null) { target.SetStringVariable(varNames[i], tempstr.Value); continue; } BooleanVariable tempBool = sourceVar as BooleanVariable; if (tempBool != null) { target.SetBooleanVariable(varNames[i], tempBool.Value); continue; } IntegerVariable tempInt = sourceVar as IntegerVariable; if (tempInt != null) { target.SetIntegerVariable(varNames[i], tempInt.Value); continue; } FloatVariable tempFloat = sourceVar as FloatVariable; if (tempFloat != null) { target.SetFloatVariable(varNames[i], tempFloat.Value); continue; } } }
private void SyncToFungus(string inkVariableName, object inkVariableNewValue) { bool hasChanged; Variable fungusVariable = fungusGlobalVariables.GetVariable(inkVariableName); Type fungusVariableType = fungusVariable.GetValue().GetType(); if (fungusVariableType == typeof(int)) { int intValue = (fungusVariable as IntegerVariable).Value; hasChanged = (intValue != (int)inkVariableNewValue); } else if (fungusVariableType == typeof(string)) { string stringValue = (fungusVariable as StringVariable).Value; hasChanged = (stringValue != (string)inkVariableNewValue); } else if (fungusVariableType == typeof(float)) { float floatValue = (fungusVariable as FloatVariable).Value; hasChanged = (floatValue != (float)inkVariableNewValue); } else if (fungusVariableType == typeof(bool)) { bool boolValue = (fungusVariable as BooleanVariable).Value; hasChanged = (boolValue != (0 != (int)inkVariableNewValue)); } else { hasChanged = false; } if (hasChanged) { // Picks the first flowchart: any flowchart is OK, it's a global variable Flowchart flowchart = syncVariables[inkVariableName][0]; Type inkVariableType = inkVariableNewValue.GetType(); try { Debug.Log(inkVariableName + "=" + inkVariableNewValue + " (Ink->Fungus)"); if (inkVariableType == typeof(int)) { if (fungusVariableType == typeof(bool)) { flowchart.SetBooleanVariable(inkVariableName, (0 != (int)inkVariableNewValue)); } else { flowchart.SetIntegerVariable(inkVariableName, (int)inkVariableNewValue); } } else if (inkVariableType == typeof(string)) { flowchart.SetStringVariable(inkVariableName, (string)inkVariableNewValue); } else if (inkVariableType == typeof(float)) { flowchart.SetFloatVariable(inkVariableName, (float)inkVariableNewValue); } else // it's an Ink list { throw new InvalidCastException(); } foreach (Flowchart affectedFlowchart in syncVariables[inkVariableName]) { BroadcastToFungus(refreshVariablesMessage, affectedFlowchart); // rough and simple BroadcastToFungus(refreshVariablesMessage + " " + inkVariableName, affectedFlowchart); // fine-grained } } catch (InvalidCastException) { Debug.LogError("Sync variable mismatch: " + inkVariableName + " is " + inkVariableType + " in Ink but it's not in Fungus"); } } else { Debug.Log(inkVariableName + " is already in sync with Fungus"); } }
public void ValueChangeCheckMouseS() { myFlowchart.SetFloatVariable("MouseSensitivity", SliderMouseS.value); }
public void SetFlowVarFloat(string name, float value) { flowchart.SetFloatVariable(name, value); }
public void PlayColorAudio() { flowchart.SetFloatVariable("narrationTime", AudioManager.instance.PlaySound(colorAudioName)); }
void setExamScore() { flowchart.SetFloatVariable("ExamScore", examScore); }
// Update is called once per frame void Update() { flow.SetFloatVariable("points1", pin1); flow.SetFloatVariable("points2", pin2); flow.SetFloatVariable("points3", pin3); flow.SetFloatVariable("points4", pin4); flow.SetFloatVariable("points5", pin5); flow.SetFloatVariable("points6", pin6); // Debug.Log(haveP1); if (Input.GetMouseButtonDown(0) && haveP == true && camOn == true) { photos.texture = ScreenCapture.CaptureScreenshotAsTexture(); haveP = false; pin1 = CameraRay.total; me += 1; } if (Input.GetMouseButtonUp(0) && haveP == false && me == 1) { haveP1 = true; } if (Input.GetMouseButtonDown(0) && haveP1 == true && camOn == true) { haveP1 = false; me += 1; pin2 = CameraRay.total; // haveP2 = true; photos1.texture = ScreenCapture.CaptureScreenshotAsTexture(); } if (Input.GetMouseButtonUp(0) && haveP1 == false && me == 2) { haveP2 = true; } if (Input.GetMouseButtonUp(0) && haveP2 == true && camOn == true) { haveP2 = false; me += 1; pin3 = CameraRay.total; photos2.texture = ScreenCapture.CaptureScreenshotAsTexture(); } if (Input.GetMouseButtonUp(0) && haveP2 == false && me == 3) { haveP3 = true; } if (Input.GetMouseButtonDown(0) && haveP3 == true && camOn == true) { haveP3 = false; me += 1; pin4 = CameraRay.total; photos3.texture = ScreenCapture.CaptureScreenshotAsTexture(); } if (Input.GetMouseButtonUp(0) && haveP3 == false && me == 4) { haveP4 = true; } if (Input.GetMouseButtonDown(0) && haveP4 == true && camOn == true) { haveP4 = false; me += 1; photos4.texture = ScreenCapture.CaptureScreenshotAsTexture(); pin5 = CameraRay.total; } if (Input.GetMouseButtonUp(0) && haveP4 == false && me == 5) { haveP5 = true; } if (Input.GetMouseButtonDown(0) && haveP5 == true && camOn == true) { haveP5 = false; me += 1; photos5.texture = ScreenCapture.CaptureScreenshotAsTexture(); pin6 = CameraRay.total; } if (Input.GetKeyDown(KeyCode.E)) { camOn = true; } if (Input.GetKeyDown(KeyCode.Q)) { camOn = false; } if (Input.GetKeyDown(KeyCode.I)) { camOn = false; } }
public void CreateConditional(List <Parser.IfStatement.Clause> clauses, Block block, Dictionary <string, Yarn.Parser.Node> nodes, Dictionary <string, Block> blocks) { /** * NOTES: * - clause.expression will be null if it's an else statement * - refer to DialogueRunner for examples of parsing */ for (int i = 0; i < clauses.Count; i++) { Parser.IfStatement.Clause clause = clauses[i]; //if the expression is null, it is an else statement if (clause.expression == null) { Else elseStatement = currentFlowchartObj.AddComponent <Else>(); block.CommandList.Add(elseStatement); } // if the clause is the first entry in clauses, then it is an if statement else if (i == 0) { If ifstatement = currentFlowchartObj.AddComponent <If>(); block.CommandList.Add(ifstatement); if (clause.expression.function != null) { //it is an operator statement switch (clause.expression.function.name) { case "LessThanOrEqualTo": ifstatement.SetCompareOperator(CompareOperator.LessThanOrEquals); break; case "GreaterThanOrEqualTo": ifstatement.SetCompareOperator(CompareOperator.GreaterThanOrEquals); break; case "LessThan": ifstatement.SetCompareOperator(CompareOperator.LessThan); break; case "GreaterThan": ifstatement.SetCompareOperator(CompareOperator.GreaterThan); break; case "EqualTo": ifstatement.SetCompareOperator(CompareOperator.Equals); break; case "NotEqualTo": ifstatement.SetCompareOperator(CompareOperator.NotEquals); break; default: Debug.LogError("NEW FUNCTION NAME: " + clause.expression.function.name); break; } Flowchart currFlowchart = currentFlowchartObj.GetComponent <Flowchart>(); Parser.Expression secondExpression = clause.expression.parameters[1]; switch (secondExpression.value.value.type) { case Value.Type.String: StringVariable sv = null; if (currFlowchart.GetVariable <StringVariable>(clause.expression.parameters[0].value.value.GetVariableName()) == null) { sv = currentFlowchartObj.AddComponent <StringVariable>(); sv.Scope = VariableScope.Public; sv.Key = clause.expression.parameters[0].value.value.GetVariableName(); sv.Value = ""; currFlowchart.AddVariable(sv); currFlowchart.SetStringVariable(sv.Key, ""); } else { sv = currFlowchart.GetVariable <StringVariable>(clause.expression.parameters[0].value.value.GetVariableName()); } StringDataMulti data = new StringDataMulti(); data.stringVal = secondExpression.value.value.GetStringValue(); ifstatement.SetVariable(sv); ifstatement.SetStringData(data); break; case Value.Type.Number: FloatVariable fv = null; if (currFlowchart.GetVariable <FloatVariable>(clause.expression.parameters[0].value.value.GetVariableName()) == null) { fv = currentFlowchartObj.AddComponent <FloatVariable>(); fv.Scope = VariableScope.Public; fv.Key = clause.expression.parameters[0].value.value.GetVariableName(); fv.Value = 0; currFlowchart.AddVariable(fv); currFlowchart.SetFloatVariable(fv.Key, 0); } else { fv = currFlowchart.GetVariable <FloatVariable>(clause.expression.parameters[0].value.value.GetVariableName()); } FloatData fdata = new FloatData(); fdata.floatVal = secondExpression.value.value.GetNumberValue(); ifstatement.SetVariable(fv); ifstatement.SetFloatData(fdata); break; case Value.Type.Bool: BooleanVariable bv = null; if (currFlowchart.GetVariable <BooleanVariable>(clause.expression.parameters[0].value.value.GetVariableName()) == null) { bv = currentFlowchartObj.AddComponent <BooleanVariable>(); bv.Scope = VariableScope.Public; bv.Key = clause.expression.parameters[0].value.value.GetVariableName(); bv.Value = false; currFlowchart.AddVariable(bv); currFlowchart.SetBooleanVariable(bv.Key, false); } else { bv = currFlowchart.GetVariable <BooleanVariable>(clause.expression.parameters[0].value.value.GetVariableName()); } BooleanData bdata = new BooleanData(); bdata.booleanVal = secondExpression.value.value.GetBoolValue(); ifstatement.SetVariable(bv); ifstatement.SetBooleanData(bdata); break; default: Debug.LogError("Unknown Parser Value Type"); break; } } } //otherwise, it's an elseif statement else { ElseIf ifstatement = currentFlowchartObj.AddComponent <ElseIf>(); block.CommandList.Add(ifstatement); if (clause.expression.function != null) { //it is an operator statement switch (clause.expression.function.name) { case "LessThanOrEqualTo": ifstatement.SetCompareOperator(CompareOperator.LessThanOrEquals); break; case "GreaterThanOrEqualTo": ifstatement.SetCompareOperator(CompareOperator.GreaterThanOrEquals); break; case "LessThan": ifstatement.SetCompareOperator(CompareOperator.LessThan); break; case "GreaterThan": ifstatement.SetCompareOperator(CompareOperator.GreaterThan); break; case "EqualTo": ifstatement.SetCompareOperator(CompareOperator.Equals); break; case "NotEqualTo": ifstatement.SetCompareOperator(CompareOperator.NotEquals); break; default: Debug.LogError("NEW FUNCTION NAME: " + clause.expression.function.name); break; } Flowchart currFlowchart = currentFlowchartObj.GetComponent <Flowchart>(); Parser.Expression secondExpression = clause.expression.parameters[1]; switch (secondExpression.value.value.type) { case Value.Type.String: StringVariable sv = null; if (currFlowchart.GetVariable <StringVariable>(clause.expression.parameters[0].value.value.GetVariableName()) == null) { sv = currentFlowchartObj.AddComponent <StringVariable>(); sv.Scope = VariableScope.Public; sv.Key = clause.expression.parameters[0].value.value.GetVariableName(); sv.Value = ""; currFlowchart.AddVariable(sv); currFlowchart.SetStringVariable(sv.Key, ""); } else { sv = currFlowchart.GetVariable <StringVariable>(clause.expression.parameters[0].value.value.GetVariableName()); } StringDataMulti data = new StringDataMulti(); data.stringVal = secondExpression.value.value.GetStringValue(); ifstatement.SetVariable(sv); ifstatement.SetStringData(data); break; case Value.Type.Number: FloatVariable fv = null; if (currFlowchart.GetVariable <FloatVariable>(clause.expression.parameters[0].value.value.GetVariableName()) == null) { fv = currentFlowchartObj.AddComponent <FloatVariable>(); fv.Scope = VariableScope.Public; fv.Key = clause.expression.parameters[0].value.value.GetVariableName(); fv.Value = 0; currFlowchart.AddVariable(fv); currFlowchart.SetFloatVariable(fv.Key, 0); } else { fv = currFlowchart.GetVariable <FloatVariable>(clause.expression.parameters[0].value.value.GetVariableName()); } FloatData fdata = new FloatData(); fdata.floatVal = secondExpression.value.value.GetNumberValue(); ifstatement.SetVariable(fv); ifstatement.SetFloatData(fdata); break; case Value.Type.Bool: BooleanVariable bv = null; if (currFlowchart.GetVariable <BooleanVariable>(clause.expression.parameters[0].value.value.GetVariableName()) == null) { bv = currentFlowchartObj.AddComponent <BooleanVariable>(); bv.Scope = VariableScope.Public; bv.Key = clause.expression.parameters[0].value.value.GetVariableName(); bv.Value = false; currFlowchart.AddVariable(bv); currFlowchart.SetBooleanVariable(bv.Key, false); } else { bv = currFlowchart.GetVariable <BooleanVariable>(clause.expression.parameters[0].value.value.GetVariableName()); } BooleanData bdata = new BooleanData(); bdata.booleanVal = secondExpression.value.value.GetBoolValue(); ifstatement.SetVariable(bv); ifstatement.SetBooleanData(bdata); break; default: Debug.LogError("Unknown Parser Value Type"); break; } } } //Parse the statements once you figure out what kind of if-else to use ParseNodeHelper(clause.statements, block, nodes, blocks); } //Put in an end-if End end = currentFlowchartObj.AddComponent <End>(); block.CommandList.Add(end); }
public void CreateAssignment(Parser.AssignmentStatement ass, Block block, Dictionary <string, Yarn.Parser.Node> nodes, Dictionary <string, Block> blocks) { SetVariable setVar = currentFlowchartObj.AddComponent <SetVariable>(); Flowchart currFlowchart = currentFlowchartObj.GetComponent <Flowchart>(); switch (ass.operation) { case Yarn.TokenType.EqualToOrAssign: setVar.SetSetOperator(Fungus.SetOperator.Assign); break; case Yarn.TokenType.AddAssign: setVar.SetSetOperator(Fungus.SetOperator.Add); break; case Yarn.TokenType.MinusAssign: setVar.SetSetOperator(SetOperator.Subtract); break; case Yarn.TokenType.DivideAssign: setVar.SetSetOperator(SetOperator.Divide); break; case Yarn.TokenType.MultiplyAssign: setVar.SetSetOperator(SetOperator.Multiply); break; default: Debug.LogError("Unknown Operator"); break; } switch (ass.valueExpression.value.value.type) { case Value.Type.String: StringDataMulti sdm = new StringDataMulti(ass.valueExpression.value.value.AsString); setVar.SetStringData(sdm); StringVariable sv = null; if (currFlowchart.GetVariable <StringVariable>(ass.destinationVariableName) == null) { sv = currentFlowchartObj.AddComponent <StringVariable>(); sv.Scope = VariableScope.Public; sv.Key = ass.destinationVariableName; sv.Value = ""; currFlowchart.AddVariable(sv); currFlowchart.SetStringVariable(sv.Key, sv.Value); } else { sv = currFlowchart.GetVariable <StringVariable>(ass.destinationVariableName); currFlowchart.SetStringVariable(sv.Key, sv.Value); } setVar.SetAffectedVariable(sv); break; case Value.Type.Number: FloatData fd = new FloatData(ass.valueExpression.value.value.AsNumber); setVar.SetFloatData(fd); FloatVariable fv = null; if (currFlowchart.GetVariable <FloatVariable>(ass.destinationVariableName) == null) { fv = currentFlowchartObj.AddComponent <FloatVariable>(); fv.Scope = VariableScope.Public; fv.Key = ass.destinationVariableName; fv.Value = 0; currFlowchart.AddVariable(fv); currFlowchart.SetFloatVariable(fv.Key, fv.Value); } else { fv = currFlowchart.GetVariable <FloatVariable>(ass.destinationVariableName); currFlowchart.SetFloatVariable(fv.Key, fv.Value); } setVar.SetAffectedVariable(fv); break; case Value.Type.Bool: BooleanData bd = new BooleanData(ass.valueExpression.value.value.AsBool); setVar.SetBooleanData(bd); BooleanVariable bv = null; if (currFlowchart.GetVariable <BooleanVariable>(ass.destinationVariableName) == null) { bv = currentFlowchartObj.AddComponent <BooleanVariable>(); bv.Scope = VariableScope.Public; bv.Key = ass.destinationVariableName; bv.Value = false; currFlowchart.AddVariable(bv); currFlowchart.SetBooleanVariable(bv.Key, bv.Value); } else { bv = currFlowchart.GetVariable <BooleanVariable>(ass.destinationVariableName); currFlowchart.SetBooleanVariable(bv.Key, bv.Value); } setVar.SetAffectedVariable(bv); break; default: Debug.LogError("Unknown type"); break; } block.CommandList.Add(setVar); }
public void GetStateFloat(string parameter) { var value = state.GetFloat(parameter); flow.SetFloatVariable(parameter, value); }