Fixed InstructionUIs & water timer

This commit is contained in:
Nicklas 2024-03-20 09:31:54 +01:00
parent ca0e05da63
commit b67d2b3e80
14 changed files with 62 additions and 54 deletions

BIN
.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -26,6 +26,8 @@ public class BoundAirScript : MonoBehaviour
private bool objectHasBeenCollected = false; private bool objectHasBeenCollected = false;
public GameObject airInstructionUI;
//Boundary control //Boundary control
public BoundaryControlScript boundControl; public BoundaryControlScript boundControl;
@ -57,6 +59,8 @@ public class BoundAirScript : MonoBehaviour
audioSource.PlayOneShot(narrationClip); audioSource.PlayOneShot(narrationClip);
yield return new WaitForSeconds(narrationClip.length); yield return new WaitForSeconds(narrationClip.length);
canActivateAir = true; canActivateAir = true;
//Instructions UI appear
airInstructionUI.SetActive(true);
} }
@ -130,6 +134,7 @@ public class BoundAirScript : MonoBehaviour
public void stationCompleted() public void stationCompleted()
{ {
airInstructionUI.SetActive(false);
windObjectToCollect.SetActive(false); windObjectToCollect.SetActive(false);
//boundControl.ReactivateBoundary(); //boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Air"); boundControl.RemoveBoundary("Air");

@ -15,6 +15,8 @@ public class BoundEarthScript : MonoBehaviour
public GameObject earthObjectToCollect; public GameObject earthObjectToCollect;
public GameObject earthInstructionUI;
private bool objectHasBeenCollected = false; private bool objectHasBeenCollected = false;
@ -41,9 +43,8 @@ public class BoundEarthScript : MonoBehaviour
audioSource.PlayOneShot(narrationClip); audioSource.PlayOneShot(narrationClip);
yield return new WaitForSeconds(narrationClip.length); yield return new WaitForSeconds(narrationClip.length);
narrationHasFinished = true; narrationHasFinished = true;
earthInstructionUI.SetActive(true);
} }
public void collectForce() { public void collectForce() {
@ -57,6 +58,7 @@ public class BoundEarthScript : MonoBehaviour
public void stationCompleted() public void stationCompleted()
{ {
earthInstructionUI.SetActive(false);
earthObjectToCollect.SetActive(false); earthObjectToCollect.SetActive(false);
//boundControl.ReactivateBoundary(); //boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Earth"); boundControl.RemoveBoundary("Earth");

@ -15,6 +15,8 @@ public class BoundFireScript : MonoBehaviour
public GameObject fireObjectToThrow; public GameObject fireObjectToThrow;
public GameObject fireObjectToCollect; public GameObject fireObjectToCollect;
public GameObject fireInstructionUI;
private bool objectHasBeenCollected = false; private bool objectHasBeenCollected = false;
@ -44,7 +46,7 @@ public class BoundFireScript : MonoBehaviour
yield return new WaitForSeconds(narrationClip.length); yield return new WaitForSeconds(narrationClip.length);
fireObjectToThrow.SetActive(true); fireObjectToThrow.SetActive(true);
narrationHasFinished = true; narrationHasFinished = true;
fireInstructionUI.SetActive(true);
} }
public void CollectFireObject() public void CollectFireObject()
@ -62,6 +64,7 @@ public class BoundFireScript : MonoBehaviour
public void stationCompleted() public void stationCompleted()
{ {
fireInstructionUI.SetActive(false);
fireObjectToCollect.SetActive(false); fireObjectToCollect.SetActive(false);
//boundControl.ReactivateBoundary(); //boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Fire"); boundControl.RemoveBoundary("Fire");

@ -14,6 +14,8 @@ public class BoundWaterScript : MonoBehaviour
public GameObject waterObjectToCollect; public GameObject waterObjectToCollect;
public GameObject waterInstructionUI;
private bool objectHasBeenCollected = false; private bool objectHasBeenCollected = false;
@ -41,9 +43,8 @@ public class BoundWaterScript : MonoBehaviour
{ {
narrationHasStarted = true; narrationHasStarted = true;
audioSource.PlayOneShot(narrationClip); audioSource.PlayOneShot(narrationClip);
yield return new WaitForSeconds(narrationClip.length); yield return new WaitForSeconds(narrationClip.length);
waterInstructionUI.SetActive(true);
narrationHasFinished = true; narrationHasFinished = true;
} }
@ -62,6 +63,7 @@ public class BoundWaterScript : MonoBehaviour
public void stationCompleted() public void stationCompleted()
{ {
waterInstructionUI.SetActive(false);
waterObjectToCollect.SetActive(false); waterObjectToCollect.SetActive(false);
//boundControl.ReactivateBoundary(); //boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Water"); boundControl.RemoveBoundary("Water");

@ -10,12 +10,6 @@ public class BoundaryControlScript : MonoBehaviour
public GameObject waterBoundary; public GameObject waterBoundary;
public GameObject fireBoundary; public GameObject fireBoundary;
//Instruction UI's
public GameObject airInstructionUI;
public GameObject earthInstructionUI;
public GameObject waterInstructionUI;
public GameObject fireInstructionUI;
//Collection images //Collection images
public GameObject airNotCollectedImage; public GameObject airNotCollectedImage;
public GameObject airCollectedImage; public GameObject airCollectedImage;
@ -47,29 +41,24 @@ public class BoundaryControlScript : MonoBehaviour
{ {
if (bound == "Air") if (bound == "Air")
{ {
//Instructions UI appear
airInstructionUI.SetActive(true);
earthBoundary.SetActive(false); earthBoundary.SetActive(false);
waterBoundary.SetActive(false); waterBoundary.SetActive(false);
fireBoundary.SetActive(false); fireBoundary.SetActive(false);
} }
else if (bound == "Earth") else if (bound == "Earth")
{ {
earthInstructionUI.SetActive(true);
airBoundary.SetActive(false); airBoundary.SetActive(false);
waterBoundary.SetActive(false); waterBoundary.SetActive(false);
fireBoundary.SetActive(false); fireBoundary.SetActive(false);
} }
else if (bound == "Water") else if (bound == "Water")
{ {
waterInstructionUI.SetActive(true);
earthBoundary.SetActive(false); earthBoundary.SetActive(false);
airBoundary.SetActive(false); airBoundary.SetActive(false);
fireBoundary.SetActive(false); fireBoundary.SetActive(false);
} }
else if (bound == "Fire") else if (bound == "Fire")
{ {
fireInstructionUI.SetActive(true);
earthBoundary.SetActive(false); earthBoundary.SetActive(false);
waterBoundary.SetActive(false); waterBoundary.SetActive(false);
airBoundary.SetActive(false); airBoundary.SetActive(false);
@ -107,7 +96,6 @@ public class BoundaryControlScript : MonoBehaviour
{ {
airFinished = true; airFinished = true;
collectionCounter++; collectionCounter++;
airInstructionUI.SetActive(false);
airNotCollectedImage.SetActive(false); airNotCollectedImage.SetActive(false);
airCollectedImage.SetActive(true); airCollectedImage.SetActive(true);
StartCoroutine(PlayCollectionNarration()); StartCoroutine(PlayCollectionNarration());
@ -118,7 +106,6 @@ public class BoundaryControlScript : MonoBehaviour
{ {
earthFinished = true; earthFinished = true;
collectionCounter++; collectionCounter++;
earthInstructionUI.SetActive(false);
earthNotCollectedImage.SetActive(false); earthNotCollectedImage.SetActive(false);
earthCollectedImage.SetActive(true); earthCollectedImage.SetActive(true);
StartCoroutine(PlayCollectionNarration()); StartCoroutine(PlayCollectionNarration());
@ -130,7 +117,6 @@ public class BoundaryControlScript : MonoBehaviour
{ {
waterFinished = true; waterFinished = true;
collectionCounter++; collectionCounter++;
waterInstructionUI.SetActive(false);
waterNotCollectedImage.SetActive(false); waterNotCollectedImage.SetActive(false);
waterCollectedImage.SetActive(true); waterCollectedImage.SetActive(true);
StartCoroutine(PlayCollectionNarration()); StartCoroutine(PlayCollectionNarration());
@ -142,7 +128,6 @@ public class BoundaryControlScript : MonoBehaviour
{ {
fireFinished = true; fireFinished = true;
collectionCounter++; collectionCounter++;
fireInstructionUI.SetActive(false);
fireNotCollectedImage.SetActive(false); fireNotCollectedImage.SetActive(false);
fireCollectedImage.SetActive(true); fireCollectedImage.SetActive(true);
StartCoroutine(PlayCollectionNarration()); StartCoroutine(PlayCollectionNarration());

@ -8,27 +8,23 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
{ {
// Websocket Service // Websocket Service
WebSocket ws; WebSocket ws;
//public AudioSource audioSource; // Assign in inspector
//public AudioClip narrationClip; // Assign in inspector
//
public string esp32IPAddress = "10.204.0.249"; // Assign your ESP32 IP Address public string esp32IPAddress = "10.204.0.249"; // Assign your ESP32 IP Address
public string esp32WebsocketPort = "81"; // Assign your ESP32 WebSocket port, typically "81" public string esp32WebsocketPort = "81"; // Assign your ESP32 WebSocket port, typically "81"
private bool touchDataReceived = false; private bool touchDataReceived = false;
private int receivedTouchValue = 0; private int receivedTouchValue = 0;
public static bool isTouchDetected = false; public static bool isTouchDetected = false;
int threshhold = 14000; int threshhold = 14000;
public BoundWaterScript waterScript; public BoundWaterScript waterScript;
private float narrationEndTime;
private float waitTime = 15f;
private bool objectAppeared = false; // Flag to track whether the object has appeared or not
private bool startedMeasuringTime = false; // Flag to track whether the time measurement has started
void Start() void Start()
{ {
ConnectWithESP32(); ConnectWithESP32();
} }
public void ConnectWithESP32() public void ConnectWithESP32()
@ -55,29 +51,43 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
Debug.Log("Websocket state - " + ws.ReadyState); Debug.Log("Websocket state - " + ws.ReadyState);
} }
void Update() void Update()
{//Change to Water script {
if (waterScript.narrationHasFinished && !waterScript.dropHasAppeared) if (waterScript.narrationHasFinished && !waterScript.dropHasAppeared)
{ {
Debug.Log("Asking for touch."); if (!startedMeasuringTime)
ws.Send("Need Touch");
if (touchDataReceived)
{ {
if (receivedTouchValue >= threshhold) startedMeasuringTime = true;
{ narrationEndTime = Time.realtimeSinceStartup;
Debug.Log("Touch threshold exceeded, action triggered."); }
isTouchDetected = true;
waterScript.collectTouch();
float elapsedTime = Time.realtimeSinceStartup - narrationEndTime;
if (elapsedTime < waitTime)
{
Debug.Log("Asking for touch.");
ws.Send("Need Touch");
if (touchDataReceived)
{
if (receivedTouchValue >= threshhold)
{
Debug.Log("Touch threshold exceeded, action triggered.");
isTouchDetected = true;
waterScript.collectTouch();
return; // Exit the update loop if touch threshold condition is met
}
touchDataReceived = false; // Reset for the next message
} }
touchDataReceived = false; // Reset for the next message }
else if (!objectAppeared && elapsedTime >= waitTime)
{
Debug.Log("15 seconds have passed since the end of narration.");
// Perform your desired action here after 15 seconds from the end of the narration
waterScript.collectTouch(); // Call collectTouch() method after 15 seconds
objectAppeared = true; // Set the flag to indicate that the object has appeared
} }
} }
} }
void OnDestroy() void OnDestroy()
@ -87,5 +97,4 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
ws.Close(); ws.Close();
} }
} }
} }

@ -14,7 +14,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
targetDeviceTypes: 020000000300000004000000 targetDeviceTypes: 020000000300000004000000
allowOptional3DofHeadTracking: 0 allowOptional3DofHeadTracking: 0
handTrackingSupport: 1 handTrackingSupport: 2
handTrackingFrequency: 1 handTrackingFrequency: 1
handTrackingVersion: 0 handTrackingVersion: 0
anchorSupport: 0 anchorSupport: 0

@ -8971,8 +8971,8 @@ BoxCollider:
m_ProvidesContacts: 0 m_ProvidesContacts: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Size: {x: 0.95211536, y: 1.4736786, z: 4.5547028} m_Size: {x: 0.95211536, y: 1.5365968, z: 4.5547028}
m_Center: {x: -0.3927261, y: 0.23683935, z: -0.21766186} m_Center: {x: -0.3927261, y: 0.2682984, z: -0.21766186}
--- !u!54 &515544900 --- !u!54 &515544900
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -10768,6 +10768,7 @@ MonoBehaviour:
narrationClip: {fileID: 8300000, guid: 687001dfd7eb24ccca4eb0e4db510dca, type: 3} narrationClip: {fileID: 8300000, guid: 687001dfd7eb24ccca4eb0e4db510dca, type: 3}
narrationClipTwo: {fileID: 8300000, guid: 8cb9b31b6571647878893398d64e6f19, type: 3} narrationClipTwo: {fileID: 8300000, guid: 8cb9b31b6571647878893398d64e6f19, type: 3}
windObjectToCollect: {fileID: 140392492} windObjectToCollect: {fileID: 140392492}
airInstructionUI: {fileID: 770984586}
boundControl: {fileID: 979159588} boundControl: {fileID: 979159588}
--- !u!82 &579970260 --- !u!82 &579970260
AudioSource: AudioSource:
@ -11720,6 +11721,7 @@ MonoBehaviour:
narrationClipTwo: {fileID: 8300000, guid: deff384217dfb4266aa229b913f8fd03, type: 3} narrationClipTwo: {fileID: 8300000, guid: deff384217dfb4266aa229b913f8fd03, type: 3}
fireObjectToThrow: {fileID: 1155277585} fireObjectToThrow: {fileID: 1155277585}
fireObjectToCollect: {fileID: 282901708} fireObjectToCollect: {fileID: 282901708}
fireInstructionUI: {fileID: 5235938035743833251}
boundControl: {fileID: 979159588} boundControl: {fileID: 979159588}
--- !u!1001 &636743900 --- !u!1001 &636743900
PrefabInstance: PrefabInstance:
@ -16389,10 +16391,6 @@ MonoBehaviour:
earthBoundary: {fileID: 1596973207} earthBoundary: {fileID: 1596973207}
waterBoundary: {fileID: 1726060519} waterBoundary: {fileID: 1726060519}
fireBoundary: {fileID: 634926185} fireBoundary: {fileID: 634926185}
airInstructionUI: {fileID: 770984586}
earthInstructionUI: {fileID: 1752584107}
waterInstructionUI: {fileID: 751470795}
fireInstructionUI: {fileID: 5235938035743833251}
airNotCollectedImage: {fileID: 1048445217} airNotCollectedImage: {fileID: 1048445217}
airCollectedImage: {fileID: 252265085} airCollectedImage: {fileID: 252265085}
earthNotCollectedImage: {fileID: 484134552} earthNotCollectedImage: {fileID: 484134552}
@ -36109,6 +36107,7 @@ MonoBehaviour:
narrationClip: {fileID: 8300000, guid: 94cf8154f1b9943aba707d774a2821c7, type: 3} narrationClip: {fileID: 8300000, guid: 94cf8154f1b9943aba707d774a2821c7, type: 3}
narrationClipTwo: {fileID: 8300000, guid: bf45e15b36fce434c9dbb9ce462fef79, type: 3} narrationClipTwo: {fileID: 8300000, guid: bf45e15b36fce434c9dbb9ce462fef79, type: 3}
earthObjectToCollect: {fileID: 31480962} earthObjectToCollect: {fileID: 31480962}
earthInstructionUI: {fileID: 1752584107}
boundControl: {fileID: 979159588} boundControl: {fileID: 979159588}
--- !u!1001 &1601739639 --- !u!1001 &1601739639
PrefabInstance: PrefabInstance:
@ -38342,9 +38341,10 @@ MonoBehaviour:
dropHasAppeared: 0 dropHasAppeared: 0
narrationHasStarted: 0 narrationHasStarted: 0
audioSource: {fileID: 171465764} audioSource: {fileID: 171465764}
narrationClip: {fileID: 8300000, guid: 08211c0f27d2740228ddd729a21f516f, type: 3} narrationClip: {fileID: 8300000, guid: 323fb72f2a17b47deb655682a5f8e963, type: 3}
narrationClipTwo: {fileID: 8300000, guid: 323fb72f2a17b47deb655682a5f8e963, type: 3} narrationClipTwo: {fileID: 8300000, guid: 86108e3698a924d59860ac92e3cc414a, type: 3}
waterObjectToCollect: {fileID: 297646202} waterObjectToCollect: {fileID: 297646202}
waterInstructionUI: {fileID: 751470795}
boundControl: {fileID: 979159588} boundControl: {fileID: 979159588}
--- !u!1 &1726452294 --- !u!1 &1726452294
GameObject: GameObject:

@ -142,6 +142,8 @@ PlayerSettings:
bundleVersion: 0.1.0 bundleVersion: 0.1.0
preloadedAssets: preloadedAssets:
- {fileID: 11400000, guid: 1224da94f9ef543cfa1a1ba9de68fa6b, type: 2} - {fileID: 11400000, guid: 1224da94f9ef543cfa1a1ba9de68fa6b, type: 2}
- {fileID: 2139348419382495779, guid: a6a4cf5690c084880ae5480fa4d944a3, type: 2}
- {fileID: 11400000, guid: 8cc7f022db65542ebadc5da4081ad2ae, type: 2}
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1