Unity21版本打包报错OBSOLETE - Providing Android resources in Assets/Plugins/Android/res
assets
Ultralytics assets
项目地址:https://gitcode.com/gh_mirrors/ass/assets
免费下载资源
·
原因是从新版本2021.2已经不允许直接把res文件放在Plugins/Android目录下了
* 新建一个AndroidPluginsUpgrader.cs
塞入下列代码
放入 Assets/Editor 文件夹
* 重启编辑器
* 打开项目
* 如果您有 Assets/Plugins/Android/<res, assets> 文件夹
,您会看到一个询问升级的对话框
* 基本上 Unity 会移动
Assets/Plugins/Android/<res,assets> -> Assets/Plugins/Android/<res, assets>-legacy
并在导出/构建时移动将手动将 Assets/Plugins/Android/<res, assets>-legacy
复制到 unityLibrary/src/main/<res, assets> 文件夹(不包括 .meta 文件)
#if UNITY_2021_2_OR_NEWER
using System;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Android;
using System.Text;
public class AndroidPluginsUpgraderfPostprocessor : IPostGenerateGradleAndroidProject
{
internal static readonly string PluginsAndroid = "Assets/Plugins/Android";
class UpgradableItem
{
public string Name { get; }
public string Path { get; }
public string LegacyDirectory { get; }
public string LegacyPath { get; }
public UpgradableItem(string directory, string legacyDirectory)
{
Name = directory;
Path = $"{PluginsAndroid}/{directory}";
LegacyDirectory = legacyDirectory;
LegacyPath = $"{PluginsAndroid}/{LegacyDirectory}";
}
}
static readonly string AskAboutUpgradeFolders = nameof(AskAboutUpgradeFolders);
static readonly UpgradableItem[] UpgradableItems = new []
{
new UpgradableItem("res", "res-legacy"),
new UpgradableItem("assets", "assets-legacy")
};
[InitializeOnLoadMethod]
public static void ValidateResFolder()
{
if (!SessionState.GetBool(AskAboutUpgradeFolders, true))
return;
bool upgradableItemsExist = UpgradableItems.Any(s => Directory.Exists(s.Path));
if (!upgradableItemsExist)
return;
var ugpradePaths = new StringBuilder();
foreach (var u in UpgradableItems)
{
ugpradePaths.AppendLine($"'{u.Path}' will be moved into '{u.LegacyPath}')");
}
var result = EditorUtility.DisplayDialog($"Upgrade {PluginsAndroid} folder ? ",
$@"Starting Unity 2021.2 {PluginsAndroid} folder can no longer be used for copying '{string.Join(", ", UpgradableItems.Select(u => u.Name))}' files to gradle project, this has to be done either via android plugins or manually.
Proceed with upgrade?
{ugpradePaths}",
"Yes",
"No and don't ask again in this Editor session");
if (!result)
{
SessionState.SetBool(AskAboutUpgradeFolders, false);
return;
}
foreach (var u in UpgradableItems)
{
if (!Directory.Exists(u.Path))
continue;
if (Directory.Exists(u.LegacyPath))
{
EditorUtility.DisplayDialog(
"Upgrade failed",
@$"Cannot upgrade since '{u.LegacyPath}' already exists, delete it.
or manually merge '{u.Path}' into '{u.LegacyPath}'
and delete '{u.Path}'.
Restart Editor afterwards.",
"Ok");
return;
}
AssetDatabase.RenameAsset(u.Path, u.LegacyDirectory);
}
}
public static void Log(string message)
{
UnityEngine.Debug.LogFormat(UnityEngine.LogType.Log, UnityEngine.LogOption.NoStacktrace, null, message);
}
public int callbackOrder { get { return 0; } }
public void OnPostGenerateGradleAndroidProject(string path)
{
foreach (var u in UpgradableItems)
{
if (!Directory.Exists(u.LegacyPath))
continue;
var destination = Path.Combine(path, $"src/main/{u.Name}").Replace("\\", "/");
var log = new StringBuilder();
log.AppendLine("Legacy Android res files copying");
log.AppendLine($"Copying '{u.LegacyPath}' -> '{destination}':");
RecursiveCopy(new DirectoryInfo(u.LegacyPath),
new DirectoryInfo(destination),
new[] { ".meta" },
log);
Log(log.ToString());
}
}
private static void RecursiveCopy(DirectoryInfo source, DirectoryInfo target, string[] ignoredExtensions, StringBuilder log)
{
if (Directory.Exists(target.FullName) == false)
Directory.CreateDirectory(target.FullName);
foreach (FileInfo fi in source.GetFiles())
{
if (ignoredExtensions.Contains(fi.Extension))
continue;
var destination = Path.Combine(target.ToString(), fi.Name);
log.AppendLine($" {fi.FullName} -> {destination}");
fi.CopyTo(destination, true);
}
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
RecursiveCopy(diSourceSubDir, nextTargetSubDir, ignoredExtensions, log);
}
}
}
#endif
GitHub 加速计划 / ass / assets
13
1
下载
Ultralytics assets
最近提交(Master分支:4 个月前 )
c02308fb
1 个月前
8b91060e
Co-authored-by: UltralyticsAssistant <web@ultralytics.com> 1 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)