This commit is contained in:
Otaku9999 2024-01-27 17:14:06 +01:00
commit c9923f789a
7 changed files with 652 additions and 50 deletions

View File

@ -642,7 +642,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: efbbc7abb0db8c7e0b29ec4bb986d783, type: 3} m_Script: {fileID: 11500000, guid: efbbc7abb0db8c7e0b29ec4bb986d783, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
webCamTexture: {fileID: 0} texture: {fileID: 0}
freezeButton: {fileID: 1776746473} freezeButton: {fileID: 1776746473}
resumeButton: {fileID: 1872873213} resumeButton: {fileID: 1872873213}
--- !u!114 &1128585037 --- !u!114 &1128585037

View File

@ -1049,7 +1049,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &638947074 --- !u!224 &638947074
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1113,7 +1113,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 638947076} m_TargetGraphic: {fileID: 638947076}
m_OnClick: m_OnClick:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls:
- m_Target: {fileID: 1202782732}
m_TargetAssemblyTypeName: GameManager, Assembly-CSharp
m_MethodName: StartGame
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &638947076 --- !u!114 &638947076
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2105,6 +2117,140 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &991600091
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 991600092}
- component: {fileID: 991600094}
- component: {fileID: 991600093}
m_Layer: 5
m_Name: ErrorCodeLabel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &991600092
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 991600091}
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: 2023851069}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 2.9758, y: 20.4609}
m_SizeDelta: {x: 154.05, y: 13.5401}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &991600093
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 991600091}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, 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_text: 'Error: the room code is invalide'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_sharedMaterial: {fileID: 8890805173838430465, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4278190335
m_fontColor: {r: 1, g: 0, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 11.43
m_fontSizeBase: 11.43
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 256
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: -0.000000025251643, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &991600094
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 991600091}
m_CullTransparentMesh: 1
--- !u!1 &1034781733 --- !u!1 &1034781733
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2596,7 +2742,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 1158329300} m_TargetGraphic: {fileID: 1158329300}
m_OnClick: m_OnClick:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls:
- m_Target: {fileID: 1202782732}
m_TargetAssemblyTypeName: GameManager, Assembly-CSharp
m_MethodName: PlayerValidateNameAndServerRoom
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1158329300 --- !u!114 &1158329300
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2668,6 +2826,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1288753599} - {fileID: 1288753599}
- {fileID: 1770783105} - {fileID: 1770783105}
- {fileID: 1224049645}
m_Father: {fileID: 2027556832} m_Father: {fileID: 2027556832}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
@ -2958,7 +3117,7 @@ GameObject:
- component: {fileID: 1202782729} - component: {fileID: 1202782729}
- component: {fileID: 1202782728} - component: {fileID: 1202782728}
- component: {fileID: 1202782727} - component: {fileID: 1202782727}
- component: {fileID: 1202782731} - component: {fileID: 1202782732}
m_Layer: 5 m_Layer: 5
m_Name: Canvas m_Name: Canvas
m_TagString: Untagged m_TagString: Untagged
@ -3049,7 +3208,7 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0} m_Pivot: {x: 0, y: 0}
--- !u!114 &1202782731 --- !u!114 &1202782732
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@ -3058,9 +3217,160 @@ MonoBehaviour:
m_GameObject: {fileID: 1202782726} m_GameObject: {fileID: 1202782726}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 77ca3ece4774c244e96dcee6ab926fbb, type: 3} m_Script: {fileID: 11500000, guid: 27a435387a7644784a6fc6ae538b68e5, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
isRoomExist: 1
isPlayerExist: 1
explanationTime: 4
roomCodeField: {fileID: 2023851070}
roomError: {fileID: 991600093}
playerNameField: {fileID: 1163479463}
nameError: {fileID: 1224049646}
submitNewPlayer: {fileID: 1158329299}
listPlayersUI: {fileID: 1891690322}
submitStartGame: {fileID: 638947073}
HomeConnection: {fileID: 2027556831}
WaitingRoom: {fileID: 1590939977}
BeforeStart: {fileID: 563000513}
TakePicture: {fileID: 1181392805}
VotePicture: {fileID: 531335861}
WaitingOtherPlayers: {fileID: 2095389711}
EndGame: {fileID: 1850164816}
--- !u!1 &1224049644
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1224049645}
- component: {fileID: 1224049647}
- component: {fileID: 1224049646}
m_Layer: 5
m_Name: ErrorNameLabel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1224049645
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1224049644}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1.0029413, y: 1.0029413, z: 0.8627451}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1163479462}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 2.9845557, y: 18.5}
m_SizeDelta: {x: 154.05, y: 13.5401}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1224049646
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1224049644}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, 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_text: 'Error: only numbers and letters'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_sharedMaterial: {fileID: 8890805173838430465, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4278190335
m_fontColor: {r: 1, g: 0, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 11.43
m_fontSizeBase: 11.43
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 256
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: -0.000000025251643, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1224049647
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1224049644}
m_CullTransparentMesh: 1
--- !u!1 &1266773203 --- !u!1 &1266773203
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4703,8 +5013,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -38.8} m_AnchoredPosition: {x: 2.8591, y: -36.5711}
m_SizeDelta: {x: 200, y: 50} m_SizeDelta: {x: 194.2818, y: 45.5423}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1770783106 --- !u!114 &1770783106
MonoBehaviour: MonoBehaviour:
@ -5610,6 +5920,7 @@ RectTransform:
m_ConstrainProportionsScale: 1 m_ConstrainProportionsScale: 1
m_Children: m_Children:
- {fileID: 2008743696} - {fileID: 2008743696}
- {fileID: 991600092}
m_Father: {fileID: 2027556832} m_Father: {fileID: 2027556832}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
@ -5768,7 +6079,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &2027556832 --- !u!224 &2027556832
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,69 +1,107 @@
using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class CameraManager : MonoBehaviour public class CameraManager : MonoBehaviour
{ {
public WebCamTexture webCamTexture; public WebCamTexture wTexture;
public WebCamDevice wDevice;
public Button freezeButton; public Button freezeButton;
public Button resumeButton; public Button resumeButton;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
webCamTexture = new WebCamTexture(); wDevice = WebCamTexture.devices.First(x => x.isFrontFacing == false);
//gameObject.transform.rotation = transform.rotation * Quaternion.AngleAxis(webCamTexture.videoRotationAngle, Vector3.up); wTexture = new WebCamTexture(wDevice.name);
WebcamResume(); WebcamResume();
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
var x = 0; Texture2D cropped = CropTexture(wTexture);
var y = 0; Texture2D rotated = RotateTexture(cropped, !wDevice.isFrontFacing);
var size = webCamTexture.height;
if (webCamTexture.height > webCamTexture.width) gameObject.GetComponent<RawImage>().texture = rotated;
{ gameObject.GetComponent<RawImage>().material.mainTexture = rotated;
size = webCamTexture.width;
y = (webCamTexture.height - webCamTexture.width) / 2;
}
else if (webCamTexture.height < webCamTexture.width)
{
size = webCamTexture.height;
x = (webCamTexture.width - webCamTexture.height) / 2;
}
Texture2D cropped = new(size, size);
cropped.SetPixels(webCamTexture.GetPixels(x, y, size, size));
cropped.Apply();
gameObject.GetComponent<RawImage>().texture = cropped;
gameObject.GetComponent<RawImage>().material.mainTexture = cropped;
} }
public void WebcamResume() public void WebcamResume()
{ {
webCamTexture.Play(); wTexture.Play();
freezeButton.gameObject.SetActive(true); freezeButton.gameObject.SetActive(true);
resumeButton.gameObject.SetActive(false); resumeButton.gameObject.SetActive(false);
} }
public void WebcamChange() public void WebcamChange()
{ {
foreach (WebCamDevice webCamDevice in WebCamTexture.devices) foreach (WebCamDevice loopDevice in WebCamTexture.devices)
{ {
if (webCamTexture.deviceName != webCamDevice.name) if ((wDevice.isFrontFacing && !loopDevice.isFrontFacing) || (!wDevice.isFrontFacing && loopDevice.isFrontFacing))
{ {
webCamTexture = new WebCamTexture(webCamDevice.name); wDevice = loopDevice;
wTexture = new WebCamTexture(wDevice.name);
WebcamResume(); WebcamResume();
break;
} }
} }
} }
public void WebcamStop() public void WebcamStop()
{ {
webCamTexture.Stop(); wTexture.Stop();
freezeButton.gameObject.SetActive(false); freezeButton.gameObject.SetActive(false);
resumeButton.gameObject.SetActive(true); resumeButton.gameObject.SetActive(true);
} }
Texture2D RotateTexture(Texture2D originalTexture, bool clockwise)
{
Color32[] original = originalTexture.GetPixels32();
Color32[] rotated = new Color32[original.Length];
int w = originalTexture.width;
int h = originalTexture.height;
int iRotated, iOriginal;
for (int j = 0; j < h; ++j)
{
for (int i = 0; i < w; ++i)
{
iRotated = (i + 1) * h - j - 1;
iOriginal = clockwise ? original.Length - 1 - (j * w + i) : j * w + i;
rotated[iRotated] = original[iOriginal];
}
}
Texture2D rotatedTexture = new(h, w);
rotatedTexture.SetPixels32(rotated);
rotatedTexture.Apply();
return rotatedTexture;
}
Texture2D CropTexture(WebCamTexture originalTexture)
{
var x = 0;
var y = 0;
var size = originalTexture.height;
if (originalTexture.height > originalTexture.width)
{
size = originalTexture.width;
y = (originalTexture.height - originalTexture.width) / 2;
}
else if (originalTexture.height < originalTexture.width)
{
size = originalTexture.height;
x = (originalTexture.width - originalTexture.height) / 2;
}
Texture2D croppedTexture = new(size, size);
croppedTexture.SetPixels(originalTexture.GetPixels(x, y, size, size));
croppedTexture.Apply();
return croppedTexture;
}
} }

