Background Audio added

This commit is contained in:
Nicklas 2024-03-19 13:58:48 +01:00
parent 93cc50524e
commit 35770e2874
8 changed files with 263 additions and 95 deletions

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0dbf49b4b7f7a481a8092b5cba931e30
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 5b0d294ed2dfc4c37a41f98cb9c8951a
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

@ -6,26 +6,21 @@ using WebSocketSharp; // Ensure this matches the WebSocket library you're using
public class ConnectUnityWithSensors : MonoBehaviour
{
// Websocket Service
WebSocket ws;
//public AudioSource audioSource; // Assign in inspector
//public AudioClip narrationClip; // Assign in inspector
//
public string esp32IPAddress = "10.204.0.248"; // Assign your ESP32 IP Address
public string esp32WebsocketPort = "81"; // Assign your ESP32 WebSocket port, typically "81"
public string esp32IPAddress = "10.204.0.248";
public string esp32WebsocketPort = "81";
private bool forceDataReceived = false;
private int receivedForceValue = 0;
public static bool isForceDetected = false;
private Coroutine forceCheckCoroutine = null; // Reference to the coroutine for managing its lifecycle
public BoundEarthScript earthScript = new BoundEarthScript();
void Start()
{
ConnectWithESP32();
}
public void ConnectWithESP32()
@ -41,42 +36,55 @@ public class ConnectUnityWithSensors : MonoBehaviour
{
Debug.Log("Received message: " + e.Data);
int parsedValue;
bool isNumeric = int.TryParse(e.Data, out parsedValue);
if (isNumeric)
if (int.TryParse(e.Data, out parsedValue))
{
receivedForceValue = parsedValue;
forceDataReceived = true; // Indicate that new data has been received
forceDataReceived = true;
if (receivedForceValue > 100 && !isForceDetected)
{
Debug.Log("Force detected immediately, cancelling timeout.");
isForceDetected = true;
earthScript.collectForce();
// Cancel the timeout coroutine if it's running
if (forceCheckCoroutine != null)
{
StopCoroutine(forceCheckCoroutine);
forceCheckCoroutine = null;
}
}
}
};
ws.Connect();
Debug.Log("Websocket state - " + ws.ReadyState);
}
void Update()
{
if (earthScript.narrationHasFinished && !earthScript.seedHasAppeared)
if (earthScript.narrationHasFinished && !earthScript.seedHasAppeared && !isForceDetected)
{
Debug.Log("Asking for force.");
Debug.Log("Checking for force...");
ws.Send("Need Force");
if (forceDataReceived)
// Start the timeout coroutine only if it hasn't been started yet
if (forceCheckCoroutine == null)
{
if (receivedForceValue > 100)
{
Debug.Log("Force threshold exceeded, action triggered.");
isForceDetected = true;
earthScript.collectForce();
}
forceDataReceived = false; // Reset for the next message
forceCheckCoroutine = StartCoroutine(IfForceUnavailable());
}
}
}
IEnumerator IfForceUnavailable()
{
yield return new WaitForSeconds(30); // Wait for 30 seconds
// Trigger the action if no force has been detected by this time
if (!isForceDetected)
{
Debug.Log("No force detected within 30 seconds, action triggered.");
isForceDetected = true;
earthScript.collectForce();
}
}
void OnDestroy()
@ -86,5 +94,4 @@ public class ConnectUnityWithSensors : MonoBehaviour
ws.Close();
}
}
}
}

@ -10,6 +10,8 @@ public class GameManagerScript : MonoBehaviour
public VideoPlayer videoPlayerObject;
public GameObject videoPicture;
public GameObject videoPictureReplace;
public GameObject introCanvas;
public GameObject airBoundary;
@ -26,14 +28,14 @@ public class GameManagerScript : MonoBehaviour
Debug.Log("Hello World Hello World");
videoPlayerObject.Prepare();
}
// Update is called once per frame
void Update()
{
}
public void OnTriggerEnter(Collider other)
@ -43,7 +45,7 @@ public class GameManagerScript : MonoBehaviour
introHasBeenEntered = true;
//Play introduction
StartCoroutine(IntroductionNarration());
}
}
@ -52,6 +54,8 @@ public class GameManagerScript : MonoBehaviour
{
//audioSource.PlayOneShot(introductionClip);
videoPlayerObject.Play();
videoPictureReplace.SetActive(true);
videoPicture.SetActive(false);
yield return new WaitForSeconds(introductionClip.length);
ActivateBoundries();
}
@ -67,4 +71,4 @@ public class GameManagerScript : MonoBehaviour
}
}
}

