You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.4 KiB
102 lines
2.4 KiB
using UnityEngine;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager Instance { get; private set; }
|
|
private void Awake()
|
|
{
|
|
if (Instance == null) Instance = this;
|
|
}
|
|
|
|
[SerializeField] private Player localPlayer;
|
|
[SerializeField] private CameraController cameraController;
|
|
|
|
[Header("Managers")]
|
|
[SerializeField] private SceneLoader sceneLoader;
|
|
[SerializeField] private MainScreensManager mainScreensManager;
|
|
|
|
[Header("References")]
|
|
[SerializeField] private GameObject loadingScreen;
|
|
[SerializeField] private Camera mainCamera;
|
|
|
|
[Header("Data")]
|
|
[SerializeField] private CharactersList charactersList;
|
|
[SerializeField] private EmojiPopupData emojiPopupData;
|
|
|
|
|
|
public static CharactersList CharactersList => Instance.charactersList;
|
|
public static EmojiPopupData EmojiPopupData => Instance.emojiPopupData;
|
|
public static Player LocalPlayer => Instance.localPlayer;
|
|
public static Camera MainCamera => Instance.mainCamera;
|
|
|
|
public void Loaded()
|
|
{
|
|
JoinMyRoom();
|
|
}
|
|
|
|
public void LoadScene(string sceneName)
|
|
{
|
|
sceneLoader.LoadScene(sceneName, () =>
|
|
{
|
|
loadingScreen.SetActive(false);
|
|
mainScreensManager.SetGameScreen();
|
|
LocalPlayer.SetPosition(new Vector3());
|
|
});
|
|
}
|
|
|
|
public void JoinLocation()
|
|
{
|
|
loadingScreen.SetActive(true);
|
|
ConnectionManager.Instance.JoinLocation(() =>
|
|
{
|
|
LoadScene("Cafe");
|
|
});
|
|
}
|
|
|
|
public void JoinMyRoom()
|
|
{
|
|
string roomName = "Room1"; //get from database;
|
|
loadingScreen.SetActive(true);
|
|
ConnectionManager.Instance.CreateLobby("MyRoom", 1, true, () =>
|
|
{
|
|
LoadScene(roomName);
|
|
});
|
|
}
|
|
|
|
public void SetCharacter(Character character)
|
|
{
|
|
LocalPlayer.SetCharacter(character);
|
|
}
|
|
|
|
public void PlayAnim(string anim)
|
|
{
|
|
LocalPlayer.PlayAnimation(anim);
|
|
}
|
|
|
|
public void Lay()
|
|
{
|
|
LocalPlayer.Lay();
|
|
}
|
|
|
|
public void Sit()
|
|
{
|
|
LocalPlayer.Sit();
|
|
}
|
|
|
|
public void Emoji(int emoji)
|
|
{
|
|
LocalPlayer.SpawnEmoji(emoji);
|
|
}
|
|
|
|
public void SetLocalPlayer(Player player)
|
|
{
|
|
if (!player.IsOwner)
|
|
{
|
|
Debug.LogError("Trying to assign not owned player");
|
|
return;
|
|
}
|
|
|
|
localPlayer = player;
|
|
cameraController.SetTarget(player.transform);
|
|
}
|
|
}
|
|
|