using CaoCao.XAsset;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace CaoCao.Editor
{
public enum PlayerAssetsSplitMode
{
SplitByAssetPacksWithInstallTime,
IncludeAllAssets,
ExcludeAllAssets
}
[CreateAssetMenu(fileName = nameof(Settings), menuName = "CaoCao/XAsset/" + nameof(Settings))]
public class Settings : ScriptableObject
{
[Header("Player")] public string downloadURL = "http://127.0.0.1/";
[Tooltip("大版本号,不一样则需要下载新包")]
public int BigVersion = 0;
[Tooltip("安装包资源分离模式: \n" +
"Split By Asset Packs With Install Time:安装包中只包含交付模式为 Install Time 的 Asset Packs 中的资源。 \n" +
"Include All Assets 安装包中包含所有资源。 \n" +
"Exclude All Assets 安装包中不包含资源。")]
public PlayerAssetsSplitMode playerAssetsSplitMode = PlayerAssetsSplitMode.IncludeAllAssets;
///
/// 是否将安装包内的资源二次打包,Android 设备上开启这个选项可以优化 IO 效率。
///
[Tooltip("是否为 AssetPack 配置中的资源生成实体文件")]
public bool packPlayerAssets = true;
///
/// 离线模式,运行时有效,开启后不会触发更新。
///
[Tooltip("离线模式,运行时有效,开启后不会触发更新")]
public bool offlineMode;
///
/// 查找依赖引用输出的文件名
///
[Tooltip("查找依赖引用输出的文件名")]
public string findReferencesInBuildPath = "FindReferencesInBuild.txt";
///
/// 打包 bundle 的设置
///
public BundleSettings bundle = new BundleSettings();
///
/// 编辑器仿真模式,开启后,无需打包可以进入播放模式。
///
[Header("Development")] public bool simulationMode = true;
///
/// 编辑器下是否开启仿真下载模式,开启后,无需把资源部署到服务器,就行运行真机的更新过程。
///
public bool simulationDownload = true;
///
/// 编辑器仿真模式下,是否采集所有资源,需要更长的初始化耗时,但是可以及时对未采集的内容进行预警。
///
public bool collectAllAssets;
///
/// 最大并行下载数量
///
[Header("Download")] [Range(1, 10)] public byte maxDownloads = 5;
///
/// 最大错误重试次数
///
[Range(0, 5)] public byte maxRetryTimes = 3;
private static string Filename => $"Assets/GameAssets/Config/XAsset/{nameof(Settings)}.asset";
public static BuildGroup GetAutoGroup()
{
return GetOrCreateAsset("Assets/GameAssets/Config/XAsset/Auto.asset", group =>
{
group.bundleMode = BundleMode.PackByFile;
group.addressMode = AddressMode.LoadByDependencies;
});
}
public PlayerAssets GetPlayerAssets()
{
var assets = CreateInstance();
assets.updateInfoURL = $"{downloadURL}{Assets.Bundles}/{Platform}/{UpdateInfo.Filename}";
assets.downloadURL = $"{downloadURL}{Assets.Bundles}/{Platform}";
assets.offlineMode = offlineMode;
assets.packed = packPlayerAssets;
assets.maxDownloads = maxDownloads;
assets.maxRetryTimes = maxRetryTimes;
return assets;
}
public static string PlatformCachePath =>
$"{Environment.CurrentDirectory}/{Assets.Bundles}Cache/{Platform}".Replace('\\', '/');
public static string PlatformDataPath =>
$"{Environment.CurrentDirectory.Replace('\\', '/')}/{Assets.Bundles}/{Platform}";
public static Platform Platform => GetPlatform();
private static Settings defaultSettings;
public static Settings GetDefaultSettings()
{
if (defaultSettings != null)
return defaultSettings;
var assets = FindAssets();
defaultSettings = assets.Length > 0
? assets[0]
: GetOrCreateAsset(Filename);
return defaultSettings;
}
public static void FindReferencesInBuild()
{
var selection = Selection.GetFiltered