diff --git a/Assets/Scenes/CameraView.unity b/Assets/Scenes/CameraView.unity index e51e2a5..e846b17 100644 --- a/Assets/Scenes/CameraView.unity +++ b/Assets/Scenes/CameraView.unity @@ -625,10 +625,10 @@ RectTransform: m_Children: [] m_Father: {fileID: 1908036955} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 1} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_SizeDelta: {x: 512, y: 512} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1128585036 MonoBehaviour: @@ -643,6 +643,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: webCamTexture: {fileID: 0} + freezeButton: {fileID: 1776746473} + resumeButton: {fileID: 1872873213} --- !u!114 &1128585037 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Morgan.unity b/Assets/Scenes/Morgan.unity index b8d2efd..d824fdd 100644 --- a/Assets/Scenes/Morgan.unity +++ b/Assets/Scenes/Morgan.unity @@ -217,6 +217,65 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &1160494271 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1160494274} + - component: {fileID: 1160494273} + - component: {fileID: 1160494272} + m_Layer: 0 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1160494272 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1160494271} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: de098f8fd5f884a1aa55db7874246b92, type: 3} + m_Name: + m_EditorClassIdentifier: + propositionTime: 60 + votingTime: 20 +--- !u!114 &1160494273 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1160494271} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 153bd176c0ad8f82692512264f5245ba, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1160494274 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1160494271} + serializedVersion: 2 + 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: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1330841196 GameObject: m_ObjectHideFlags: 0 @@ -309,72 +368,10 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1963197093 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1963197096} - - component: {fileID: 1963197095} - - component: {fileID: 1963197094} - m_Layer: 0 - m_Name: GameObject - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1963197094 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1963197093} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0735c225bee4c490bbef74cb455fa748, type: 3} - m_Name: - m_EditorClassIdentifier: - promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2} - addPrompt: - k__BackingField: 8c52bab5-726b-42d6-bc54-42ed1898a50c - k__BackingField: hello - k__BackingField: coucou ---- !u!114 &1963197095 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1963197093} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 153bd176c0ad8f82692512264f5245ba, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!4 &1963197096 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1963197093} - serializedVersion: 2 - 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: 0} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 m_Roots: - {fileID: 1330841199} - {fileID: 272045953} - - {fileID: 1963197096} + - {fileID: 1160494274} diff --git a/Assets/Scripts/CameraManager.cs b/Assets/Scripts/CameraManager.cs index 4fbfd69..c1144a7 100644 --- a/Assets/Scripts/CameraManager.cs +++ b/Assets/Scripts/CameraManager.cs @@ -11,14 +11,34 @@ public class CameraManager : MonoBehaviour void Start() { webCamTexture = new WebCamTexture(); + //gameObject.transform.rotation = transform.rotation * Quaternion.AngleAxis(webCamTexture.videoRotationAngle, Vector3.up); WebcamResume(); } // Update is called once per frame void Update() { - gameObject.GetComponent().texture = webCamTexture; - gameObject.GetComponent().material.mainTexture = webCamTexture; + var x = 0; + var y = 0; + var size = webCamTexture.height; + + if (webCamTexture.height > webCamTexture.width) + { + 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().texture = cropped; + gameObject.GetComponent().material.mainTexture = cropped; } public void WebcamResume() diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index 65e124f..27e43a2 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using UnityEngine; [System.Serializable] public class Room @@ -7,5 +8,15 @@ public class Room public List questions; public List players; public int currentQuestion; - public int creationDate; + public double creationDate; + + + public Room(string _code) + { + this.code = _code; + this.creationDate = System.DateTime.Now.ToOADate(); + this.players = new List(); + this.questions = new List(); + this.currentQuestion = 0; + } } diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index aeb1abf..6147313 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -1,10 +1,16 @@ using System.Collections; using System.Collections.Generic; +using Firebase; +using Firebase.Database; +using Firebase.Extensions; +using TMPro; using UnityEngine; +using System; public class RoomManager : MonoBehaviour { private RoomState currentState; + private Room currentRoom = null; private List players; public float propositionTime = 60; @@ -25,13 +31,108 @@ public class RoomManager : MonoBehaviour /// private int numberOfQuestionVoted = 0; + DatabaseReference realtimeDB; + + /// + /// TextMeshPro that show the value of the current rooom code + /// + public TextMeshProUGUI roomCodeLabel; + + private void Awake() + { + FirebaseInitializer.Instance.onFirebaseReady += Initialize; + } + private void Start() { + propositionCurrentTime = propositionTime; votingCurrentTime = votingTime; } + private void OnApplicationQuit() + { + realtimeDB.Child("rooms").Child(currentRoom.code).RemoveValueAsync(); + Debug.Log($"delete room {currentRoom.code}"); + currentRoom = null; + } + + private void Initialize() + { + FirebaseInitializer.Instance.onFirebaseReady -= Initialize; + realtimeDB = FirebaseDatabase.DefaultInstance.RootReference; + Debug.Log("Realtime DB initialized"); + CreateNewRoom(); + } + + /// + /// Check all the rooms in the server and give back the number already taken + /// + private void WhichCodesAreAlreadyUsed(Action> callback_OnCodesChecked) + { + List alreadyUsedCodes = new List(); + realtimeDB.Child("rooms").GetValueAsync().ContinueWithOnMainThread(task => + { + if (task.IsFaulted) + { + Debug.LogException(task.Exception); + } + else if (task.IsCompleted) + { + DataSnapshot snapshot = task.Result; + List onlineRooms = JsonUtility.FromJson>(snapshot.GetRawJsonValue()); + foreach (Room r in onlineRooms) + { + alreadyUsedCodes.Add(int.Parse(r.code)); + } + } + callback_OnCodesChecked?.Invoke(alreadyUsedCodes); + }); + + } + + /// + /// Automatically called at start of game + /// + [ContextMenu("Create New Room")] + public void CreateNewRoom() + { + WhichCodesAreAlreadyUsed(codes => + { + Room newRoom = new Room(GenerateRandomAvailableCode(codes).ToString("D4")); + currentRoom = newRoom; + string JSON = JsonUtility.ToJson(newRoom); + realtimeDB.Child("rooms").Child(newRoom.code).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task => + { + Debug.Log($"room {currentRoom.code} has been created on the server"); + //TODO MARINE : uncomment and reference the correct game object + //roomCodeLabel.text = currentRoom.code; + }); + }); + } + + /// + /// Generate a code between 0 and 1000 that is not in the list + /// + /// the list of code you don"t want to get + /// + private int GenerateRandomAvailableCode(List _impossibleCodes) + { + int random = UnityEngine.Random.Range(0, 1000); + while (_impossibleCodes.Contains(random)) + { + Debug.Log($"{random} is already taken, choosing another room code", this); + random = UnityEngine.Random.Range(0, 1000); + } + return random; + } + + private void DisplayRoomCode() + { + + } + public void PlayerSendProposition(Proposition _proposition) { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index a9cc00e..aa0a8ab 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -8,7 +8,7 @@ PlayerSettings: AndroidProfiler: 0 AndroidFilterTouchesWhenObscured: 0 AndroidEnableSustainedPerformanceMode: 0 - defaultScreenOrientation: 4 + defaultScreenOrientation: 0 targetDevice: 2 useOnDemandResources: 0 accelerometerFrequency: 60 @@ -48,7 +48,6 @@ PlayerSettings: defaultScreenHeightWeb: 600 m_StereoRenderingPath: 0 m_ActiveColorSpace: 1 - unsupportedMSAAFallback: 0 m_SpriteBatchVertexThreshold: 300 m_MTRendering: 1 mipStripping: 0 @@ -76,7 +75,6 @@ PlayerSettings: androidMinimumWindowWidth: 400 androidMinimumWindowHeight: 300 androidFullscreenMode: 1 - androidAutoRotationBehavior: 1 defaultIsNativeResolution: 1 macRetinaSupport: 1 runInBackground: 1 @@ -88,7 +86,6 @@ PlayerSettings: hideHomeButton: 0 submitAnalytics: 1 usePlayerLog: 1 - dedicatedServerOptimizations: 0 bakeCollisionMeshes: 0 forceSingleInstance: 0 useFlipModelSwapchain: 1 @@ -128,7 +125,6 @@ PlayerSettings: switchNVNMaxPublicTextureIDCount: 0 switchNVNMaxPublicSamplerIDCount: 0 switchNVNGraphicsFirmwareMemory: 32 - switchMaxWorkerMultiple: 8 stadiaPresentMode: 0 stadiaTargetFramerate: 0 vulkanNumSwapchainBuffers: 3 @@ -137,8 +133,6 @@ PlayerSettings: vulkanEnableLateAcquireNextImage: 0 vulkanEnableCommandBufferRecycling: 1 loadStoreDebugModeEnabled: 0 - visionOSBundleVersion: 1.0 - tvOSBundleVersion: 1.0 bundleVersion: 0.1 preloadedAssets: [] metroInputSource: 0 @@ -151,7 +145,6 @@ PlayerSettings: isWsaHolographicRemotingEnabled: 0 enableFrameTimingStats: 0 enableOpenGLProfilerGPURecorders: 1 - allowHDRDisplaySupport: 0 useHDRDisplay: 0 hdrBitDepth: 0 m_ColorGamuts: 00000000 @@ -163,6 +156,7 @@ PlayerSettings: applicationIdentifier: Android: fr.snaparazzi Standalone: fr.spnaparazzi + iPhone: fr.snaparazzi buildNumber: Standalone: 0 VisionOS: 0 @@ -596,7 +590,7 @@ PlayerSettings: switchSocketConcurrencyLimit: 14 switchScreenResolutionBehavior: 2 switchUseCPUProfiler: 0 - switchEnableFileSystemTrace: 0 + switchUseGOLDLinker: 0 switchLTOSetting: 0 switchApplicationID: 0x01004b9000490000 switchNSODependencies: @@ -726,6 +720,7 @@ PlayerSettings: switchSocketBufferEfficiency: 4 switchSocketInitializeEnabled: 1 switchNetworkInterfaceManagerInitializeEnabled: 1 + switchPlayerConnectionEnabled: 1 switchUseNewStyleFilepaths: 1 switchUseLegacyFmodPriorities: 0 switchUseMicroSleepForYield: 1