Unity3D - WEBGL 中未触发静态动作

发布于 2025-01-15 23:20:56 字数 1352 浏览 1 评论 0原文

当我在 WebGL 上运行应用程序时,我遇到了一个未触发的事件。它在 Unity 编辑器中工作得很好,但在浏览器上,不会调用操作的订阅方法。如果我能得到一些帮助,那就太好了。
这是动作类

public static class RestAction
{
    public static Action<double, double> OnSpinDataReadyToSend;
    public static Action<SlotPlayer> OnSlotMachineReady;
}

Where it is being invoked
public class GameController
{
    void Start()
    {
        RestAction.OnSlotMachineReady?.Invoke(this.MPlayer);
    }
}

And then, the concerned methods
    private void OnEnable()
    {
        RestAction.OnSlotMachineReady += getPlayerInfo;
        SlotPlayer.ChangeCoinsEvent += UpdateBalance;
    }

    private void OnDisable()
    {
        SlotPlayer.ChangeCoinsEvent -= UpdateBalance;
        RestAction.OnSlotMachineReady -= getPlayerInfo;
    }

    private void getPlayerInfo(SlotPlayer player)
    {
        this.MPlayer = player;
        Debug.Log("player number = "+PlayerPrefs.GetString(Player.PlayerKey));
        StartCoroutine(RestClient.Instance.GetPlayerInfo(PLAYER_INFO,PlayerPrefs.GetString(Player.PlayerKey),player.webAPIUpdateCoins));
    }

    private void UpdateBalance(int coins)
    {
        Debug.LogWarning("coins : "+coins);
        StartCoroutine(RestClient.Instance.SendSpinData(WEB_URL,coins,randomCallback));
    }

I'm stuck with an event not triggered when I run an app on WebGL. It works pretty well when within the Unity Editor, but on browser subscribed methods to the Action aren't being called. Would really nice if I may have some helps.

Here is the Action Class

public static class RestAction
{
    public static Action<double, double> OnSpinDataReadyToSend;
    public static Action<SlotPlayer> OnSlotMachineReady;
}

Where it is being invoked

public class GameController
{
    void Start()
    {
        RestAction.OnSlotMachineReady?.Invoke(this.MPlayer);
    }
}

And then, the concerned methods

    private void OnEnable()
    {
        RestAction.OnSlotMachineReady += getPlayerInfo;
        SlotPlayer.ChangeCoinsEvent += UpdateBalance;
    }

    private void OnDisable()
    {
        SlotPlayer.ChangeCoinsEvent -= UpdateBalance;
        RestAction.OnSlotMachineReady -= getPlayerInfo;
    }

    private void getPlayerInfo(SlotPlayer player)
    {
        this.MPlayer = player;
        Debug.Log("player number = "+PlayerPrefs.GetString(Player.PlayerKey));
        StartCoroutine(RestClient.Instance.GetPlayerInfo(PLAYER_INFO,PlayerPrefs.GetString(Player.PlayerKey),player.webAPIUpdateCoins));
    }

    private void UpdateBalance(int coins)
    {
        Debug.LogWarning("coins : "+coins);
        StartCoroutine(RestClient.Instance.SendSpinData(WEB_URL,coins,randomCallback));
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文