@ -6,29 +6,23 @@ using WebSocketSharp; // Ensure this matches the WebSocket library you're using
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"
public string esp32IPAddress = "10.204.0.249";
public string esp32WebsocketPort = "81";
private bool touchDataReceived = false;
private int receivedTouchValue = 0;
public static bool isTouchDetected = false;
int threshhold = 14000;
int threshold = 14000;
private Coroutine touchCheckCoroutine = null; // Reference to the coroutine
public BoundWaterScript waterScript = new BoundWaterScript();
void Start()
{
ConnectWithESP32();
}
public void ConnectWithESP32()
@ -44,46 +38,55 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
{
Debug.Log("Received message: " + e.Data);
int parsedValue;
bool isNumeric = int.TryParse(e.Data, out parsedValue);
if (isNumeric)
if (int.TryParse(e.Data, out parsedValue))
{
receivedTouchValue = parsedValue;
touchDataReceived = true; // Indicate that new data has been received
touchDataReceived = true;
if (receivedTouchValue >= threshold && !isTouchDetected)
{
Debug.Log("Touch detected, cancelling timeout.");
isTouchDetected = true;
waterScript.collectTouch();
// Cancel the timeout coroutine if it's running
if (touchCheckCoroutine != null)
{
StopCoroutine(touchCheckCoroutine);
touchCheckCoroutine = null;
}
}
}
};
ws.Connect();
Debug.Log("Websocket state - " + ws.ReadyState);
}
void Update()
{//Change to Water script
if (waterScript.narrationHasFinished && !waterScript.dropHasAppeared)
{
if (waterScript.narrationHasFinished && !waterScript.dropHasAppeared && !isTouchDetected)
{
Debug.Log("Asking for touch.");
Debug.Log("Checking for touch...");
ws.Send("Need Touch");
if (touchDataReceived)
// Start the timeout coroutine only if it hasn't been started yet
if (touchCheckCoroutine == null)
{
if (receivedTouchValue >= threshhold)
{
Debug.Log("Touch threshold exceeded, action triggered.");
isTouchDetected = true;
waterScript.collectTouch();
}
touchDataReceived = false; // Reset for the next message
touchCheckCoroutine = StartCoroutine(IfTouchUnavailable());
}
}
}
//Failsafe in case something goes wrong (Get key down to make it so if the sensor
//doesnt work or is giving issues we can control it somehow (but how if we use apk lol????)
IEnumerator IfTouchUnavailable()
{
yield return new WaitForSeconds(30); // Wait for 30 seconds
// Trigger the action if no touch has been detected by this time
if (!isTouchDetected)
{
Debug.Log("No touch detected within 30 seconds, action triggered.");
isTouchDetected = true;
waterScript.collectTouch();
}
}
void OnDestroy()
@ -93,6 +96,4 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
ws.Close();
}
}
}

@ -117,7 +117,7 @@ Material:
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.3818698, g: 0.5, b: 0.2555, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 0.38186976, g: 0.5, b: 0.25549996, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []

