we can create rooms
This commit is contained in:
parent
2620d91331
commit
6375f4a34f
@ -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:
|
||||
<id>k__BackingField: 8c52bab5-726b-42d6-bc54-42ed1898a50c
|
||||
<fr>k__BackingField: hello
|
||||
<en>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}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Room
|
||||
@ -7,5 +8,15 @@ public class Room
|
||||
public List<Question> questions;
|
||||
public List<Player> 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<Player>();
|
||||
this.questions = new List<Question>();
|
||||
this.currentQuestion = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Firebase;
|
||||
using Firebase.Database;
|
||||
using UnityEngine;
|
||||
|
||||
public class RoomManager : MonoBehaviour
|
||||
{
|
||||
private RoomState currentState;
|
||||
private Room currentRoom = null;
|
||||
private List<Player> players;
|
||||
|
||||
public float propositionTime = 60;
|
||||
@ -25,11 +28,48 @@ public class RoomManager : MonoBehaviour
|
||||
/// </summary>
|
||||
private int numberOfQuestionVoted = 0;
|
||||
|
||||
DatabaseReference realtimeDB;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
FirebaseInitializer.Instance.onFirebaseReady += Initialize;
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
propositionCurrentTime = propositionTime;
|
||||
votingCurrentTime = votingTime;
|
||||
|
||||
//we need to call CreateNewRoom. but not yet
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automatically called at start of game
|
||||
/// </summary>
|
||||
[ContextMenu("Create New Room")]
|
||||
public void CreateNewRoom()
|
||||
{
|
||||
Room newRoom = new Room(Random.Range(0, 1000).ToString("D4"));
|
||||
currentRoom = newRoom;
|
||||
string JSON = JsonUtility.ToJson(newRoom);
|
||||
realtimeDB.Child("rooms").Child(newRoom.code).SetRawJsonValueAsync(JSON);
|
||||
Debug.Log($"room {currentRoom.code} has been created on the server");
|
||||
}
|
||||
|
||||
public void PlayerSendProposition(Proposition _proposition)
|
||||
|
Loading…
Reference in New Issue
Block a user