Unity3d打包API

First Post:

Last Update:

Word Count:
437

Read Time:
2 min

Unity3d打包API

C#读取xml方式

从xml中读取int类型的方法

1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Xml;
static int GetXmlNodeInt(string tag, int defaultValue)
{
XmlDocument xml_file = new XmlDocument();
var val = xml_file.GetElementsByTagName(tag);
if (val == null || val.Count <= 0) return defaultValue;
int outValue;
if(int.TryParse(val[0].InnerText,out outValue))
{
return outValue;
}
return defaultValue;
}

从xml中读取string类型的方法

1
2
3
4
5
6
7
8
9
10
11
static string GetXmlNodeString(string tag,string defaultValue)
{
XmlDocument xml_file = new XmlDocument();
xml_file.LoadXml("具体的地址");
var val = xml_file.GetElementsByTagName(tag);
if(val == null || val.Count <= 0)
{
return defaultValue;
}
return val[0].InnerText;
}

Unity中相关的设置

Android的数字签名

1
2
3
4
5
6
7
8
9
10
11
12
13
static void SetAndroidSign()
{
//设置bundle的版本号
PlayerSettings.Android.bundleVersionCode = 1;
//设置keystoreName
PlayerSettings.Android.keystoreName = "keystore的路径";
//设置keystore密码
PlayerSettings.Android.keystorePass = "密码";
//设置keyaliasName
PlayerSettings.Android.keyaliasName = "keystore的名称";
//设置keyalias密码
PlayerSettings.Android.keyaliasPass = "跟keystore密码一样";
}

选择对应的平台

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//自定义平台名称
public enum PLATFORM
{
PC = 0,
IOS = 1,
ANDROID = 2,
}
static void SelectPlat(PLATFORM plat)
{
BuildTarget target = BuildTarget.StandaloneWindows64;
BuildTargetGroup targetGroup = BuildTargetGroup.Standalone;
//根据平台选择target和targetGroup
if(plat == PLATFORM.PC)
{
target = BuildTarget.StandaloneWindows64;
targetGroup = BuildTargetGroup.Standalone;
}
else if (plat == PLATFORM.ANDROID)
{
target = BuildTarget.Android;
targetGroup = BuildTargetGroup.Android;
}
else if(plat == PLATFORM.IOS)
{
target = BuildTarget.iOS;
targetGroup = BuildTargetGroup.iOS;
}

//选择当前平台
if(EditorUserBuildSettings.activeBuildTarget != target)
{
EditorUserBuildSettings.SwitchActiveBuildTarget(targetGroup,target);
}

}

获取打包场景名称

1
2
3
4
5
6
7
8
9
10
static string[] GetBuildScenes()
{
List<string> sceneArray = new List<string>();
foreach(EditorBuildSettingsScene e in EditorBuildSettings.scenes)
{
if (e == null) continue;
if (e.enabled) sceneArray.Add(e.path);
}
return sceneArray.ToArray();
}

相关的一些设置

设置com.公司名.包名

1
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup,"com.公司名.包名");

设置宏定义

1
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup,"宏定义");

android专用,设置采用IL2CPP还是Mono

1
PlayerSettings.SetScriptingBackend(BuildTargetGroup,ScriptingImplementation.Mono2X /ScriptingImplementation.IL2CPP);

打包

1
2
string[] scenes = GetBuildScenes();//获取用于打包的场景
BuildPipeline.BuildPlayer(scenes,"输出包路径+输出包名字+后缀",BuildTarget,BuildOptions);

ref:https://blog.csdn.net/weixin_39677098/article/details/103917389

打赏点小钱
支付宝 | Alipay
微信 | WeChat