View File

@ -1,8 +1,12 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Firebase.Database;
using Firebase.Extensions;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.UIElements;
/// <summary> /// <summary>
/// This is the game state manager on the phone side /// This is the game state manager on the phone side
@ -12,17 +16,58 @@ public class GameManager : MonoBehaviour
private GameState currentState; private GameState currentState;
private List<Player> players = new List<Player>(); private List<Player> players = new List<Player>();
[Header("Temp variables")]
public bool isRoomExist = true;
public bool isPlayerExist = true;
[Header("Other component")]
public float explanationTime = 4f; public float explanationTime = 4f;
private float currentExplanationTime = 0; private float currentExplanationTime = 0;
public InputField roomCodeField; [Header("Home Component")]
public TMP_InputField roomCodeField;
public TextMeshProUGUI roomError; public TextMeshProUGUI roomError;
public InputField playerNameField; public TMP_InputField playerNameField;
public TextMeshProUGUI nameError; public TextMeshProUGUI nameError;
public UnityEngine.UI.Button submitNewPlayer;
[Header("WaitingRoom Component")]
public TextMeshProUGUI listPlayersUI;
public GameObject submitStartGame;
[Header("Pages")]
[SerializeField]
public GameObject HomeConnection;
[SerializeField]
public GameObject WaitingRoom;
[SerializeField]
public GameObject BeforeStart;
[SerializeField]
public GameObject TakePicture;
[SerializeField]
public GameObject VotePicture;
[SerializeField]
public GameObject WaitingOtherPlayers;
[SerializeField]
public GameObject EndGame;
private DatabaseReference realtimeDB;
private Room myRoom;
private void Awake()
{
FirebaseInitializer.Instance.onFirebaseReady += Initialize;
}
private void Start() private void Start()
{ {
currentExplanationTime = explanationTime; currentExplanationTime = explanationTime;
HomeConnection.SetActive(true);
} }
public GameState GetCurrentState() public GameState GetCurrentState()
@ -30,17 +75,100 @@ public GameState GetCurrentState()
return currentState; return currentState;
} }
private void Initialize()
{
FirebaseInitializer.Instance.onFirebaseReady -= Initialize;
realtimeDB = FirebaseDatabase.DefaultInstance.RootReference;
Debug.Log("Realtime DB initialized");
//TODO MARINE : enable the submit button here. Disabled it at start
}
/// <summary> /// <summary>
/// Send your name and game room to the server /// Send your name and game room to the server
/// </summary> /// </summary>
public void PlayerValidateNameAndServerRoom() public void PlayerValidateNameAndServerRoom(string _name, string _code)
{ {
//check if the room exists, if not display an error message //check if the room exists, if not display an error message
realtimeDB.Child("rooms").Child(_code).GetValueAsync().ContinueWithOnMainThread(task =>
{
if (task.IsFaulted)
{
Debug.LogException(task.Exception);
}
else if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
if (snapshot == null)
{
Debug.LogError("The room doesn't exists");
roomError.text = "Error: the room doesn't exists";
roomError.gameObject.SetActive(true);
}
else
{
myRoom = JsonUtility.FromJson<Room>(snapshot.GetRawJsonValue());
realtimeDB.Child("rooms").Child(_code).ChildChanged += OnRoomUpdate;
}
}
});
string playerName = playerNameField.text;
string roomCode = roomCodeField.text;
// send to the server the room code and the player name
// MORGANE ENVOIE AU SERV
// answer isPlayerExist and isRoomExist
//if succeed, then the player to the server //if succeed, then the player to the server
if (isPlayerExist && isRoomExist)
{
currentState = GameState.WaitingForOtherPlayersToJoin;
WaitingRoom.SetActive(true);
HomeConnection.SetActive(false);
//TEMP
Player player = new Player();
player.SetName(playerName);
player.id = "1";
players.Add(player);
if (players.Count == 1)
{
submitStartGame.SetActive(true);
}
Player player2 = new Player();
player2.SetName("3J");
player2.id = "2";
Player player3 = new Player();
player3.SetName("3J");
player3.id = "3";
Player player4 = new Player();
player4.SetName("3J");
player4.id = "4";
Player player5 = new Player();
player5.SetName("3J");
player5.id = "5";
Player player6 = new Player();
player6.SetName("3J");
player6.id = "6";
players.Add(player2);
players.Add(player3);
players.Add(player4);
players.Add(player5);
players.Add(player6);
UpdateDisplayedListUser();
}
// else we show the errors
roomError.gameObject.SetActive(!isRoomExist);
nameError.gameObject.SetActive(!isPlayerExist);
//if succeed, change the state and change page
currentState = GameState.WaitingForOtherPlayersToJoin;
} }
/// <summary> /// <summary>
@ -48,6 +176,12 @@ public void PlayerValidateNameAndServerRoom()
/// </summary> /// </summary>
public void StartGame() public void StartGame()
{ {
// send Start Game
currentState = GameState.Explanation;
WaitingRoom.SetActive(false);
BeforeStart.SetActive(true);
} }
@ -58,6 +192,8 @@ public void StartGame()
/// <param name="_prompt">The prompt to display</param> /// <param name="_prompt">The prompt to display</param>
public void MakeAProposition(Prompt _prompt) public void MakeAProposition(Prompt _prompt)
{ {
currentState = GameState.MakeProposition;
} }
@ -99,9 +235,28 @@ public void DisplayEndScreen()
/// <summary> /// <summary>
/// Automatically called when something change in your room /// Automatically called when something change in your room
/// </summary> /// </summary>
private void OnRoomUpdate() private void OnRoomUpdate(object sender, ChildChangedEventArgs e)
{ {
myRoom = JsonUtility.FromJson<Room>(e.Snapshot.GetRawJsonValue());
switch (currentState)
{
case GameState.WaitingForOtherPlayersToJoin:
{
// players = new list en fonction de ce qu'envoie fangh
UpdateDisplayedListUser();
break;
}
}
}
private void UpdateDisplayedListUser()
{
listPlayersUI.text = string.Empty;
for (int i = 0; i < players.Count; i++)
{
listPlayersUI.text += "\n" + players[i].name;
}
} }
} }

