400 lines
14 KiB
C#
400 lines
14 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEditor;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using GameEditor.Core;
|
||
using GameEditor.GameEditor.PlayerBuilder;
|
||
using GameLogic;
|
||
using System.Diagnostics;
|
||
using ResUpdate;
|
||
using GameCore;
|
||
using System.Net;
|
||
|
||
namespace GameEditor.FrameTool {
|
||
public class BuildWindow : EditorWindow
|
||
{
|
||
/// <summary>
|
||
/// 版本文件名
|
||
/// </summary>
|
||
const string VersionsFile = "version";
|
||
|
||
Version version;
|
||
string defaultVersion;
|
||
string subChannel;
|
||
string serverUrl;
|
||
string resUrl;
|
||
|
||
/// <summary>
|
||
/// 导出APK/XCODE工程
|
||
/// </summary>
|
||
bool isBuildPlayer;
|
||
/// <summary>
|
||
/// 是否拷贝AB包到StreamingAssets
|
||
/// </summary>
|
||
bool isCopyABSToStreamingAssets;
|
||
// Add menu named "My Window" to the Window menu
|
||
[MenuItem("Build/BuildWindow")]
|
||
static void Init()
|
||
{
|
||
|
||
// Get existing open window or if none, make a new one:
|
||
BuildWindow window = (BuildWindow)EditorWindow.GetWindow(typeof(BuildWindow));
|
||
window.Show();
|
||
window.InitWindow();
|
||
|
||
}
|
||
|
||
void InitWindow()
|
||
{
|
||
InitSize();
|
||
InitGames();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化大小
|
||
/// </summary>
|
||
void InitSize()
|
||
{
|
||
minSize = new Vector2(300, 400);
|
||
maxSize = new Vector2(300, 650);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 初始化游戏
|
||
/// </summary>
|
||
void InitGames()
|
||
{
|
||
//version = new Version(Resources.Load<TextAsset>(VersionsFile).text);
|
||
//defaultVersion = version.GetInfo("version");
|
||
//subChannel = version.GetInfo("subChannel");
|
||
//serverUrl = version.GetInfo("serverUrl");
|
||
//resUrl = version.GetInfo("resUrl");
|
||
}
|
||
|
||
void OnGUI()
|
||
{
|
||
EditorGUILayout.BeginVertical();
|
||
EditorGUILayout.Space();
|
||
EditorGUILayout.LabelField(string.Format("当前平台:{0}", EditorUserBuildSettings.activeBuildTarget.ToString()));
|
||
EditorGUILayout.Space();
|
||
EditorGUILayout.EndVertical();
|
||
|
||
isCopyABSToStreamingAssets = EditorGUILayout.BeginToggleGroup("拷贝AssetBundle到流媒体目录(打包到App包体内)", isCopyABSToStreamingAssets);
|
||
//if (isCopyABSToStreamingAssets)
|
||
//{
|
||
// EditorGUILayout.BeginVertical();
|
||
// defaultVersion = EditorGUILayout.TextField("Version", defaultVersion);
|
||
// subChannel = EditorGUILayout.TextField("SubChannel", subChannel);
|
||
// serverUrl = EditorGUILayout.TextField("ServerUrl", serverUrl);
|
||
// resUrl = EditorGUILayout.TextField("ResUrl", resUrl);
|
||
// EditorGUILayout.EndVertical();
|
||
//}
|
||
EditorGUILayout.EndToggleGroup();
|
||
EditorGUILayout.Space();
|
||
|
||
isBuildPlayer = EditorGUILayout.BeginToggleGroup(GetBuildTitle(), isBuildPlayer);
|
||
if (isBuildPlayer)
|
||
{
|
||
var gameSet = GameObject.FindObjectOfType<GameSettings>();
|
||
gameSet.settingInfo.isUpdate = true;
|
||
gameSet.settingInfo.bundleMode = true;
|
||
gameSet.settingInfo.isDebug = false;
|
||
gameSet.settingInfo.luaBundleMode = true;
|
||
}
|
||
EditorGUILayout.EndToggleGroup();
|
||
EditorGUILayout.Space();
|
||
|
||
if (GUILayout.Button("整体打包", GUILayout.Height(40f)))
|
||
{
|
||
if (EditorUtility.DisplayDialog("打包提示", "打包将持续一段时间,确定打包?", "是", "否")) //显示对话框
|
||
{
|
||
BuildGame();
|
||
}
|
||
}
|
||
if (GUILayout.Button("单打lua资源", GUILayout.Height(40f)))
|
||
{
|
||
if (EditorUtility.DisplayDialog("打包提示", "单打lua资源将持续一段时间,确定打包?", "是", "否")) //显示对话框
|
||
{
|
||
if (FrameTool.BuildLuaAssetBundles())
|
||
{
|
||
//拷贝AssetBundle到流媒体目录
|
||
if (isCopyABSToStreamingAssets)
|
||
{
|
||
string exportPath = AssetBundle.AssetBundleConfig.GetExportPath(EditorUserBuildSettings.activeBuildTarget);
|
||
string targetPath = FrameTool.GetStreamingAssetPath(EditorUserBuildSettings.activeBuildTarget);
|
||
|
||
#if PLATFORM_IOS
|
||
File.Copy(exportPath + "/lzma_luabytes.unity3d", targetPath + "/lzma_luabytes.unity3d", true);
|
||
File.Copy(exportPath + "/lzma_resconfigs.unity3d", targetPath + "/lzma_resconfigs.unity3d", true);
|
||
#else
|
||
File.Copy(exportPath + "/lzma/luabytes.unity3d", targetPath + "/lzma/luabytes.unity3d", true);
|
||
File.Copy(exportPath + "/lzma/resconfigs.unity3d", targetPath + "/lzma/resconfigs.unity3d", true);
|
||
#endif
|
||
|
||
File.Copy(exportPath + "/files.unity3d", targetPath + "/files.unity3d", true);
|
||
//SaveVersionFile();
|
||
}
|
||
Close();
|
||
}
|
||
}
|
||
}
|
||
if (GUILayout.Button("资源合法性检查", GUILayout.Height(40f)))
|
||
{
|
||
FrameTool.CheckAssetBundleStates();
|
||
}
|
||
if (GUILayout.Button("查看多依赖资源", GUILayout.Height(40f)))
|
||
{
|
||
FrameTool.AssetsDuplicatedInMultBundlesCache(1);
|
||
}
|
||
if (GUILayout.Button("处理多依赖资源", GUILayout.Height(40f)))
|
||
{
|
||
FrameTool.AssetsDuplicatedInMultBundlesCache(2);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打包游戏
|
||
/// </summary>
|
||
void BuildGame()
|
||
{
|
||
//打包游戏
|
||
FrameTool.BuildGameAssetBundles();
|
||
|
||
//拷贝AssetBundle到流媒体目录
|
||
if (isCopyABSToStreamingAssets)
|
||
{
|
||
FrameTool.CopyAssetBundleToStreamingAssets();
|
||
//SaveVersionFile();
|
||
}
|
||
//是否BuildPlayer
|
||
if (isBuildPlayer)
|
||
{
|
||
switch (EditorUserBuildSettings.activeBuildTarget)
|
||
{
|
||
case BuildTarget.Android:
|
||
ExportApk();
|
||
break;
|
||
case BuildTarget.iOS:
|
||
ExportXcode();
|
||
break;
|
||
}
|
||
}
|
||
Close();
|
||
}
|
||
|
||
void SaveVersionFile()
|
||
{
|
||
var VersionsFilePath = Application.dataPath + "/Resources/" + VersionsFile + ".txt";
|
||
var VersionsFilePath2 = AppConst.PersistentDataPath + VersionsFile + ".txt";
|
||
|
||
version.SetInfo("version", defaultVersion);
|
||
version.SetInfo("subChannel", subChannel);
|
||
version.SetInfo("serverUrl", serverUrl);
|
||
version.SetInfo("resUrl", resUrl);
|
||
|
||
string directoryPath = Path.GetDirectoryName(VersionsFilePath);
|
||
if (!Directory.Exists(directoryPath))
|
||
Directory.CreateDirectory(directoryPath);
|
||
File.WriteAllText(VersionsFilePath, version.ToJson(), System.Text.Encoding.UTF8);
|
||
|
||
string directoryPath2 = Path.GetDirectoryName(VersionsFilePath2);
|
||
if (!Directory.Exists(directoryPath2))
|
||
Directory.CreateDirectory(directoryPath2);
|
||
File.WriteAllText(VersionsFilePath2, version.ToJson(), System.Text.Encoding.UTF8);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取是否打包
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
string GetBuildTitle()
|
||
{
|
||
switch (EditorUserBuildSettings.activeBuildTarget)
|
||
{
|
||
case BuildTarget.Android:
|
||
return "导出APK";
|
||
case BuildTarget.iOS:
|
||
return "导出XCODE工程";
|
||
}
|
||
return "请切换到Android/IOS平台";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导出XCODE工程
|
||
/// </summary>
|
||
void ExportXcode()
|
||
{
|
||
PlayerBuilder.BuildXCode();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否导出APK
|
||
/// </summary>
|
||
void ExportApk()
|
||
{
|
||
PlayerBuilder.BuildApk();
|
||
}
|
||
}
|
||
|
||
public class VersionTxt
|
||
{
|
||
public string subChannel;
|
||
public string buglyId;
|
||
public string channel;
|
||
public string resUrl;
|
||
public string packageVersion;
|
||
public string version;
|
||
public string serverUrl;
|
||
//public string noticeChannel;
|
||
}
|
||
|
||
|
||
public class VersionWindow : EditorWindow
|
||
{
|
||
static string versionPath = Application.dataPath + "/../Version";
|
||
static string editorVersion = Application.dataPath + "/../AssetBundles";// + AppConst.GameVersionFile;
|
||
//static string persistVersion = Application.dataPath + "/Resources/version.txt";
|
||
static string streamVersion = AppConst.StreamPath + AppConst.GameVersionFile;
|
||
|
||
static VersionTxt m_VersionTxt; // 热更版本
|
||
|
||
|
||
|
||
static string[] m_Files;
|
||
static bool[] m_Choose;
|
||
static string m_Ver;
|
||
|
||
|
||
|
||
|
||
[MenuItem("Build/Version")]
|
||
static void Init()
|
||
{
|
||
LoadVersion(editorVersion);
|
||
LoadDic();
|
||
// Get existing open window or if none, make a new one:
|
||
VersionWindow window = (VersionWindow)EditorWindow.GetWindow(typeof(VersionWindow));
|
||
window.Show();
|
||
|
||
}
|
||
// 加载version文件
|
||
private static void LoadVersion(string path)
|
||
{
|
||
versionPath = path + "/" + AppConst.GameVersionFile;
|
||
if (!string.IsNullOrEmpty(versionPath) && File.Exists(versionPath))
|
||
{
|
||
string json = File.ReadAllText(versionPath);
|
||
m_VersionTxt = JsonUtility.FromJson<VersionTxt>(json);
|
||
}
|
||
if (!path.Equals(editorVersion))
|
||
{
|
||
SaveToEditorPath();
|
||
}
|
||
}
|
||
|
||
// 保存到编辑器路径
|
||
private static void SaveToEditorPath()
|
||
{
|
||
string json = JsonUtility.ToJson(m_VersionTxt);
|
||
SaveToVersion(editorVersion, json);
|
||
}
|
||
// 保存到打包路径
|
||
private static void SaveToBuildPath()
|
||
{
|
||
string json = JsonUtility.ToJson(m_VersionTxt);
|
||
//SaveToVersion(persistVersion, json);
|
||
SaveToVersion(streamVersion, json);
|
||
}
|
||
// 保存到version
|
||
private static void SaveToVersion(string path, string json)
|
||
{
|
||
if (!string.IsNullOrEmpty(path) && File.Exists(path))
|
||
{
|
||
File.WriteAllText(path, json);
|
||
}else
|
||
{
|
||
UnityEngine.Debug.Log("未找到目标路径:"+path);
|
||
}
|
||
}
|
||
|
||
// 加载version目录
|
||
private static void LoadDic()
|
||
{
|
||
//if (!string.IsNullOrEmpty(versionPath) && Directory.Exists(versionPath))
|
||
//{
|
||
ClientConfigManager.Instance.SVN_Update();
|
||
m_Files = ClientConfigManager.Instance.GetVersionList();//Directory.GetFiles(versionPath, "*.txt", SearchOption.AllDirectories);
|
||
m_Choose = new bool[m_Files.Length];
|
||
//}
|
||
}
|
||
void OnGUI()
|
||
{
|
||
|
||
EditorGUILayout.BeginVertical();
|
||
EditorGUILayout.LabelField("version文件配置:");
|
||
EditorGUILayout.Space();
|
||
EditorGUILayout.LabelField("登录服地址:");
|
||
m_VersionTxt.serverUrl = EditorGUILayout.TextField("", m_VersionTxt.serverUrl);
|
||
EditorGUILayout.LabelField("热更CDN地址:");
|
||
m_VersionTxt.resUrl = EditorGUILayout.TextField("", m_VersionTxt.resUrl);
|
||
EditorGUILayout.LabelField("渠道:");
|
||
m_VersionTxt.channel = EditorGUILayout.TextField("", m_VersionTxt.channel);
|
||
EditorGUILayout.LabelField("子渠道:");
|
||
m_VersionTxt.subChannel = EditorGUILayout.TextField("", m_VersionTxt.subChannel);
|
||
EditorGUILayout.LabelField("包版本号:");
|
||
m_VersionTxt.packageVersion = EditorGUILayout.TextField("", m_VersionTxt.packageVersion);
|
||
EditorGUILayout.LabelField("热更版本号:");
|
||
m_VersionTxt.version = EditorGUILayout.TextField("", m_VersionTxt.version);
|
||
//EditorGUILayout.LabelField("公告:");
|
||
//m_VersionTxt.noticeChannel = EditorGUILayout.TextField("", m_VersionTxt.noticeChannel);
|
||
EditorGUILayout.EndVertical();
|
||
|
||
if (GUILayout.Button("应用", GUILayout.Height(40f)))
|
||
{
|
||
SaveToEditorPath();
|
||
UnityEngine.Debug.Log("应用成功");
|
||
}
|
||
EditorGUILayout.BeginVertical();
|
||
EditorGUILayout.Space();
|
||
EditorGUILayout.LabelField("请选择要使用的version文件:");
|
||
if (m_Files != null && m_Files.Length != 0)
|
||
{
|
||
for (int i = 0; i < m_Files.Length; i++)
|
||
{
|
||
m_Choose[i] = EditorGUILayout.ToggleLeft(Path.GetFileNameWithoutExtension(m_Files[i]), m_Choose[i]);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
EditorGUILayout.LabelField("未找到分支");
|
||
}
|
||
EditorGUILayout.EndVertical();
|
||
|
||
if (GUILayout.Button("使用选中的version文件", GUILayout.Height(40f)))
|
||
{
|
||
for (int i = 0; i < m_Files.Length; i++)
|
||
{
|
||
if (m_Choose[i])
|
||
{
|
||
LoadVersion(m_Files[i]);
|
||
UnityEngine.Debug.Log("使用成功");
|
||
return;
|
||
}
|
||
}
|
||
UnityEngine.Debug.Log("未找到可用的version");
|
||
}
|
||
|
||
|
||
if (GUILayout.Button("保存到打包路径", GUILayout.Height(40f)))
|
||
{
|
||
SaveToBuildPath();
|
||
UnityEngine.Debug.Log("保存成功");
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|