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

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

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

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

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

@ -8,27 +8,23 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
{
// Websocket Service
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 esp32WebsocketPort = "81"; // Assign your ESP32 WebSocket port, typically "81"
private bool touchDataReceived = false;
private int receivedTouchValue = 0;
public static bool isTouchDetected = false;
int threshhold = 14000;
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()
{
ConnectWithESP32();
}
public void ConnectWithESP32()
@ -55,29 +51,43 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
Debug.Log("Websocket state - " + ws.ReadyState);
}
void Update()
{//Change to Water script
{
if (waterScript.narrationHasFinished && !waterScript.dropHasAppeared)
{
Debug.Log("Asking for touch.");
ws.Send("Need Touch");
if (touchDataReceived)
if (!startedMeasuringTime)
{
if (receivedTouchValue >= threshhold)
{
Debug.Log("Touch threshold exceeded, action triggered.");
isTouchDetected = true;
waterScript.collectTouch();
startedMeasuringTime = true;
narrationEndTime = Time.realtimeSinceStartup;
}
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()
@ -87,5 +97,4 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
ws.Close();
}
}
}

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

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

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