您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

29 行
1.0 KiB

using System.Threading;
using UnityEditor;
using UnityEngine;
namespace Unity.Services.Relay.Scheduler
{
// "inspired" by UniTask
public static class ThreadHelper
{
public static SynchronizationContext SynchronizationContext => _unitySynchronizationContext;
public static System.Threading.Tasks.TaskScheduler TaskScheduler => _taskScheduler;
public static int MainThreadId => _mainThreadId;
private static SynchronizationContext _unitySynchronizationContext;
private static System.Threading.Tasks.TaskScheduler _taskScheduler;
private static int _mainThreadId;
#if UNITY_EDITOR
[InitializeOnLoadMethod]
#endif
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Init()
{
_unitySynchronizationContext = SynchronizationContext.Current;
_taskScheduler = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
_mainThreadId = Thread.CurrentThread.ManagedThreadId;
}
}
}