这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private void Init(RequestBuilder requestBuilder, RequestRepository requestRepo,
Notifications = new NotificationsCallbackService(Configuration, _logHelper);
ProxyNotificationsService notificationsService = new ProxyNotificationsService(transform, Configuration, _logHelper, InternalStartCoroutine, Events);
_push = new PushCountlyService(Configuration, _logHelper, RequestHelper, notificationsService, Notifications, Consents);
Session = new SessionCountlyService(Configuration, _logHelper, Events, RequestHelper, Location, Consents);
Session = new SessionCountlyService(Configuration, _logHelper, Events, RequestHelper, Location, Consents, this);

CrashReports = new CrashReportsCountlyService(Configuration, _logHelper, RequestHelper, Consents);
Initialization = new InitializationCountlyService(Configuration, _logHelper, Location, Session, Consents);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Threading;
using Plugins.CountlySDK;
using UnityEngine;

public class CountlyMainThreadHandler : MonoBehaviour
{
private static CountlyMainThreadHandler _instance;
private Thread mainThread;
private Action _queuedAction;
private readonly object lockObject = new object(); // For thread safety

public static CountlyMainThreadHandler Instance
{
get {
if (_instance == null) {
// If instance is null, add this script to the created Countly object
GameObject gameObject = Countly.Instance.gameObject;
_instance = gameObject.AddComponent<CountlyMainThreadHandler>();
}
return _instance;
}
internal set {
// Allow internal setting of the instance (used during cleanup)
_instance = value;
}
}

private void Awake()
{
// Record the main thread when the script is first initialized
mainThread = Thread.CurrentThread;
}

public bool IsMainThread()
{
return Thread.CurrentThread.ManagedThreadId == mainThread.ManagedThreadId;
}

public void RunOnMainThread(Action action)
{
// Check if we are on the main thread
if (IsMainThread()) {
// If on the main thread, invoke the action immediately
action.Invoke();
} else {
// If on a different thread, queue the action to be executed on the main thread
lock (lockObject) {
_queuedAction = action;
}
}
}

private void Update()
{
// Execute any queued action on the main thread during the Unity Update phase
if (_queuedAction != null) {
lock (lockObject) {
_queuedAction.Invoke();
_queuedAction = null;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading