Unity3D 通过脚本设置PlayerSettings的属性(GPU Skinning,Auto Graphics APi[OpenGLES2])等

Unity3D PlayerSettings脚本设置Android OpenGL、CPU架构、屏幕旋转方式等

官方API链接 PlayerSettings

使用情景:部署Andorid打包环境时。不需要手动设置如图的属性,通过脚本设置。其他同事部署打包环境时可以省略这一步。
Unity3D 通过脚本设置PlayerSettings的属性(GPU Skinning,Auto Graphics APi[OpenGLES2])等_第1张图片
Unity3D 通过脚本设置PlayerSettings的属性(GPU Skinning,Auto Graphics APi[OpenGLES2])等_第2张图片
1)在 Assets/Editor/xxxx.cs的Android打包脚本中初始化AndroidPlayerSettings

        //初始化Android PlayerSettings
public static void initAndroidPlayerSettings()
{
//#if UNITY_ANDROID
    if (PlayerSettings.gpuSkinning)
        PlayerSettings.gpuSkinning = false;
	
	//我使用的Unity客户端版本5.6.2f1
    //注意 Unity客户端高版本 如果Api弃用mobileMTRendering,则改用PlayerSettings.GetMobileMTRendering(BuildTargetGroup targetGroup);
    if (PlayerSettings.mobileMTRendering)
        PlayerSettings.mobileMTRendering = false;
        
    if (PlayerSettings.GetUseDefaultGraphicsAPIs(BuildTarget.Android))
    {
        PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false);
        GraphicsDeviceType[] graphicsDeviceType = new GraphicsDeviceType[1] { GraphicsDeviceType.OpenGLES2 };//如果使用其它版本OpenGL请自行设置
        PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, graphicsDeviceType);
    }

    if (PlayerSettings.Android.targetDevice != AndroidTargetDevice.FAT)
        PlayerSettings.Android.targetDevice = AndroidTargetDevice.FAT;         //Android CPU架构选择(FAT【armeabe-v7 x86】)

    if (!PlayerSettings.use32BitDisplayBuffer)
        PlayerSettings.use32BitDisplayBuffer = true;                           //Use 32-bit Display Buffer

	//设置Android屏幕旋转方式
    if (PlayerSettings.defaultInterfaceOrientation != UIOrientation.AutoRotation)
    {
        PlayerSettings.defaultInterfaceOrientation = UIOrientation.AutoRotation;//Default Orientation
        PlayerSettings.allowedAutorotateToPortrait = false;                     //Protrait                
        PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;           //Protrait Upside Down
        PlayerSettings.allowedAutorotateToLandscapeRight = true;                //Landscape Right
            PlayerSettings.allowedAutorotateToLandscapeLeft = true;                 //Landscape Left
        }
//#endif
    }
}

你可能感兴趣的:(Unity3D)