public void SetCharactersInTeam(string main, string second) { var list = new InkList("CharactersInTeam", inkStory); list.AddItem(main); if (!String.IsNullOrEmpty(second)) { list.AddItem(second); } inkStory.variablesState["CharactersInTeam"] = list; }
public void OnVariablesChanged(Flowchart origin) { Debug.Log("OnVariablesChange origin=" + origin.name); if (beforeFirstSync) { Debug.Log("Still initializing, Fungus->Ink sync request ignored"); return; } List <Variable> affectedFungusVariables; if (origin != null) { affectedFungusVariables = origin.Variables; } else { affectedFungusVariables = new List <Variable>(); foreach (KeyValuePair <string, List <Flowchart> > syncVariable in syncVariables) { // Picks the first flowchart: any flowchart is OK, it's a global variable affectedFungusVariables.Add(syncVariable.Value[0].GetVariable(syncVariable.Key)); } } bool useless = true; foreach (Variable fungusVariable in affectedFungusVariables) { if (fungusVariable.Scope == VariableScope.Global && syncVariables.ContainsKey(fungusVariable.Key)) { useless = false; Type fungusVariableType = fungusVariable.GetValue().GetType(); if (fungusVariableType == typeof(int)) { int intValue = (fungusVariable as IntegerVariable).Value; Debug.Log(fungusVariable.Key + "=" + intValue + " (Fungus->Ink)"); story.variablesState[fungusVariable.Key] = intValue; } else if (fungusVariableType == typeof(string)) { string stringValue = (fungusVariable as StringVariable).Value; Debug.Log(fungusVariable.Key + "=" + stringValue + " (Fungus->Ink)"); story.variablesState[fungusVariable.Key] = stringValue; } else if (fungusVariableType == typeof(float)) { float floatValue = (fungusVariable as FloatVariable).Value; Debug.Log(fungusVariable.Key + "=" + floatValue + " (Fungus->Ink)"); story.variablesState[fungusVariable.Key] = floatValue; } else if (fungusVariableType == typeof(bool)) { bool boolValue = (fungusVariable as BooleanVariable).Value; Debug.Log(fungusVariable.Key + "=" + boolValue + " (Fungus->Ink)"); string[] listVariableParts = SplitFungusVariableName(fungusVariable.Key); if (listVariableParts.Length <= 1) { story.variablesState[fungusVariable.Key] = (boolValue ? 1 : 0); } else { string listName = listVariableParts[0]; string listItemName = listVariableParts[1]; InkList inkList = story.variablesState[listName] as InkList; if (inkList == null) { Debug.LogError("Sync list mismatch: " + listName + " is not a list in Ink"); } else { if (boolValue) { if (!inkList.ContainsItemNamed(listItemName)) { inkList.AddItem(listItemName); Debug.Log(listItemName + " added in Ink list " + listName); } } else { List <InkListItem> toRemove = new List <InkListItem>(); foreach (InkListItem inkListItem in inkList.Keys) { if (inkListItem.itemName == listItemName) { toRemove.Add(inkListItem); } } foreach (InkListItem inkListItem in toRemove) { inkList.Remove(inkListItem); Debug.Log(inkListItem.fullName + " removed from Ink list " + listName); } } } } } else { Debug.LogWarning("Sync variable skipped: " + fungusVariable.Key + " is " + fungusVariableType + " in Fungus, which does not translate well to Ink"); } } } if (useless) { Debug.LogWarning("No global Fungus variables to sync, consider removing this OnVariablesChange call from the flowchart"); } }