Version: 2023.2
Method group is Obsolete

切换到手册

描述

This class reports progress when you start a task with Progress.RunTask(...).

[MenuItem("Progress/Run Task 1 (MD5 all assets)", priority = 25)]
static void RunTask1()
{
    Progress.RunTask("Compute MD5", null, (id, data) => EnumerateMD5());
}

static string CalculateMD5(string filename) { using (var md5 = MD5.Create()) { using (var stream = File.OpenRead(filename)) { var hash = md5.ComputeHash(stream); return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } } }

private static IEnumerator EnumerateMD5() { var assets = AssetDatabase.GetAllAssetPaths(); var index = 0; foreach (var assetPath in assets) { if (Directory.Exists(assetPath)) continue; // Do some calculations with the asset. var md5 = CalculateMD5(assetPath); yield return new Progress.TaskReport(index++ / (float)assets.Length, md5); } }

See Also: Progress.Progress.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961