XRoom_Unity/Assets/EN.cs

114 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Android;
using static ENMenu;
public class EN : MonoBehaviour
{
public static EN instance;
public List<User> users = new List<User>();
public User SelectedUser;
public User Me;
// ✅ Lists for meetings and spaces
public List<Meeting> meetings = new List<Meeting>();
public List<UserSpace> spaces = new List<UserSpace>();
public string selectedSpaceUrl;
public string selectedSpaceId;
public GameObject Error;
void Awake()
{
if (EN.instance)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this.gameObject);
instance = this;
}
public void Start()
{
if (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
{
Permission.RequestUserPermission(Permission.Microphone);
}
// Optionally preload meetings and spaces if Me is available
// StartCoroutine(webservice.instance.GetUserMeetings(OnMeetingsLoaded));
// StartCoroutine(webservice.instance.GetSpaces(OnSpacesLoaded));
}
// ✅ Callback to populate meetings list
public void OnMeetingsLoaded(MeetingResponse response)
{
if (response != null && response.meetings != null)
{
meetings = response.meetings;
Debug.Log("Meetings loaded: " + meetings.Count);
}
else
{
showError("خطا", "بارگذاری جلسات با خطا مواجه شد");
}
}
// ✅ Callback to populate spaces list
public void OnSpacesLoaded(SpaceResponse response)
{
if (response != null && response.spaces != null)
{
spaces = response.spaces;
if (spaces != null && spaces.Count > 0 && spaces[0].assetBundleRoomId != null)
{
selectedSpaceUrl = spaces[0].assetBundleRoomId.url;
}
else
{
Debug.LogWarning("No available spaces or assetBundleRoomId is null.");
selectedSpaceUrl = null; // or some fallback
}
Debug.Log("Spaces loaded: " + spaces.Count);
}
else
{
showError("خطا", "بارگذاری فضاها با خطا مواجه شد");
}
}
public void showError(string title, string description)
{
CancelInvoke("hideError");
gameObject.transform.position = GameObject.FindGameObjectWithTag("anocher").transform.position;
gameObject.transform.rotation = GameObject.FindGameObjectWithTag("anocher").transform.rotation;
Error.SetActive(true);
Error.transform.Find("error/title").GetComponentInChildren<RTLTMPro.RTLTextMeshPro>().text = title;
Error.transform.Find("error/description").GetComponentInChildren<RTLTMPro.RTLTextMeshPro>().text = description;
Invoke("hideError", 6);
}
public void hideError()
{
Error.SetActive(false);
}
internal void Print(string j)
{
print(j);
}
}