Skip to content
Snippets Groups Projects
Commit 392eb324 authored by DA MAIA Hugo's avatar DA MAIA Hugo
Browse files

try to modified the async finction (not working) and turn it to a coroutine but still doesn't work

parent 6314fdeb
No related branches found
No related tags found
No related merge requests found
using System;
using System.Threading.Tasks;
using System.Collections;
using Lib.Scripts.Data;
using Lib.Scripts.Network;
using UnityEngine;
......@@ -19,7 +19,18 @@ namespace Lib.Scripts
private Experiment _expData;
private int _iterationIndex;
#region Singleton declaration
public static GameManager Instance;
private void Awake()
{
if(Instance != null && Instance != this) Destroy(gameObject);
Instance = this;
}
#endregion
private void Start()
{
......@@ -59,7 +70,7 @@ namespace Lib.Scripts
OnIterationBegin();
break;
case GameState.WaitForData:
HandleWaitForData(Time.time);
HandleWaitForData();
break;
case GameState.EndOfExperiment:
break;
......@@ -100,21 +111,24 @@ namespace Lib.Scripts
_iterationIndex = 0; //Set the first iteration
}
private async void OnIterationBegin()
private void OnIterationBegin() => StartCoroutine(IterationBeginCoroutine());
private IEnumerator IterationBeginCoroutine()
{
Debug.Log("A new iteration begin");
var iteration = _expData.Iterations[_iterationIndex];
//Place both balls and set their colors.
_main.PlaceBalls(iteration.Ball1, iteration.Ball2, iteration.Ball1Color, iteration.Ball2Color);
_main.SetEnhancement(iteration.Augmentation);
//start exposition time
await Task.Delay(expositionTime);
yield return new WaitForSeconds(expositionTime);
ChangeState(GameState.WaitForData);
}
private float _answeringTime;
private void HandleWaitForData(float time)
private void HandleWaitForData()
{
_answeringTime = time;
Debug.Log("Exposition is over. Waiting for tablet data.");
//Tell the tablet to start interaction
_network.Send("interact! Exposition time is over, it is time to interact.");
//Hide the balls
_main.HideBalls();
//This state is ended when we received the _network.OnUserEndIteration event.
......
......@@ -20,11 +20,11 @@ namespace Lib.Scripts.Network
#endregion
public Client(string hostname, int port = 8052)
public Client(NetworkManager network, string hostname, int port = 8052)
{
_hostname = hostname;
_port = port;
_network = NetworkManager.Singleton;
_network = network;
ConnectToTcpServer();
}
......@@ -66,8 +66,8 @@ namespace Lib.Scripts.Network
Array.Copy(bytes, 0, incomingData, 0, length);
// Convert byte array to string message.
var serverMessage = Encoding.ASCII.GetString(incomingData);
Debug.Log("server message received as: " + serverMessage);
//_network.DealMessage(serverMessage); //Tell the network manager to deal with the message data
//Debug.Log("server message received as: " + serverMessage);
_network.DealMessage(serverMessage); //Tell the network manager to deal with the message data
}
}
}
......
......@@ -14,6 +14,7 @@ namespace Lib.Scripts.Network
//private IterationManager _iterationManager;
private Client _networkClient;
private GameManager _gameManager;
#endregion
......@@ -33,8 +34,8 @@ namespace Lib.Scripts.Network
private void Start()
{
_networkClient = new Client(hostname,port); //Declare the client that will deal directly with the network part
_networkClient = new Client(this, hostname,port); //Declare the client that will deal directly with the network part
_gameManager = GameManager.Instance;
}
#region Events
......@@ -52,6 +53,7 @@ namespace Lib.Scripts.Network
public void DealMessage(string msg)
{
var sections = msg.Split('!');
Debug.Log($"section0 : {sections[0]} and Message from server is {msg}");
switch (sections[0])
{
case "start":
......@@ -60,6 +62,9 @@ namespace Lib.Scripts.Network
case "endIt":
OnUserEndIteration?.Invoke();
break;
case "over":
_gameManager.ChangeState(GameState.EndOfExperiment);
break;
default:
throw new Exception($"Unknow type {sections[0]} for a message !");
}
......
......@@ -432,7 +432,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!4 &421975797
Transform:
m_ObjectHideFlags: 0
......@@ -631,36 +631,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!21 &1295011977
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 'oieMaterial
41368'
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 5
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 7ff338d983cb4576bf50e6b34aebd44c, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors:
- _Color: {r: 0.82089555, g: 0.82089555, b: 0.82089555, a: 1}
m_BuildTextureStacks: []
--- !u!1 &1327202257
GameObject:
m_ObjectHideFlags: 0
......@@ -710,7 +680,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 1842914478}
- {fileID: 1511373777}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
......@@ -865,6 +835,36 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!21 &1511373777
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 'vergerMaterial
45924'
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 5
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 5ec880c6d71649eea7b3eed515aaf3ea, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors:
- _Color: {r: 0.82089555, g: 0.82089555, b: 0.82089555, a: 1}
m_BuildTextureStacks: []
--- !u!1001 &1529282074
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -1096,7 +1096,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 1295011977}
- {fileID: 2062830574}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
......@@ -1416,36 +1416,6 @@ Mesh:
offset: 0
size: 0
path:
--- !u!21 &1842914478
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 'vergerMaterial
41340'
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 5
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 5ec880c6d71649eea7b3eed515aaf3ea, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors:
- _Color: {r: 0.82089555, g: 0.82089555, b: 0.82089555, a: 1}
m_BuildTextureStacks: []
--- !u!1 &1919177133
GameObject:
m_ObjectHideFlags: 0
......@@ -1462,7 +1432,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!114 &1919177134
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -1685,3 +1655,33 @@ Mesh:
offset: 0
size: 0
path:
--- !u!21 &2062830574
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 'oieMaterial
45966'
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 5
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 7ff338d983cb4576bf50e6b34aebd44c, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors:
- _Color: {r: 0.82089555, g: 0.82089555, b: 0.82089555, a: 1}
m_BuildTextureStacks: []
......@@ -13,3 +13,4 @@ Qr 1 Founds.
Target status: oie NO_POSE -- NOT_OBSERVED
Target status: verger NO_POSE -- NOT_OBSERVED
Vuforia Stopped
Vuforia Deinitialized
......@@ -242,8 +242,6 @@ PlayerSettings:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 5483873183897974787, guid: 03e9d0b0ea5b74945a30d89c8163bc43, type: 2}
- {fileID: 5446824126193539027, guid: 9790d1b2279b01247ad6b75a79b3b361, type: 2}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment