Version: 2022.1
public static bool enabled ;

描述

控制是否在运行时启用 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
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961