Merge pull request from Mukheem/Fixing_button_click

Fixing button click to stop audio narrations mess
This commit is contained in:
Abdul Mukheem Shaik 2024-05-28 18:33:54 +02:00 committed by GitHub
commit 10bf71623e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 14 deletions
Assets/SharedSpatialAnchors
Prefabs/Resources
Scripts
ProjectSettings

@ -1119,6 +1119,10 @@ PrefabInstance:
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7516989854395125640, guid: d2d6934a666a18d46b8b7a3864dc9f63, type: 3}
propertyPath: m_TagString
value: SB
objectReference: {fileID: 0}
- target: {fileID: 7516989854707263118, guid: d2d6934a666a18d46b8b7a3864dc9f63, type: 3}
propertyPath: m_LocalScale.x
value: 0.89236
@ -1482,6 +1486,10 @@ PrefabInstance:
propertyPath: ObservedComponents.Array.data[1]
value:
objectReference: {fileID: 4890728645620921254}
- target: {fileID: 4293156748659161764, guid: ebcaad662ef2ae14ca92fbcd7a67ee56, type: 3}
propertyPath: m_TagString
value: EB
objectReference: {fileID: 0}
- target: {fileID: 4293156748659161770, guid: ebcaad662ef2ae14ca92fbcd7a67ee56, type: 3}
propertyPath: m_LocalPosition.y
value: -132.3

@ -68,13 +68,22 @@ public class API : MonoBehaviourPunCallbacks, IPunObservable
photonView = PhotonView.Get(this);
photonView.RPC("RPC_EmergencyButtonClick", RpcTarget.All,false,0.0f);
avatar = GameObject.FindGameObjectWithTag("Avatar");
audioControllerScript = avatar.GetComponent<AudioController>();
// Turning on both the buttons on GUI when something is playing
transform.GetChild(1).gameObject.SetActive(false);
transform.GetChild(3).gameObject.SetActive(false);
}
void Update()
{
if (isButtonPressed)
{
webSocketController = GameObject.FindGameObjectWithTag("WebController");
webSocketControllerScript = webSocketController.GetComponent<WebSocketController>();
if (webSocketControllerScript.ws.ReadyState != WebSocketState.Open)
{
webSocketControllerScript.ws.Connect();
@ -83,19 +92,32 @@ public class API : MonoBehaviourPunCallbacks, IPunObservable
photonView.RPC("RPC_VoltageUpdate", RpcTarget.All, webSocketControllerScript.voltageValue.ToString());
}
if (audioControllerScript.audioSource.isActiveAndEnabled && !audioControllerScript.audioSource.isPlaying)
{
// Turning off both the buttons on GUI when something is playing
transform.GetChild(1).gameObject.SetActive(true);
transform.GetChild(3).gameObject.SetActive(true);
}
}
public void OnButtonClick()
{
webSocketController = GameObject.FindGameObjectWithTag("WebController");
webSocketControllerScript = webSocketController.GetComponent<WebSocketController>();
webSocketControllerScript.ConnectWithESP32();
StartCoroutine(GetText());
if (!isButtonPressed)
{
webSocketController = GameObject.FindGameObjectWithTag("WebController");
webSocketControllerScript = webSocketController.GetComponent<WebSocketController>();
webSocketControllerScript.ConnectWithESP32();
StartCoroutine(GetText());
avatar = GameObject.FindGameObjectWithTag("Avatar");
audioControllerScript = avatar.GetComponent<AudioController>();
audioControllerScript.fn_call_AudioNarration2();
Debug.Log("Button is Clicked");
audioControllerScript.fn_call_AudioNarration2();
Debug.Log("Button is Clicked");
transform.GetChild(1).gameObject.SetActive(false);
transform.GetChild(3).gameObject.SetActive(false);
}
}
public void emergencyButtonClick()
{
@ -129,7 +151,7 @@ public class API : MonoBehaviourPunCallbacks, IPunObservable
{
Debug.Log("Received data" + www.downloadHandler.text);
ExtractDataFromJson(www.downloadHandler.text);
isButtonPressed = true; // Boolean to keep voltage updated as long as the turbine is rotating
}
}
@ -187,13 +209,13 @@ public void ExtractDataFromJson(string json)
}
}
photonView = PhotonView.Get(this);
photonView.RPC("RPC_GreenButtonClick", RpcTarget.All,windDirectionInDirectionTerms,LatestT+" C","Kista",latestWS+" m/s",true,latestWD,latestWS);
photonView.RPC("RPC_GreenButtonClick", RpcTarget.All,windDirectionInDirectionTerms,LatestT+" C","Kista",latestWS+" m/s",true,latestWD,latestWS, true);
}
[PunRPC]
public void RPC_GreenButtonClick(String windDirection,String locationTemperature,String location,String windSpeed,bool turn_WT_on_Y_Axis_val,float latestWD_val, float latestWS_val)
public void RPC_GreenButtonClick(String windDirection,String locationTemperature,String location,String windSpeed,bool turn_WT_on_Y_Axis_val,float latestWD_val, float latestWS_val,bool isButtonPressed_val)
{
isButtonPressed = isButtonPressed_val;
latestWD = latestWD_val; // Just for RPC purposes
latestWS = latestWS_val; // Just for RPC purposes
windDirValue.SetText(windDirection);

@ -5,7 +5,7 @@ using Photon.Pun;
public class AudioController : MonoBehaviour
{
AudioSource audioSource;
public AudioSource audioSource;
public AudioClip audioNarration_1;
public AudioClip audioNarration_2;
PhotonView photonView;
@ -55,6 +55,8 @@ public class AudioController : MonoBehaviour
{
yield return new WaitForSeconds(0.0f);
audioSource.PlayOneShot(audioNarration_2);
yield return new WaitForSeconds(audioNarration_2.length+2.0f);
audioSource.gameObject.SetActive(false);
}

@ -10,6 +10,8 @@ TagManager:
- Avatar
- map
- Wind_Turbine_withMap
- EB
- SB
layers:
- Default
- TransparentFX