init
This commit is contained in:
74
Assets/Scripts/AdminLobby.cs
Normal file
74
Assets/Scripts/AdminLobby.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Photon.Pun;
|
||||
using Photon.Realtime;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AdminLobby : MonoBehaviourPunCallbacks, ILobbyCallbacks
|
||||
{
|
||||
|
||||
public GameObject listItemPrefab;
|
||||
public Transform parent;
|
||||
|
||||
public static AdminLobby instance;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(instance != null) { Destroy(gameObject); return; }
|
||||
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
PhotonNetwork.Disconnect();
|
||||
PhotonNetwork.ConnectUsingSettings();
|
||||
}
|
||||
|
||||
public override void OnConnectedToMaster()
|
||||
{
|
||||
base.OnConnectedToMaster();
|
||||
Debug.Log("Connected to photon");
|
||||
PhotonNetwork.JoinLobby();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnRoomListUpdate(List<RoomInfo> roomList)
|
||||
{
|
||||
base.OnRoomListUpdate(roomList);
|
||||
|
||||
//PURGE
|
||||
foreach(Transform child in parent.GetComponentsInChildren<Transform>())
|
||||
{
|
||||
if(child == parent) { continue; }
|
||||
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
RoomInfo _room;
|
||||
foreach(RoomInfo room in roomList)
|
||||
{
|
||||
GameObject newItem = Instantiate(listItemPrefab, parent);
|
||||
_room = room;
|
||||
newItem.GetComponentInChildren<Text>().text = room.Name;
|
||||
newItem.GetComponentInChildren<Button>().onClick.AddListener(() => JoinRoom(_room.Name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JoinRoom(string roomName)
|
||||
{
|
||||
PhotonNetwork.JoinRoom(roomName);
|
||||
PhotonNetwork.LoadLevel("ADMIN_CHAT");
|
||||
|
||||
//PhotonNetwork.Instantiate("Communicator", Vector3.zero, Quaternion.identity);
|
||||
}
|
||||
|
||||
public override void OnJoinedRoom()
|
||||
{
|
||||
base.OnJoinedRoom();
|
||||
Debug.Log("Joined success");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/AdminLobby.cs.meta
Normal file
11
Assets/Scripts/AdminLobby.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 116e29545a58fa84aaa98fd46b9b928d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
45
Assets/Scripts/ChatUI.cs
Normal file
45
Assets/Scripts/ChatUI.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ChatUI : MonoBehaviour
|
||||
{
|
||||
public GameObject chatItemPrefab;
|
||||
public Transform chatParent;
|
||||
|
||||
public static ChatUI instance;
|
||||
|
||||
public InputField chatInputField;
|
||||
public Button sendBtn;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
//PURGE
|
||||
foreach(Transform t in chatParent.GetComponentInChildren<Transform>())
|
||||
{
|
||||
if(t != chatItemPrefab) { Destroy(t.gameObject); }
|
||||
}
|
||||
|
||||
sendBtn.onClick.AddListener(SendMsg);
|
||||
chatInputField.onEndEdit.AddListener(SendMsg);
|
||||
}
|
||||
|
||||
public void AddNewMessage(string message,bool isMe)
|
||||
{
|
||||
GameObject newChatItem = Instantiate(chatItemPrefab,chatParent);
|
||||
newChatItem.GetComponentInChildren<Text>().text = message;
|
||||
newChatItem.GetComponentInChildren<Text>().alignment = isMe ? TextAnchor.MiddleRight : TextAnchor.MiddleLeft;
|
||||
}
|
||||
|
||||
public void SendMsg()
|
||||
{
|
||||
SendMsg("");
|
||||
}
|
||||
public void SendMsg(string msg)
|
||||
{
|
||||
MPChat.instance.SendMsg(chatInputField.text);
|
||||
chatInputField.text = "";
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ChatUI.cs.meta
Normal file
11
Assets/Scripts/ChatUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 566d1306559c27a4299fab4251a10424
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/ClientManager.cs
Normal file
35
Assets/Scripts/ClientManager.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
//using Oculus.Voice.Dictation;
|
||||
using Oculus.Voice.Dictation;
|
||||
using Photon.Pun;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ClientManager : MonoBehaviour
|
||||
{
|
||||
public TMPro.TMP_InputField inputField;
|
||||
public TMPro.TMP_Text text;
|
||||
|
||||
public AppDictationExperience voiceToText;
|
||||
|
||||
public static ClientManager instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
PhotonNetwork.Instantiate("Communicator", Vector3.zero, Quaternion.identity);
|
||||
//TTSSpeaker.speaker.Speak(text.text);
|
||||
|
||||
// voiceToText.DictationEvents.OnFullTranscription.AddListener(SendMessage);
|
||||
}
|
||||
public void SendMsg(string message)
|
||||
{
|
||||
MPChat.instance.SendMsg(message);
|
||||
inputField.text = "";
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/ClientManager.cs.meta
Normal file
11
Assets/Scripts/ClientManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31ae767e8e982be4eaf07c0fe6f7cbd0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Scripts/MPChat.cs
Normal file
43
Assets/Scripts/MPChat.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Meta.WitAi.TTS.Utilities;
|
||||
using Photon.Pun;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class MPChat : MonoBehaviourPunCallbacks
|
||||
{
|
||||
public static bool isAdmin;
|
||||
public static MPChat instance;
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void SendMsg(string msg)
|
||||
{
|
||||
photonView.RPC("_SendMsg", RpcTarget.All, msg, isAdmin ? "ADMIN" : MultiplayerManager.uid);
|
||||
if (isAdmin)
|
||||
{
|
||||
//ChatUI.instance.AddNewMessage(msg, true);
|
||||
}
|
||||
}
|
||||
|
||||
[PunRPC]
|
||||
void _SendMsg(string message, string author)
|
||||
{
|
||||
Debug.Log($"{author} said {message}");
|
||||
if(isAdmin)
|
||||
{
|
||||
ChatUI.instance.AddNewMessage(message, author == "ADMIN");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (author == "ADMIN")
|
||||
{
|
||||
TTSSpeaker.speaker.Speak(message);
|
||||
ClientManager.instance.text.text = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MPChat.cs.meta
Normal file
11
Assets/Scripts/MPChat.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 610d87131bf0bf1489883a4625b1ad45
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Scripts/MainMenu.cs
Normal file
29
Assets/Scripts/MainMenu.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public InputField password;
|
||||
public Button loginBtn;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
loginBtn.onClick.AddListener(Login);
|
||||
}
|
||||
|
||||
void Login()
|
||||
{
|
||||
if(password.text == "admin@123")
|
||||
{
|
||||
MPChat.isAdmin = true;
|
||||
SceneManager.LoadScene("ADMIN_LOBBY");
|
||||
}
|
||||
else
|
||||
{
|
||||
password.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MainMenu.cs.meta
Normal file
11
Assets/Scripts/MainMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34655b55a23dc3446b3b3893f3dd2b34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
Assets/Scripts/MultiplayerManager.cs
Normal file
60
Assets/Scripts/MultiplayerManager.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Photon.Pun;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MultiplayerManager : MonoBehaviourPunCallbacks
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
private static string _uid = "";
|
||||
|
||||
public static MultiplayerManager instance;
|
||||
|
||||
public bool isVR = false;
|
||||
|
||||
public static string uid { get {
|
||||
if(_uid == "")
|
||||
{
|
||||
char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
|
||||
|
||||
while(_uid.Length < 6)
|
||||
{
|
||||
_uid += chars[Random.Range(0, chars.Length)];
|
||||
}
|
||||
Debug.Log("New uid: " + _uid);
|
||||
}
|
||||
return _uid; } }
|
||||
void Awake()
|
||||
{
|
||||
if(instance != null) { Destroy(gameObject); return; }
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
PhotonNetwork.ConnectUsingSettings();
|
||||
|
||||
}
|
||||
|
||||
public override void OnConnectedToMaster()
|
||||
{
|
||||
base.OnConnectedToMaster();
|
||||
|
||||
Debug.Log("Connected to photon");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
public void ConnectToAdmin()
|
||||
{
|
||||
PhotonNetwork.CreateRoom(uid);
|
||||
}
|
||||
|
||||
public override void OnCreatedRoom()
|
||||
{
|
||||
base.OnCreatedRoom();
|
||||
Debug.Log("New room created : " + uid);
|
||||
MPChat.isAdmin = false;
|
||||
PhotonNetwork.LoadLevel(isVR ? "ADMIN_MP_VR" : "ADMIN_MP");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/MultiplayerManager.cs.meta
Normal file
11
Assets/Scripts/MultiplayerManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dac205cf925a5fb4599d14d06b386a5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/SceneLoader.cs
Normal file
17
Assets/Scripts/SceneLoader.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Photon.Pun;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SceneLoader : MonoBehaviour
|
||||
{
|
||||
public void LoadScene(string levelName)
|
||||
{
|
||||
|
||||
SceneManager.LoadScene(levelName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
11
Assets/Scripts/SceneLoader.cs.meta
Normal file
11
Assets/Scripts/SceneLoader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b62211e828a0b034d8daf5cf68bd32c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Scripts/VRSwitch.cs
Normal file
20
Assets/Scripts/VRSwitch.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class VRSwitch : MonoBehaviour
|
||||
{
|
||||
public RectTransform canvas;
|
||||
public RectTransform vrCanvas;
|
||||
public GameObject[] hideForVR;
|
||||
void Start()
|
||||
{
|
||||
// if(Application.platform == RuntimePlatform.)
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/VRSwitch.cs.meta
Normal file
11
Assets/Scripts/VRSwitch.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f319dae424eb15b45a2763dc144cff26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user