View File

@ -1,13 +1,31 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
public class PhoneLoop : MonoBehaviour public class PhoneLoop : MonoBehaviour
{ {
[SerializeField]
public GameObject homeConnection;
[SerializeField]
public GameObject WaitingRoom;
[SerializeField]
public GameObject BeforeStart;
[SerializeField]
public GameObject TakePicture;
[SerializeField]
public GameObject VotePicture;
[SerializeField]
public GameObject WaitingOtherPlayers;
[SerializeField]
public GameObject EndGame;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
homeConnection.SetActive(true);
} }
// Update is called once per frame // Update is called once per frame
@ -15,4 +33,69 @@ void Update()
{ {
} }
void ShowWaititngRoom()
{
homeConnection.SetActive(false);
WaitingRoom.SetActive(true);
}
void ShowBeforeStart()
{
WaitingRoom.SetActive(false);
BeforeStart.SetActive(true);
}
void ShowTakePicture()
{
BeforeStart.SetActive(false);
TakePicture.SetActive(true);
}
void showWaitingOtherPlayers()
{
if (TakePicture.activeInHierarchy)
{
TakePicture.SetActive(false);
}
if (VotePicture.activeInHierarchy)
{
VotePicture.SetActive(false);
}
WaitingOtherPlayers.SetActive(true);
}
void ShowVotePicture()
{
if (TakePicture.activeInHierarchy)
{
TakePicture.SetActive(false);
}
if (WaitingOtherPlayers.activeInHierarchy)
{
WaitingOtherPlayers.SetActive(false);
}
VotePicture.SetActive(true);
}
void ShowEndGame()
{
WaitingOtherPlayers.SetActive(false) ;
EndGame.SetActive(true);
}
[ContextMenu("Fake Player Connection")]
private void FakePlayerConnection()
{
}
} }