@ -3074,6 +3074,8 @@ MonoBehaviour:
audioSource: {fileID: 0}
introductionClip: {fileID: 0}
videoPlayerObject: {fileID: 0}
videoPicture: {fileID: 0}
videoPictureReplace: {fileID: 0}
introCanvas: {fileID: 0}
airBoundary: {fileID: 0}
earthBoundary: {fileID: 0}
@ -8981,7 +8983,7 @@ Transform:
m_GameObject: {fileID: 515544897}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -2.415, y: 0.05, z: 3.77}
m_LocalPosition: {x: -2.39, y: 0.05, z: 3.77}
m_LocalScale: {x: 0.3, y: 1, z: 0.1}
m_ConstrainProportionsScale: 0
m_Children:
@ -14786,6 +14788,99 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 927170614}
m_PrefabAsset: {fileID: 0}
--- !u!1 &939494915
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 939494916}
- component: {fileID: 939494919}
- component: {fileID: 939494918}
- component: {fileID: 939494917}
m_Layer: 5
m_Name: Image (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &939494916
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 939494915}
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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1770249137}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 184, y: -307.5}
m_SizeDelta: {x: 368, y: 205}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &939494917
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 939494915}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: -1
m_PreferredWidth: -1
m_PreferredHeight: 205
m_FlexibleWidth: -1
m_FlexibleHeight: 0
m_LayoutPriority: 1
--- !u!114 &939494918
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 939494915}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 8400000, guid: 111856c8bcade9a44a279d27230f0203, type: 2}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!222 &939494919
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 939494915}
m_CullTransparentMesh: 1
--- !u!1001 &941538618
PrefabInstance:
m_ObjectHideFlags: 0
@ -20860,6 +20955,8 @@ MonoBehaviour:
audioSource: {fileID: 171465764}
introductionClip: {fileID: 8300000, guid: f7315d147971644c0b44069739a92e7b, type: 3}
videoPlayerObject: {fileID: 1770249135}
videoPicture: {fileID: 1770249138}
videoPictureReplace: {fileID: 939494915}
introCanvas: {fileID: 1770249136}
airBoundary: {fileID: 579970255}
earthBoundary: {fileID: 1596973207}
@ -35542,13 +35639,19 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6803299175986173597, guid: 327cf65127c86414a83ad3b0a2bc55b0,
type: 3}
propertyPath: m_LocalPosition.x
value: 7.38
objectReference: {fileID: 0}
- target: {fileID: 8280929046561396919, guid: 327cf65127c86414a83ad3b0a2bc55b0,
type: 3}
propertyPath: m_Name
value: PillarWall (6)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_RemovedGameObjects:
- {fileID: 5184265386037683545, guid: 327cf65127c86414a83ad3b0a2bc55b0, type: 3}
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 327cf65127c86414a83ad3b0a2bc55b0, type: 3}
@ -36372,7 +36475,7 @@ Transform:
m_GameObject: {fileID: 1633672324}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: -0.63, z: 0}
m_LocalPosition: {x: -0, y: -0.63, z: 1.05}
m_LocalScale: {x: 0.1, y: 1, z: 0.4}
m_ConstrainProportionsScale: 0
m_Children: []
@ -36420,7 +36523,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
- {fileID: 2100000, guid: 610d8eab62248e145a08551da327c921, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@ -38983,17 +39086,17 @@ PrefabInstance:
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_LocalScale.x
value: 0.011
value: 0.014000001
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_LocalScale.y
value: 0.004
value: 0.0050909095
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_LocalScale.z
value: 0.007
value: 0.008909092
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
@ -39008,17 +39111,17 @@ PrefabInstance:
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_LocalPosition.z
value: 5.1
value: 8.1
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
value: 0.9914449
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
value: -0.13052624
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
@ -39038,12 +39141,12 @@ PrefabInstance:
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 1.29
value: 1.68
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
value: -15
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
@ -39058,7 +39161,7 @@ PrefabInstance:
- target: {fileID: 2381686859592504020, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
propertyPath: m_ConstrainProportionsScale
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2381686859592504023, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
@ -39304,7 +39407,11 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects:
- {fileID: 2381686860641061470, guid: 95e4f970cffc348e1937878ecd30a6eb, type: 3}
m_AddedGameObjects: []
m_AddedGameObjects:
- targetCorrespondingSourceObject: {fileID: 2381686861650712202, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
insertIndex: -1
addedObject: {fileID: 939494916}
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 95e4f970cffc348e1937878ecd30a6eb, type: 3}
--- !u!328 &1770249135 stripped
@ -39319,6 +39426,18 @@ GameObject:
type: 3}
m_PrefabInstance: {fileID: 1770249134}
m_PrefabAsset: {fileID: 0}
--- !u!224 &1770249137 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 2381686861650712202, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
m_PrefabInstance: {fileID: 1770249134}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1770249138 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2381686860521046453, guid: 95e4f970cffc348e1937878ecd30a6eb,
type: 3}
m_PrefabInstance: {fileID: 1770249134}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1779903091
PrefabInstance:
m_ObjectHideFlags: 0
@ -44804,13 +44923,19 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6803299175986173597, guid: 327cf65127c86414a83ad3b0a2bc55b0,
type: 3}
propertyPath: m_LocalPosition.z
value: -6.8
objectReference: {fileID: 0}
- target: {fileID: 8280929046561396919, guid: 327cf65127c86414a83ad3b0a2bc55b0,
type: 3}
propertyPath: m_Name
value: PillarWall (3)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_RemovedGameObjects:
- {fileID: 5184265386037683545, guid: 327cf65127c86414a83ad3b0a2bc55b0, type: 3}
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 327cf65127c86414a83ad3b0a2bc55b0, type: 3}
@ -44992,7 +45117,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
- {fileID: 2100000, guid: 610d8eab62248e145a08551da327c921, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@ -46811,7 +46936,7 @@ AudioSource:
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 5b0d294ed2dfc4c37a41f98cb9c8951a, type: 3}
m_PlayOnAwake: 1
m_Volume: 0.2
m_Pitch: 1
@ -49448,22 +49573,22 @@ PrefabInstance:
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
propertyPath: m_LocalPosition.z
value: -7.270001
value: -7.52
objectReference: {fileID: 0}
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
propertyPath: m_LocalRotation.w
value: -0.49999997
value: -0.42261827
objectReference: {fileID: 0}
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
propertyPath: m_LocalRotation.y
value: 0.86602545
value: 0.9063079
objectReference: {fileID: 0}
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
@ -49473,7 +49598,7 @@ PrefabInstance:
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -1.7000022
value: -1.4
objectReference: {fileID: 0}
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
@ -49488,7 +49613,7 @@ PrefabInstance:
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 150
value: 230
objectReference: {fileID: 0}
- target: {fileID: 4503316873746296701, guid: ee63e9e4a907044968ed60ecbfaf78d6,
type: 3}