当我尝试将事件发送到统一分析(服务,而不是遗留)时,我收到以下错误:
ervicesInitializationException:Analytics 服务尚未初始化。请初始化 Unity 服务。
我使用的初始化脚本是:
using System;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;
public class InitializeUnityServices : MonoBehaviour
{
public string environment = "production";
async void Start()
{
try
{
var options = new InitializationOptions()
.SetEnvironmentName(environment);
await UnityServices.InitializeAsync(options);
}
catch (Exception exception)
{
// An error occurred during services initialization.
}
}
}
不起作用的事件脚本是:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using Unity.Services.Analytics;
using UnityEngine;
using UnityEngine.Analytics;
public class analyticsEvent_ScenePlayed_MainMenu : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
{
Dictionary<string, object> parameters = new Dictionary<string, object>()
{
{ "Scene Played", "Main Menu" },
};
AnalyticsService.Instance.CustomData("ScenePlayed_MainMenu", parameters);
// Analytics.CustomEvent("ScenePlayed_MainMenu");
Debug.Log("Sent ScenePlayed_MainMenu analytics event");
AnalyticsService.Instance.Flush();
Debug.Log("Flushed ScenePlayed_MainMenu analytics event");
}
}
// Update is called once per frame
void Update()
{
}
}
这两个脚本都附加到场景中的组件。这是正确的方法吗?