View File

@ -46,7 +46,6 @@ private void Awake()
private void Start() private void Start()
{ {
propositionCurrentTime = propositionTime; propositionCurrentTime = propositionTime;
votingCurrentTime = votingTime; votingCurrentTime = votingTime;
} }
@ -106,6 +105,7 @@ public void CreateNewRoom()
realtimeDB.Child("rooms").Child(newRoom.code).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task => realtimeDB.Child("rooms").Child(newRoom.code).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task =>
{ {
Debug.Log($"room {currentRoom.code} has been created on the server"); Debug.Log($"room {currentRoom.code} has been created on the server");
realtimeDB.Child("rooms").Child(newRoom.code).Child("players").ChildAdded += PlayerConnect;
//TODO MARINE : uncomment and reference the correct game object //TODO MARINE : uncomment and reference the correct game object
//roomCodeLabel.text = currentRoom.code; //roomCodeLabel.text = currentRoom.code;
}); });
@ -210,9 +210,18 @@ public void GenerateCouples()
/// is automatically called when a player connect to the room /// is automatically called when a player connect to the room
/// </summary> /// </summary>
/// <param name="_player"></param> /// <param name="_player"></param>
public void PlayerConnect(Player _player) public void PlayerConnect(object sender, ChildChangedEventArgs args)
{ {
if (args.DatabaseError != null)
{
Debug.LogError(args.DatabaseError.Message);
return;
}
string JSON = args.Snapshot.GetRawJsonValue();
Player joinedPlayer = JsonUtility.FromJson<Player>(JSON);
Debug.Log($"{joinedPlayer.name} has joined the room");
//TODO Marine : do somtethjing with the newly joinde player
} }
[ContextMenu("Fake Player Connection")] [ContextMenu("Fake Player Connection")]

