【问题标题】:Unity WebGL check if MobileUnity WebGL 检查是否移动
【发布时间】:2020-03-23 01:40:54
【问题描述】:

如何检查 webgl 是否在移动环境中播放?
我在谷歌上搜索了一些例子,但没有一个能正常工作。
我试过 Input.touchSupported 和 #if UNITY_IOS || UNITY_ANDROID。 有任何想法吗?

【问题讨论】:

    标签: unity3d unity-webgl


    【解决方案1】:

    好的,我刚刚找到了执行此操作的最佳方法。

    http://answers.unity.com/answers/1698985/view.html

    它马上就起作用了。

    assets/plugins/webgl/MyPlugin.jslib

    var MyPlugin = {
       IsMobile: function()
       {
          return UnityLoader.SystemInfo.mobile;
       }
    };  
    mergeInto(LibraryManager.library, MyPlugin);
    

    在统一中

    [DllImport("__Internal")]
     private static extern bool IsMobile();
    
     public bool isMobile()
     {
         #if !UNITY_EDITOR && UNITY_WEBGL
             return IsMobile();
         #endif
         return false;
     }
    

    【讨论】:

      【解决方案2】:

      dav0803 提出的解决方案中,我不得不替换这个:

      返回 UnityLoader.SystemInfo.mobile;

      为此:

      返回 Module.SystemInfo.mobile;

      开始在 Unity 2020.3.30f1 中工作

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多