This commit is contained in:
Morgan - 6 Freedom 2024-01-28 02:41:25 +01:00
commit 68a056b3a1
6 changed files with 150 additions and 14 deletions

View File

@ -3385,13 +3385,14 @@ GameObject:
m_Component:
- component: {fileID: 1181392806}
- component: {fileID: 1181392807}
- component: {fileID: 1181392808}
m_Layer: 5
m_Name: TakePictureState
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1181392806
RectTransform:
m_ObjectHideFlags: 0
@ -3434,6 +3435,21 @@ MonoBehaviour:
freezeButton: {fileID: 223773138}
resumeButton: {fileID: 1114535086}
photoBox: {fileID: 1316036600}
--- !u!114 &1181392808
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1181392805}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 02a8e72b27188ad7f8079b04e756e652, type: 3}
m_Name:
m_EditorClassIdentifier:
managers: {fileID: 429358648}
explainText: {fileID: 2139867527}
promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2}
--- !u!1 &1202782726
GameObject:
m_ObjectHideFlags: 0
@ -6279,9 +6295,9 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 429358652}
m_TargetAssemblyTypeName: StorageManager, Assembly-CSharp
m_MethodName: UploadPhoto
- m_Target: {fileID: 1181392808}
m_TargetAssemblyTypeName: QuestionHandler, Assembly-CSharp
m_MethodName: OnSubmitButton
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}

View File

@ -43,7 +43,45 @@ public List<Question> GetQuestionList()
return new List<Question>(questions.Values);
}
public void setPlayersAreReady(int _state)
public List<Question> GetQuestionsByPlayer(Player player)
{
List<Question> questions = new();
foreach (Question question in GetQuestionList())
{
foreach (Proposition proposition in new List<Proposition>(question.propositions.Values))
{
if (proposition.owner.id == player.id)
{
questions.Add(question);
break;
}
}
}
return questions;
}
public List<Proposition> GetPropositionsByPlayer(Player player)
{
List<Proposition> propositions = new();
foreach (Question question in GetQuestionList())
{
foreach (Proposition proposition in new List<Proposition>(question.propositions.Values))
{
if (proposition.owner.id == player.id)
{
propositions.Add(proposition);
break;
}
}
}
return propositions;
}
public void SetPlayersAreReady(int _state)
{
currentState = _state;
}

View File

@ -7,7 +7,6 @@
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters;
/// <summary>
/// This is the game state manager on the phone side
@ -220,12 +219,12 @@ private void JoinRoom(Action callback_OnRoomJoined)
public void StartGame()
{
// send Start Game
myRoom.setPlayersAreReady(1);
myRoom.SetPlayersAreReady(1);
string JSON = JsonUtility.ToJson(myRoom);
Debug.Log(JSON);
try
{
sendCurrentState(GameState.Explanation, () =>
SendCurrentState(GameState.Explanation, () =>
{
Debug.Log($"start the game", this);
myRoom.currentState = (int)GameState.Explanation;
@ -238,8 +237,6 @@ public void StartGame()
{
Debug.LogException(ex);
}
}
/// <summary>
@ -368,7 +365,7 @@ private void CheckIfIAmTheFirst(List<Player> players)
submitStartGame.SetActive(true);
}
}
public void sendCurrentState(GameState state, Action callback_oncCurrentStateSent)
public void SendCurrentState(GameState state, Action callback_oncCurrentStateSent)
{
myOnlineRoom.Child("currentState").SetValueAsync((int)state).ContinueWithOnMainThread(task =>
{

View File

@ -0,0 +1,74 @@
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
public class QuestionHandler : MonoBehaviour
{
public GameObject managers;
private GameManager gameManager;
public TextMeshProUGUI explainText;
public PromptList promptList;
private List<Question> player2questions;
private int currentQuestion = 0;
void OnEnable()
{
player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer);
Redraw(++currentQuestion);
}
void OnDisable()
{
player2questions = null;
}
void Redraw(int currentQuestion)
{
Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion - 1].promptId);
explainText.SetText(prompt.en);
CameraManager cameraManager = gameObject.GetComponent<CameraManager>();
cameraManager.WebcamResume();
}
string GetQuestionRef(string promptId)
{
return gameManager.myRoom.questions.First(x => x.Value.promptId == promptId).Key;
}
string GetPropRef(string questionRef, string playerId)
{
return gameManager.myRoom.questions[questionRef].propositions.First(x => x.Value.owner.id == playerId).Key;
}
public void OnSubmitButton()
{
string questionRef = GetQuestionRef(player2questions[currentQuestion - 1].promptId);
StorageManager storageManager = managers.GetComponent<StorageManager>();
storageManager.UploadPhoto(
gameManager.myRoom.code,
gameManager.currentPlayer.id,
GetQuestionRef(questionRef),
GetPropRef(questionRef, gameManager.currentPlayer.id));
if (currentQuestion < 2) {
Redraw(++currentQuestion);
} else {
gameManager.myRoom.currentState = (int) GameState.PropositionsSent;
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 02a8e72b27188ad7f8079b04e756e652
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -33,7 +33,7 @@ void Update()
}
public void UploadPhoto()
public void UploadPhoto(string roomCode, string playerId, string questionRef, string propRef)
{
Texture2D photo = gameObject.GetComponent<CameraManager>().GetPhoto();
byte[] photoBytes = ImageConversion.EncodeToJPG(photo);