Browse Source

Merge pull request #345 from FungusGames/read-text-file

Read a text file into a string variable #344
master
Chris Gregan 9 years ago
parent
commit
05d6e15e72
  1. 60
      Assets/Fungus/Flowchart/Scripts/Commands/ReadTextFile.cs
  2. 12
      Assets/Fungus/Flowchart/Scripts/Commands/ReadTextFile.cs.meta
  3. 356
      Assets/Tests/Scripting/Scripting.unity
  4. 9
      Assets/Tests/TestAssets/Text.meta
  5. 1
      Assets/Tests/TestAssets/Text/text.txt
  6. 8
      Assets/Tests/TestAssets/Text/text.txt.meta

60
Assets/Fungus/Flowchart/Scripts/Commands/ReadTextFile.cs

@ -0,0 +1,60 @@
using UnityEngine;
using System.Collections;
using Fungus;
namespace Fungus
{
[CommandInfo("Variable",
"Read Text File",
"Reads in a text file and stores the contents in a string variable")]
public class ReadTextFile : Command
{
[Tooltip("Text file to read into the string variable")]
public TextAsset textFile;
[Tooltip("String variable to store the tex file contents in")]
[VariableProperty(typeof(StringVariable))]
public StringVariable stringVariable;
public override void OnEnter()
{
if (textFile == null ||
stringVariable == null)
{
Continue();
return;
}
stringVariable.value = textFile.text;
Continue();
}
public override string GetSummary()
{
if (stringVariable == null)
{
return "Error: Variable not selected";
}
if (textFile == null)
{
return "Error: Text file not selected";
}
return stringVariable.key;
}
public override bool HasReference(Variable variable)
{
return (variable == stringVariable);
}
public override Color GetButtonColor()
{
return new Color32(253, 253, 150, 255);
}
}
}

12
Assets/Fungus/Flowchart/Scripts/Commands/ReadTextFile.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1c0d03b6eb503400fab7982a48c8a93a
timeCreated: 1445960955
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

356
Assets/Tests/Scripting/Scripting.unity

@ -8,25 +8,25 @@ SceneSettings:
m_PVSPortalsArray: []
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: .25
smallestHole: 0.25
backfaceThreshold: 100
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
m_Fog: 0
m_FogColor: {r: .5, g: .5, b: .5, a: 1}
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: .00999999978
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: .211999997, g: .226999998, b: .259000003, a: 1}
m_AmbientEquatorColor: {r: .114, g: .125, b: .133000001, a: 1}
m_AmbientGroundColor: {r: .0469999984, g: .0430000015, b: .0350000001, a: 1}
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: .5
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
@ -40,7 +40,7 @@ RenderSettings:
--- !u!157 &4
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 5
serializedVersion: 6
m_GIWorkflowMode: 1
m_LightmapsMode: 1
m_GISettings:
@ -66,7 +66,7 @@ LightmapSettings:
m_FinalGather: 0
m_FinalGatherRayCount: 1024
m_ReflectionCompression: 2
m_LightmapSnapshot: {fileID: 0}
m_LightingDataAsset: {fileID: 0}
m_RuntimeCPUUsage: 25
--- !u!196 &5
NavMeshSettings:
@ -74,15 +74,15 @@ NavMeshSettings:
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentRadius: .5
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: .400000006
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
accuratePlacement: 0
minRegionArea: 2
cellSize: .166666672
cellSize: 0.16666667
manualCellSize: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &169310208
@ -257,7 +257,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
--- !u!1 &396492925
GameObject:
m_ObjectHideFlags: 0
@ -835,12 +835,13 @@ MonoBehaviour:
itemId: 8
errorMessage:
indentLevel: 0
duration: .25
duration: 0.25
fadeOut: 0
targetView: {fileID: 1759271211}
waitUntilFinished: 1
fadeColor: {r: 0, g: 0, b: 0, a: 1}
fadeTexture: {fileID: 0}
targetCamera: {fileID: 0}
--- !u!114 &590474774
MonoBehaviour:
m_ObjectHideFlags: 2
@ -1014,6 +1015,7 @@ MonoBehaviour:
duration: 5
targetView: {fileID: 1920662343}
waitUntilFinished: 1
targetCamera: {fileID: 0}
--- !u!1 &636123604
GameObject:
m_ObjectHideFlags: 0
@ -1221,12 +1223,13 @@ MonoBehaviour:
itemId: 8
errorMessage:
indentLevel: 0
duration: .100000001
duration: 0.1
fadeOut: 0
targetView: {fileID: 0}
waitUntilFinished: 1
fadeColor: {r: 0, g: 0, b: 0, a: 1}
fadeTexture: {fileID: 0}
targetCamera: {fileID: 0}
--- !u!114 &636123615
MonoBehaviour:
m_ObjectHideFlags: 2
@ -1282,7 +1285,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 61dddfdc5e0e44ca298d8f46f7f5a915, type: 3}
m_Name:
m_EditorClassIdentifier:
selectedFlowchart: {fileID: 590474781}
selectedFlowchart: {fileID: 1982550314}
--- !u!4 &646902075
Transform:
m_ObjectHideFlags: 1
@ -1295,6 +1298,56 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!1 &697320579
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 697320581}
- 114: {fileID: 697320580}
m_Layer: 0
m_Name: ReadTextFileTest
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &697320580
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 697320579}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b1dba0b27b0864740a8720e920aa88c0, type: 3}
m_Name:
m_EditorClassIdentifier:
timeout: 5
ignored: 0
succeedAfterAllAssertionsAreExecuted: 0
expectException: 0
expectedExceptionList:
succeedWhenExceptionIsThrown: 0
includedPlatforms: -1
platformsToIgnore: []
dynamic: 0
dynamicTypeName:
--- !u!4 &697320581
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 697320579}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1982550309}
m_Father: {fileID: 0}
m_RootOrder: 7
--- !u!1 &756526316
GameObject:
m_ObjectHideFlags: 0
@ -1344,14 +1397,14 @@ Camera:
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: .300000012
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
@ -1367,7 +1420,7 @@ Camera:
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: .0219999999
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!4 &756526321
Transform:
@ -1380,7 +1433,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_RootOrder: 1
--- !u!1 &842242620
GameObject:
m_ObjectHideFlags: 0
@ -1427,7 +1480,7 @@ MonoBehaviour:
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: .5
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &842242623
MonoBehaviour:
@ -1454,7 +1507,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
--- !u!1 &911947601
GameObject:
m_ObjectHideFlags: 0
@ -1483,7 +1536,7 @@ Transform:
m_Children:
- {fileID: 396492935}
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
--- !u!114 &911947603
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1561,7 +1614,7 @@ Transform:
- {fileID: 1759271210}
- {fileID: 1920662342}
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
--- !u!1 &1141004796
GameObject:
m_ObjectHideFlags: 0
@ -1591,11 +1644,11 @@ RectTransform:
m_Children: []
m_Father: {fileID: 1960747668}
m_RootOrder: 0
m_AnchorMin: {x: .5, y: .5}
m_AnchorMax: {x: .5, y: .5}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 4, y: 128}
m_SizeDelta: {x: 609, y: 81}
m_Pivot: {x: .5, y: .5}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1141004798
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1623,6 +1676,7 @@ MonoBehaviour:
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
@ -1680,14 +1734,18 @@ SpriteRenderer:
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_AutoUVMaxDistance: .5
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: d568b9f360a9641fba3a3c558cfbd607, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
--- !u!1 &1384749029
GameObject:
m_ObjectHideFlags: 0
@ -1717,7 +1775,7 @@ Transform:
- {fileID: 1618689133}
- {fileID: 1960615185}
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
--- !u!114 &1384749031
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1878,7 +1936,7 @@ MonoBehaviour:
typeFullname: System.Single
intValue: 0
boolValue: 0
floatValue: 5.19999981
floatValue: 5.2
stringValue:
colorValue: {r: 0, g: 0, b: 0, a: 0}
gameObjectValue: {fileID: 0}
@ -2041,7 +2099,7 @@ MonoBehaviour:
typeFullname: System.Single
intValue: 0
boolValue: 0
floatValue: 5.19999981
floatValue: 5.2
stringValue:
colorValue: {r: 0, g: 0, b: 0, a: 0}
gameObjectValue: {fileID: 0}
@ -2558,7 +2616,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 95c387d3e32404bcc91c60318d766bb1, type: 3}
m_Name:
m_EditorClassIdentifier:
viewSize: 1.74694014
viewSize: 1.7469401
primaryAspectRatio: {x: 4, y: 3}
secondaryAspectRatio: {x: 2, y: 1}
--- !u!1 &1920662341
@ -2601,7 +2659,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 95c387d3e32404bcc91c60318d766bb1, type: 3}
m_Name:
m_EditorClassIdentifier:
viewSize: .795018613
viewSize: 0.7950186
primaryAspectRatio: {x: 4, y: 3}
secondaryAspectRatio: {x: 2, y: 1}
--- !u!1 &1960615183
@ -2640,7 +2698,7 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1960615183}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -.137771219, y: -.16843766, z: 0}
m_LocalPosition: {x: -0.13777122, y: -0.16843766, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1384749030}
@ -2735,3 +2793,233 @@ Canvas:
m_OverridePixelPerfect: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!1 &1982550308
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 142980, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1982550309}
- 114: {fileID: 1982550314}
- 114: {fileID: 1982550313}
- 114: {fileID: 1982550312}
- 114: {fileID: 1982550311}
- 114: {fileID: 1982550310}
- 114: {fileID: 1982550319}
- 114: {fileID: 1982550318}
- 114: {fileID: 1982550317}
- 114: {fileID: 1982550316}
- 114: {fileID: 1982550315}
m_Layer: 0
m_Name: Flowchart
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1982550309
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 467082, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 697320581}
m_RootOrder: 0
--- !u!114 &1982550310
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4580f28dd8581476b810b38eea2f1316, type: 3}
m_Name:
m_EditorClassIdentifier:
scope: 0
key: StringVar
value:
--- !u!114 &1982550311
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1c0d03b6eb503400fab7982a48c8a93a, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 1
errorMessage:
indentLevel: 0
textFile: {fileID: 4900000, guid: 79d0482254a77462cb1e27a74f2d07e5, type: 3}
stringVariable: {fileID: 1982550310}
--- !u!114 &1982550312
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 11462346, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3}
m_Name:
m_EditorClassIdentifier:
parentBlock: {fileID: 1982550313}
--- !u!114 &1982550313
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 11433304, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3}
m_Name:
m_EditorClassIdentifier:
nodeRect:
serializedVersion: 2
x: 67
y: 70
width: 120
height: 40
itemId: 0
blockName: Start
description:
eventHandler: {fileID: 1982550312}
commandList:
- {fileID: 1982550311}
- {fileID: 1982550319}
- {fileID: 1982550316}
- {fileID: 1982550318}
- {fileID: 1982550315}
- {fileID: 1982550317}
--- !u!114 &1982550314
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11430050, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 1.0
scrollPos: {x: 0, y: 0}
variablesScrollPos: {x: 0, y: 0}
variablesExpanded: 1
blockViewHeight: 400
zoom: 1
scrollViewRect:
serializedVersion: 2
x: -343
y: -340
width: 1114
height: 859
selectedBlock: {fileID: 1982550313}
selectedCommands: []
variables:
- {fileID: 1982550310}
description:
stepPause: 0
colorCommands: 1
hideComponents: 1
saveSelection: 1
localizationId:
hideCommands: []
--- !u!114 &1982550315
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2dcb71131f45b47fead560a97ef55f1c, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 6
errorMessage:
indentLevel: 1
failMessage:
--- !u!114 &1982550316
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4920f47cde1a84b11ad07b7317568494, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 5
errorMessage:
indentLevel: 1
--- !u!114 &1982550317
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 93cb9773f2ca04e2bbf7a68ccfc23267, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 4
errorMessage:
indentLevel: 0
--- !u!114 &1982550318
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3fa968f01a7f9496bb50e13dfe16760d, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 3
errorMessage:
indentLevel: 0
--- !u!114 &1982550319
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1982550308}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70c5622b8a80845c980954170295f292, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 2
errorMessage:
indentLevel: 0
compareOperator: 0
variable: {fileID: 1982550310}
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
integerData:
integerRef: {fileID: 0}
integerVal: 0
floatData:
floatRef: {fileID: 0}
floatVal: 0
stringData:
stringRef: {fileID: 0}
stringVal: test

9
Assets/Tests/TestAssets/Text.meta

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 397a031d497e1439c841af3872ae3b3f
folderAsset: yes
timeCreated: 1452700950
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

1
Assets/Tests/TestAssets/Text/text.txt

@ -0,0 +1 @@
test

8
Assets/Tests/TestAssets/Text/text.txt.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 79d0482254a77462cb1e27a74f2d07e5
timeCreated: 1452700950
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save