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)
        {

        }

 

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大不懂

码字不易,一块也是爱,么么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值