打包各个平台-总结(自己记录)
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.XR.Management;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Management;
public class SettingWindows : EditorWindow
{
string AndmanifestFilerootpath = @"\Plugins\Android\";
private string Macro = null;
XRGeneralSettings buildTargetSettings;
/// <summary>
/// 每打开一次窗口就会执行一次
/// </summary>
private void OnEnable()
{
buildTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.Android);
Macro = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android);//获取宏信息 参数:获取哪个平台下的
Debug.Log("获取宏:" + Macro);
}
private void OnGUI()
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Pico-发布设置", GUILayout.Width(110)))
{
SaveMacro();
}
if (GUILayout.Button("创维一体机-发布设置", GUILayout.Width(160)))
{
SaveMacro("创维一体机");
}
EditorGUILayout.EndHorizontal();
}
private void SaveMacro(string hong = "")
{
if (!string.IsNullOrEmpty(hong))
{
Macro += ";" + hong;
buildTargetSettings.InitManagerOnStart = true;
FileMoveToReName(false);
}
else
{
buildTargetSettings.InitManagerOnStart = false;
Macro = Macro.Replace(";创维一体机", " ");
FileMoveToReName(true);
}
Debug.Log("新的宏: " + Macro + " - XR init on start 设置: " + buildTargetSettings.InitManagerOnStart);
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, Macro);
}
private void FileMoveToReName(bool isPico = true)
{
string ManifestName = Application.dataPath + AndmanifestFilerootpath + "AndroidManifest.xml";
string skyworthManifestName = Application.dataPath + AndmanifestFilerootpath + "AndroidManifest-skyworth.xml";
string picoManifestName = Application.dataPath + AndmanifestFilerootpath + "AndroidManifest-PICO.xml";
if (File.Exists(skyworthManifestName) && File.Exists(picoManifestName))
{
if (isPico)
File.Move(picoManifestName, ManifestName);
else
File.Move(skyworthManifestName, ManifestName);
}
else if (File.Exists(skyworthManifestName) && File.Exists(ManifestName))
{
if (!isPico)
{
File.Move(ManifestName, picoManifestName);
File.Move(skyworthManifestName, ManifestName);
}
}
else if (File.Exists(picoManifestName) && File.Exists(ManifestName))
{
if (isPico)
{
File.Move(ManifestName, skyworthManifestName);
File.Move(picoManifestName, ManifestName);
}
}
AssetDatabase.Refresh();
}
}
public class Menu
{
[MenuItem("Tools/Setting")]
public static void Settings()
{
SettingWindows sw = EditorWindow.GetWindow<SettingWindows>();
sw.titleContent = new GUIContent("设置窗口");
sw.Show();
}
}