using System; using System.Collections.Generic; using System.Diagnostics; namespace CaoCao.Editor { public interface IBuildJobStep { void Start(BuildJob job); } public class BuildJob { public readonly List bundledAssets = new List(); public readonly List bundles = new List(); public readonly List changes = new List(); public readonly List rawAssets = new List(); public string error { get; set; } public BuildJob(BuildParameters buildParameters) { parameters = buildParameters; } public BuildParameters parameters { get; } public void AddAsset(BuildAsset asset) { if (asset.group.bundleMode == BundleMode.PackByRaw) rawAssets.Add(asset); else bundledAssets.Add(asset); } public static BuildJob StartNew(BuildParameters parameters, params IBuildJobStep[] steps) { var task = new BuildJob(parameters); task.Start(steps); return task; } public void Start(params IBuildJobStep[] steps) { foreach (var step in steps) { var sw = new Stopwatch(); sw.Start(); try { step.Start(this); } catch (Exception e) { XAsset.Logger.E($"{e.Message}:{e.StackTrace}"); error = e.Message; } sw.Stop(); if (!string.IsNullOrEmpty(error)) { XAsset.Logger.I($"{step.GetType().Name} for {parameters.name} failed({error}) with {sw.ElapsedMilliseconds / 1000f}s."); break; } XAsset.Logger.I($"{step.GetType().Name} for {parameters.name} success with {sw.ElapsedMilliseconds / 1000f}s."); } } public void TreatError(string e) { error = e; XAsset.Logger.E($"{error}"); } } }