protected override void Apply() { base.Apply(); // Get all declarations that came from this program var thisProgramDeclarations = new List <Yarn.Compiler.Declaration>(); for (int i = 0; i < serializedDeclarationsProperty.arraySize; i++) { var decl = serializedDeclarationsProperty.GetArrayElementAtIndex(i); if (decl.FindPropertyRelative("sourceYarnAsset").objectReferenceValue != null) { continue; } var name = decl.FindPropertyRelative("name").stringValue; SerializedProperty typeProperty = decl.FindPropertyRelative("type"); Type type = (Yarn.Type)typeProperty.enumValueIndex; var description = decl.FindPropertyRelative("description").stringValue; object defaultValue; switch (type) { case Yarn.Type.Number: defaultValue = decl.FindPropertyRelative("defaultValueNumber").floatValue; break; case Yarn.Type.String: defaultValue = decl.FindPropertyRelative("defaultValueString").stringValue; break; case Yarn.Type.Bool: defaultValue = decl.FindPropertyRelative("defaultValueBool").boolValue; break; default: throw new System.ArgumentOutOfRangeException($"Invalid declaration type {type}"); } var declaration = Declaration.CreateVariable(name, defaultValue, description); thisProgramDeclarations.Add(declaration); } var output = Yarn.Compiler.Utility.GenerateYarnFileWithDeclarations(thisProgramDeclarations, "Program"); var importer = target as YarnProjectImporter; File.WriteAllText(importer.assetPath, output, System.Text.Encoding.UTF8); AssetDatabase.ImportAsset(importer.assetPath); }
protected override void Apply() { base.Apply(); // Get all declarations that came from this program var thisProgramDeclarations = new List <Yarn.Compiler.Declaration>(); for (int i = 0; i < serializedDeclarationsProperty.arraySize; i++) { var decl = serializedDeclarationsProperty.GetArrayElementAtIndex(i); if (decl.FindPropertyRelative("sourceYarnAsset").objectReferenceValue != null) { continue; } var name = decl.FindPropertyRelative("name").stringValue; SerializedProperty typeProperty = decl.FindPropertyRelative("typeName"); Yarn.IType type = YarnProjectImporter.SerializedDeclaration.BuiltInTypesList.FirstOrDefault(t => t.Name == typeProperty.stringValue); var description = decl.FindPropertyRelative("description").stringValue; System.IConvertible defaultValue; if (type == Yarn.BuiltinTypes.Number) { defaultValue = decl.FindPropertyRelative("defaultValueNumber").floatValue; } else if (type == Yarn.BuiltinTypes.String) { defaultValue = decl.FindPropertyRelative("defaultValueString").stringValue; } else if (type == Yarn.BuiltinTypes.Boolean) { defaultValue = decl.FindPropertyRelative("defaultValueBool").boolValue; } else { throw new System.ArgumentOutOfRangeException($"Invalid declaration type {type.Name}"); } var declaration = Declaration.CreateVariable(name, type, defaultValue, description); thisProgramDeclarations.Add(declaration); } var output = Yarn.Compiler.Utility.GenerateYarnFileWithDeclarations(thisProgramDeclarations, "Program"); var importer = target as YarnProjectImporter; File.WriteAllText(importer.assetPath, output, System.Text.Encoding.UTF8); AssetDatabase.ImportAsset(importer.assetPath); }