private bool IsCloseTo(GameObject thing) { var v = flowchart.GetVariable <VariableBase <Vector3> >("jellyTarget"); var pos = v.Value; var dist = (pos - thing.transform.position).magnitude; Logger.Log(dist); return(dist < 2f); }
protected virtual void Awake() { tileBoard = FindObjectOfType <TileBoardController>(); TileController.AnyClicked += OnAnyTileClicked; swapDurationVar = tileSwapVals.GetVariable("swapDuration") as FloatVariable; swapEnabledVar = tileSwapVals.GetVariable("swapEnabled") as BooleanVariable; cancelAxisVar = tileSwapVals.GetVariable("cancelAxis") as StringVariable; airTileVar = gameVals.GetVariable("airTileType") as ObjectVariable; AnyPhysicalSwapMade += this.OnAnyPhysicalSwapMade; }
void GetReferencesFromScene() { flowchart = GameObject.FindObjectOfType <Flowchart>(); flowchartTransVar = flowchart.GetVariable <TransformVariable>("thisTrans"); gameSaver = GameObject.FindObjectOfType <GameSaver>(); gameLoader = GameObject.FindObjectOfType <GameLoader>(); saveManager = GameObject.FindObjectOfType <SaveManager>(); saveReader = saveManager.SaveReader; someInt = flowchart.GetVariable <IntegerVariable>("someInt"); GetRefsToGameObjects(); }
protected virtual void Awake() { swapEnabled = tileSwapVals.GetVariable("swapEnabled") as BooleanVariable; SetToHighlightWhenTileClicked(); SetToResetWhenSwapHappens(); RegisterTheAirTileType(); }
public void SetRandomDestination() { var target = new Vector3(Random.Range(targetRect.xMin, targetRect.xMax), Random.Range(targetRect.yMin, targetRect.yMax), transform.position.z); var v = flowchart.GetVariable <VariableBase <Vector3> >("jellyTarget"); v.Value = target; }
public void Check() { string glass1 = flowchart.GetVariable("glass1").ToString(); string glass2 = flowchart.GetVariable("glass2").ToString(); string glass3 = flowchart.GetVariable("glass3").ToString(); if (glass1 == "green" && glass2 == "purple" && glass3 == "orange") { flowchart.ExecuteBlock("PaintDone"); } else if ((glass1 == "purple" || glass1 == "green" || glass1 == "orange") && (glass2 == "purple" || glass2 == "green" || glass2 == "orange") && (glass3 == "purple" || glass3 == "green" || glass3 == "orange")) { flowchart.ExecuteBlock("wrongPaint"); } }
void Awake() { TileSwapHandler.AnyPhysicalSwapMade += OnAnyPhysicalSwapMade; TileSwapHandler.AnyBoardSwapMade += OnAnyBoardSwapMade; minAmountForMatch = tileBoardVals.GetVariable("minAmountForMatch") as IntegerVariable; tiles = boardGenerator.GenerateBoard(this); UpdateColumnsAndRows(); }
/// <summary> /// Sets the value of a variable in the flowchart to the value that was passed. /// </summary> public static void SetVariable <TBase, TVarType>(this Flowchart flowchart, string key, TBase value) where TVarType : BaseFungus.VariableBase <TBase> { var variable = flowchart.GetVariable <TVarType>(key); if (variable != null) { variable.Value = value; } else { LetUserKnowVarDoesntExist(flowchart, key); } }
void Start() { Debug.Log(tuFlowchart.GetVariable("isDone")); player.fAmount = 2; player.wAmount = 3; tSystem.isTutorial = true; GameObject p = Resources.Load <GameObject>("Prefabs/Plant"); GameObject plantObject = Instantiate(p); plant = plantObject.GetComponent <Plant>(); plant.transform.position = new Vector3(5.81f, -1.38f, -5f); plant.flowchart = tuFlowchart; nSystem = plant.GetComponent <NourishmentSystem>(); plant.SyncWaterAndFertilizer(nSystem.water, nSystem.fertilizer); }
//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; } } }
protected virtual void DoPointerClick() { if (!clickEnabled) { return; } var block = flowchart.FindBlock(blockName); if (setVariableToMe != "") { var variable = flowchart.GetVariable <Variable>(setVariableToMe); if (variable == null) { Debug.LogError("No variable with the name: " + setVariableToMe); } if (variable is GameObjectVariable) { var goV = variable as GameObjectVariable; goV.Value = gameObject; flowchart.SetVariable <GameObjectVariable>(setVariableToMe, goV); } else if (variable is TransformVariable) { var tV = variable as TransformVariable; tV.Value = transform; flowchart.SetVariable <TransformVariable>(setVariableToMe, tV); } else if (variable is AnimatorVariable) { var aV = variable as AnimatorVariable; aV.Value = GetComponent <Animator>(); flowchart.SetVariable <AnimatorVariable>(setVariableToMe, aV); } else { Debug.LogError("Unsupported variable type: " + setVariableToMe); } } flowchart.ExecuteBlock(block, commandIndex); }
void Awake() { damageVar = hasDamageValue.GetVariable(damageValueName) as FloatVariable; }
void Update() { // パラメータを受け取るまで処理しない if (loadEventParam == null) { return; } // イベントシーンスタート if (!eventStarted) { flowchart.SendFungusMessage(loadEventParam); eventStarted = true; SetInitBackground(loadEventParam); } // イベント終了時:タイトルへ戻る場合 if (flowchart.GetVariable <BooleanVariable>(GameUtil.Const.FUNGUS_KEY_BACK_END).Value) { SceneManager.LoadScene(GameUtil.Const.SCENE_NAME_TITLE); } // イベント終了時:ゲームシーンへ遷移する場合 if (flowchart.GetVariable <BooleanVariable>(GameUtil.Const.FUNGUS_KEY_EVENT_END).Value) { // 読み込んだイベントで遷移先を指定 switch (loadEventParam) { // エピソードN開始 -> ステージN case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE1_START: SceneManager.LoadScene(GameUtil.Const.SCENE_NAME_STAGE1); break; case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE2_START: SceneManager.LoadScene(GameUtil.Const.SCENE_NAME_STAGE2); break; case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE3_START: SceneManager.LoadScene(GameUtil.Const.SCENE_NAME_STAGE3); break; case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE4_START: SceneManager.LoadScene(GameUtil.Const.SCENE_NAME_STAGE4); break; case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE5_START: SceneManager.LoadScene(GameUtil.Const.SCENE_NAME_STAGE5); break; // エピソードN終了 -> エピソードN+1開始 case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE1_END: LoadEpisode(GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE2_START); break; case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE2_END: case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE2_END_2: LoadEpisode(GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE3_START); break; case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE3_END: LoadEpisode(GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE4_START); break; case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE4_END: LoadEpisode(GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE5_START); break; // エンディング case GameUtil.Const.FUNGUS_KEY_EVENT_EPISODE5_END: assetsManager.PlayBGM(GameUtil.Const.BGM_KEY_STOP); SceneManager.LoadScene(GameUtil.Const.SCENE_NAME_END); break; } } // 再生中のオーディオと異なる曲が指定されたら再生 string playBGMKey = flowchart.GetVariable <StringVariable>(GameUtil.Const.FUNGUS_KEY_PLAY_BGM).Value; if (!string.IsNullOrEmpty(playBGMKey)) { if (assetsManager.getPlayingAudio() != assetsManager.getAudioClip(playBGMKey)) { assetsManager.PlayBGM(playBGMKey); } flowchart.SetStringVariable(GameUtil.Const.FUNGUS_KEY_PLAY_BGM, null); } // 効果音が指定されたら再生 string playSEKey = flowchart.GetVariable <StringVariable>(GameUtil.Const.FUNGUS_KEY_PLAY_SE).Value; if (!string.IsNullOrEmpty(playSEKey)) { assetsManager.PlayOneShot(playSEKey); flowchart.SetStringVariable(GameUtil.Const.FUNGUS_KEY_PLAY_SE, null); } // 背景の切替処理 string setBackKey = flowchart.GetVariable <StringVariable>(GameUtil.Const.FUNGUS_KEY_SET_BACKGROUD).Value; if (!string.IsNullOrEmpty(setBackKey)) { SwitchBackground(setBackKey); flowchart.SetStringVariable(GameUtil.Const.FUNGUS_KEY_SET_BACKGROUD, null); } }
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 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); }
void GetHealthValueContainers() { healthValueContainer = hasHealthValues.GetVariable(healthValueName) as FloatVariable; maxHealthValueContainer = hasHealthValues.GetVariable(maxHealthValueName) as FloatVariable; }
void RegisterTheAirTileType() { airTileVar = gameVals.GetVariable("airTileType") as ObjectVariable; }
private void Awake() { xPosition = hasXPosition.GetVariable(xPositionName) as FloatVariable; }
void Awake() { healthVariable = hasHealthValue.GetVariable(healthValueName) as FloatVariable; }