控制是否在运行时启用 Analytics 服务。
在运行时将此属性设置为 false 可以禁用 Analytics 服务。
您可以将此属性设为 true 以重新启用 Analytics 服务,但前提是构建项目时启用了 Analytics。
如果构建项目时未启用 Analytics,则无法使用此设置在运行时启用该服务。
using System; using UnityEngine;
#if ENABLE_CLOUD_SERVICES_ANALYTICS using UnityEngine.Analytics;
public class DataPrivacyOptInFlow { [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void InitStepOne() { Analytics.initializeOnStartup = false; }
public void EnableAnonymizingData() { Analytics.limitUserTracking = true; }
// Call this when the user has given permission to collect data public void UserHasOptedIntoDataCollection_LetsResumeAnalyticsInitialization() { Analytics.ResumeInitialization(); }
// Call this when the user has given limited data collection permission public void UserHasOptedIntoLimitedDataCollection_LetsResumeAnalyticsInitialization() { EnableAnonymizingData(); Analytics.ResumeInitialization(); }
// Call this when the user doesn't want any data collection. public void UserHasOptedOutOfAllDataCollection() { // Don't call ResumeInitialization // But disable Analytics so the code knows to shutdown DisableAnalyticsCompletely(); }
// If you want to disable Analytics completely during runtime public void DisableAnalyticsCompletely() { Analytics.enabled = false; Analytics.deviceStatsEnabled = false; PerformanceReporting.enabled = false; } } #endif