-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
folder cleanup - completed samples - less debug noise
- Loading branch information
Showing
24 changed files
with
5,736 additions
and
23 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Squiggle.Unity/Assets/Squiggle/Common/SquiggleUnityRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using UnityEngine; | ||
|
||
public class SquiggleUnityRunner : MonoBehaviour | ||
{ | ||
|
||
} | ||
// public class Runner : MonoBehaviour | ||
// { | ||
|
||
// } | ||
// public static void UnityWaitOverride(Squiggle.Commands.Wait waitCommand) | ||
// { | ||
// StartCoroutine(WaitMs(waitCommand)); | ||
// } | ||
|
||
// static IEnumerator WaitMs(Squiggle.Commands.Wait waitCommand) | ||
// { | ||
// yield return new WaitForSeconds(waitCommand.WaitMS / 1000f); | ||
// waitCommand.CommandExecutionComplete?.Invoke(); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections; | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
using System.IO; | ||
|
||
namespace Squiggle.Unity | ||
{ | ||
public static class Utils | ||
{ | ||
public static string ReadTextFileFromStreamingAssets(string sFileName) | ||
{ | ||
//Debug.Log("Reading " + sFileName); | ||
//Check to see if the filename specified exists, if not try adding '.txt', otherwise fail | ||
string sFileNameFound = ""; | ||
if (File.Exists(Application.streamingAssetsPath + "/" + sFileName)) | ||
{ | ||
//Debug.Log("Reading '" + sFileName + "'."); | ||
sFileNameFound = Application.streamingAssetsPath + "/" + sFileName; //file found | ||
} | ||
else if (File.Exists(Application.streamingAssetsPath + "/" + sFileName + ".txt")) | ||
{ | ||
sFileNameFound = Application.streamingAssetsPath + "/" + sFileName + ".txt"; | ||
} | ||
else | ||
{ | ||
Debug.Log("Could not find file '" + sFileName + "'."); | ||
return null; | ||
} | ||
|
||
StreamReader sr; | ||
try | ||
{ | ||
sr = new StreamReader(sFileNameFound); | ||
} | ||
catch (System.Exception e) | ||
{ | ||
Debug.LogWarning("Something went wrong with read. " + e.Message); | ||
return null; | ||
} | ||
|
||
string fileContents = sr.ReadToEnd(); | ||
sr.Close(); | ||
|
||
return fileContents; | ||
} | ||
} | ||
} |
Binary file not shown.
73 changes: 73 additions & 0 deletions
73
...ggle.Unity/Assets/Squiggle/Sample Scenes/1 - Monobehaviour/SquiggleMonobehaviourSample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using UnityEngine.EventSystems; | ||
using Squiggle; | ||
|
||
public class SquiggleMonobehaviourSample : MonoBehaviour | ||
{ | ||
public Text SpeakerName; | ||
public Text SpeakerText; | ||
public Button RunSquiggle; | ||
[TextArea] | ||
public string SquiggleCode; | ||
void OnEnable() | ||
{ | ||
SpeakerName.text = ""; | ||
SpeakerText.text = ""; | ||
|
||
RunSquiggle.onClick.AddListener(() => { | ||
EventSystem.current.SetSelectedGameObject(null); | ||
StartCoroutine(TryExecuteSquiggle()); | ||
}); | ||
} | ||
void OnDisable() | ||
{ | ||
RunSquiggle.onClick.RemoveAllListeners(); | ||
} | ||
|
||
Squiggle.Runner currentRunner; | ||
bool currentlyRunning = false; | ||
IEnumerator TryExecuteSquiggle() | ||
{ | ||
if(currentlyRunning) | ||
{ | ||
yield return null; | ||
} | ||
|
||
currentlyRunning = true; | ||
currentRunner = Squiggle.Core.Run( squiggleText : SquiggleCode, | ||
runnerOptions : new Squiggle.Runner.Options(){ | ||
AutoStart = false, | ||
Debug = true, | ||
LogHandler = (text) => Debug.Log(text), | ||
WaitOverride = (command) => StartCoroutine(WaitMs(command)), | ||
DialogHandler = (command) => { | ||
SpeakerName.text = command.Speaker; | ||
SpeakerText.text = command.Text; | ||
command.CommandExecutionComplete?.Invoke(); | ||
}, | ||
}); | ||
|
||
currentRunner.CompletedExecution += OnRunnerComplete; | ||
currentRunner.Start(); | ||
yield return null; | ||
} | ||
|
||
IEnumerator WaitMs(Squiggle.Commands.Wait waitCommand) | ||
{ | ||
Debug.Log("inside wait ms"); | ||
yield return new WaitForSeconds(waitCommand.WaitMS / 1000f); | ||
waitCommand.CommandExecutionComplete?.Invoke(); | ||
} | ||
|
||
void OnRunnerComplete() | ||
{ | ||
currentRunner.CompletedExecution -= OnRunnerComplete; | ||
currentRunner = null; | ||
currentlyRunning = false; | ||
SpeakerName.text = ""; | ||
SpeakerText.text = ""; | ||
} | ||
} |
Oops, something went wrong.