unity 查看运行平台

Posted 大不懂

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity 查看运行平台相关的知识,希望对你有一定的参考价值。

查看官方地址:https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

我写了一个工具类:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KsRunUtils
{
    public static string PlatformDefines()
    {
        string s = "";
        #if UNITY_EDITOR//unity编辑
                s = "UNITY_EDITOR";
        #endif
        
        #if UNITY_EDITOR//directive to call Unity Editor scripts from your game code.
                s = "UNITY_EDITOR";
        #endif
        #if UNITY_EDITOR_WIN//directive for Editor code on Windows.
                s = "UNITY_EDITOR_WIN";
        #endif
        #if UNITY_EDITOR_OSX//directive for Editor code on Mac OS X.
                s = "UNITY_EDITOR_OSX";
        #endif
        #if UNITY_EDITOR_LINUX//directive for Editor code on Linux
                s = "UNITY_EDITOR_LINUX";
        #endif
        #if UNITY_STANDALONE_LINUX //directive for compiling/executing code specifically for Linux standalone applications.
                s = "UNITY_STANDALONE_LINUX";
        #endif
        #if UNITY_STANDALONE //directive for compiling/executing code for any standalone platform (Mac OS X, Windows or Linux).
                s = "UNITY_STANDALONE";
        #endif
        #if UNITY_WII //directive for compiling/executing code for the Wii console.
                s = "UNITY_WII";
        #endif
        #if UNITY_ios //directive for compiling/executing code for the iOS platform.
                s = "UNITY_IOS";
        #endif
        #if UNITY_PS4 //directive for running PlayStation 4 code
                s = UNITY_PS4"";
        #endif
        #if UNITY_XBOXONE //directive for executing Xbox One code.
                s = "UNITY_XBOXONE";
        #endif
        #if UNITY_LUMIN //define directive for the Magic Leap OS platform. You can also use PLATFORM_LUMIN.
                s = "UNITY_LUMIN";
        #endif
        #if UNITY_TIZEN //directive for the Tizen platform.
                s = "UNITY_TIZEN";
        #endif
        #if UNITY_TVOS //directive for the Apple TV platform.
                s = "UNITY_TVOS";
        #endif
        #if UNITY_WSA //directive for Universal Windows Platform. Additionally, NETFX_CORE is defined when compiling C# files against .NET Core and using .NET scripting backend.
                s = "UNITY_WSA";
        #endif
        #if UNITY_WSA_10_0 //directive for Universal Windows Platform. Additionally WINDOWS_UWP is defined when compiling C# files against .NET Core.
                s = "UNITY_WSA_10_0";
        #endif
        #if UNITY_WINRT //UNITY_WSA
                s = "UNITY_WINRT";
        #endif
        #if UNITY_WINRT_10_0 //Equivalent to UNITY_WSA_10_0
                s = "UNITY_WINRT_10_0";
        #endif
        #if UNITY_WEBGL //directive for WebGL
                s = "UNITY_WEBGL";
        #endif
        #if UNITY_FACEBOOK //directive for the Facebook platform (WebGL or Windows standalone).
                s = "UNITY_FACEBOOK";
        #endif
        #if UNITY_ANALYTICS //directive for calling Unity Analytics methods from your game code. Version 5.2 and above
                s = "UNITY_ANALYTICS";
        #endif
        #if UNITY_ASSERTIONS //directive for assertions control process.
                s = "UNITY_ASSERTIONS";
        #endif
        #if UNITY_ASSERTIONS // directive for 64-bit platforms.
                s = "UNITY_ASSERTIONS";
        #endif
        
        
        
        #if UNITY_XBOX360//XBOX360平台 
                s = "UNITY_XBOX360";
        #endif
        #if UNITY_IPHONE//IPHONE平台
                s = "UNITY_IPHONE";
        #endif
        #if UNITY_android//ANDROID平台
                s = "UNITY_ANDROID";
        #endif
        #if UNITY_STANDALONE_OSX//OSX平台
                s = "UNITY_STANDALONE_OSX";
        #endif
        #if UNITY_STANDALONE_WIN//Windows平台
                s = "UNITY_STANDALONE_WIN";
        #endif

        return s;


    }
}

使用的话我是:

  private void onButtonNavigableBoundariesJsonClick()
    {
        

        if (pd.Equals("UNITY_EDITOR") || pd.Equals("UNITY_STANDALONE_WIN"))
        {
            
        }
        else if (pd.Equals("UNITY_ANDROID"))
        {
            
        }
        else
        {
            return;
        }
}

 

也可以用这个方法:

if (Application.platform == RuntimePlatform.Android)
        {

        }

 

以上是关于unity 查看运行平台的主要内容,如果未能解决你的问题,请参考以下文章

unity 查看运行平台

Android 逆向Android 逆向通用工具开发 ( Android 平台运行的 cmd 程序类型 | Android 平台运行的 cmd 程序编译选项 | 编译 cmd 可执行程序 )(代码片段

unity动画一个片段播放完怎么让它不会到初始状态

Unity运行错误代码处理

自定义Mono,实现Unity Android平台代码更新

《java精品毕设》基于javaweb宠物领养平台管理系统(源码+毕设论文+sql):主要实现:个人中心,信息修改,填写领养信息,交流论坛,新闻,寄养信息,公告,宠物领养信息,我的寄养信息等(代码片段