View File

@ -48,6 +48,7 @@ PlayerSettings:
defaultScreenHeightWeb: 600 defaultScreenHeightWeb: 600
m_StereoRenderingPath: 0 m_StereoRenderingPath: 0
m_ActiveColorSpace: 1 m_ActiveColorSpace: 1
unsupportedMSAAFallback: 0
m_SpriteBatchVertexThreshold: 300 m_SpriteBatchVertexThreshold: 300
m_MTRendering: 1 m_MTRendering: 1
mipStripping: 0 mipStripping: 0
@ -75,6 +76,7 @@ PlayerSettings:
androidMinimumWindowWidth: 400 androidMinimumWindowWidth: 400
androidMinimumWindowHeight: 300 androidMinimumWindowHeight: 300
androidFullscreenMode: 1 androidFullscreenMode: 1
androidAutoRotationBehavior: 1
defaultIsNativeResolution: 1 defaultIsNativeResolution: 1
macRetinaSupport: 1 macRetinaSupport: 1
runInBackground: 1 runInBackground: 1
@ -86,6 +88,7 @@ PlayerSettings:
hideHomeButton: 0 hideHomeButton: 0
submitAnalytics: 1 submitAnalytics: 1
usePlayerLog: 1 usePlayerLog: 1
dedicatedServerOptimizations: 0
bakeCollisionMeshes: 0 bakeCollisionMeshes: 0
forceSingleInstance: 0 forceSingleInstance: 0
useFlipModelSwapchain: 1 useFlipModelSwapchain: 1
@ -125,6 +128,7 @@ PlayerSettings:
switchNVNMaxPublicTextureIDCount: 0 switchNVNMaxPublicTextureIDCount: 0
switchNVNMaxPublicSamplerIDCount: 0 switchNVNMaxPublicSamplerIDCount: 0
switchNVNGraphicsFirmwareMemory: 32 switchNVNGraphicsFirmwareMemory: 32
switchMaxWorkerMultiple: 8
stadiaPresentMode: 0 stadiaPresentMode: 0
stadiaTargetFramerate: 0 stadiaTargetFramerate: 0
vulkanNumSwapchainBuffers: 3 vulkanNumSwapchainBuffers: 3
@ -133,6 +137,8 @@ PlayerSettings:
vulkanEnableLateAcquireNextImage: 0 vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1 vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0 loadStoreDebugModeEnabled: 0
visionOSBundleVersion: 1.0
tvOSBundleVersion: 1.0
bundleVersion: 0.1 bundleVersion: 0.1
preloadedAssets: [] preloadedAssets: []
metroInputSource: 0 metroInputSource: 0
@ -145,6 +151,7 @@ PlayerSettings:
isWsaHolographicRemotingEnabled: 0 isWsaHolographicRemotingEnabled: 0
enableFrameTimingStats: 0 enableFrameTimingStats: 0
enableOpenGLProfilerGPURecorders: 1 enableOpenGLProfilerGPURecorders: 1
allowHDRDisplaySupport: 0
useHDRDisplay: 0 useHDRDisplay: 0
hdrBitDepth: 0 hdrBitDepth: 0
m_ColorGamuts: 00000000 m_ColorGamuts: 00000000
@ -590,7 +597,7 @@ PlayerSettings:
switchSocketConcurrencyLimit: 14 switchSocketConcurrencyLimit: 14
switchScreenResolutionBehavior: 2 switchScreenResolutionBehavior: 2
switchUseCPUProfiler: 0 switchUseCPUProfiler: 0
switchUseGOLDLinker: 0 switchEnableFileSystemTrace: 0
switchLTOSetting: 0 switchLTOSetting: 0
switchApplicationID: 0x01004b9000490000 switchApplicationID: 0x01004b9000490000
switchNSODependencies: switchNSODependencies:
@ -720,7 +727,6 @@ PlayerSettings:
switchSocketBufferEfficiency: 4 switchSocketBufferEfficiency: 4
switchSocketInitializeEnabled: 1 switchSocketInitializeEnabled: 1
switchNetworkInterfaceManagerInitializeEnabled: 1 switchNetworkInterfaceManagerInitializeEnabled: 1
switchPlayerConnectionEnabled: 1
switchUseNewStyleFilepaths: 1 switchUseNewStyleFilepaths: 1
switchUseLegacyFmodPriorities: 0 switchUseLegacyFmodPriorities: 0
switchUseMicroSleepForYield: 1 switchUseMicroSleepForYield: 1
@ -834,7 +840,7 @@ PlayerSettings:
additionalCompilerArguments: {} additionalCompilerArguments: {}
platformArchitecture: {} platformArchitecture: {}
scriptingBackend: scriptingBackend:
Android: 1 Android: 0
Standalone: 1 Standalone: 1
il2cppCompilerConfiguration: {} il2cppCompilerConfiguration: {}
il2cppCodeGeneration: {} il2cppCodeGeneration: {}