diff --git a/Assets/YooAsset/Runtime/OperationSystem/OperationScheduler.cs b/Assets/YooAsset/Runtime/OperationSystem/OperationScheduler.cs index cef60108..cabfe18e 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/OperationScheduler.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/OperationScheduler.cs @@ -10,6 +10,7 @@ namespace YooAsset { private readonly List _operations = new List(100); private readonly List _newList = new List(100); + private uint _priority = 0; /// /// 所属包裹名称 @@ -19,7 +20,23 @@ namespace YooAsset /// /// 调度器优先级(值越大越优先) /// - public int Priority { private set; get; } + public uint Priority + { + get { return _priority; } + set + { + if (_priority != value) + { + _priority = value; + IsDirty = true; + } + } + } + + /// + /// 优先级是否已变更(需要重新排序) + /// + public bool IsDirty { set; get; } = false; /// /// 创建顺序(用于同优先级稳定排序) @@ -27,7 +44,7 @@ namespace YooAsset public int CreateIndex { private set; get; } - public OperationScheduler(string packageName, int priority, int createIndex) + public OperationScheduler(string packageName, uint priority, int createIndex) { PackageName = packageName; Priority = priority; diff --git a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs index e72de0df..ac2709f3 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs @@ -21,7 +21,6 @@ namespace YooAsset private static readonly Dictionary _schedulerDic = new Dictionary(100); private static readonly List _schedulerList = new List(100); private static bool _isInitialize = false; - private static bool _schedulerListDirty = false; private static int _createIndex = 0; // 计时器相关 @@ -75,10 +74,18 @@ namespace YooAsset if (_isInitialize == false) return; - // 重新排序调度器 - if (_schedulerListDirty) + // 检测是否需要执行排序 + bool isDirty = false; + foreach (var scheduler in _schedulerList) + { + if (scheduler.IsDirty) + { + scheduler.IsDirty = false; + isDirty = true; + } + } + if (isDirty) { - _schedulerListDirty = false; _schedulerList.Sort(); } @@ -110,7 +117,6 @@ namespace YooAsset } _schedulerDic.Clear(); _schedulerList.Clear(); - _schedulerListDirty = false; _createIndex = 0; _watch = null; @@ -121,7 +127,7 @@ namespace YooAsset /// /// 创建包裹调度器 /// - public static void CreatePackageScheduler(string packageName, int priority) + public static OperationScheduler CreatePackageScheduler(string packageName, uint priority) { DebugCheckInitialize(packageName); @@ -133,7 +139,7 @@ namespace YooAsset var scheduler = new OperationScheduler(packageName, priority, _createIndex++); _schedulerDic.Add(packageName, scheduler); _schedulerList.Add(scheduler); - _schedulerListDirty = true; + return scheduler; } /// @@ -179,6 +185,28 @@ namespace YooAsset scheduler.StartOperation(operation); } + /// + /// 设置调度器优先级 + /// + public static void SetSchedulerPriority(string packageName, uint priority) + { + DebugCheckInitialize(packageName); + + var scheduler = GetScheduler(packageName); + scheduler.Priority = priority; + } + + /// + /// 获取调度器优先级 + /// + public static uint GetSchedulerPriority(string packageName) + { + DebugCheckInitialize(packageName); + + var scheduler = GetScheduler(packageName); + return scheduler.Priority; + } + /// /// 获取调度器(严格模式) /// diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index bb07e1f5..e48a6dbd 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -44,6 +44,15 @@ namespace YooAsset } } + /// + /// 包裹优先级(值越大越优先更新) + /// + public uint PackagePriority + { + get { return OperationSystem.GetSchedulerPriority(PackageName); } + set { OperationSystem.SetSchedulerPriority(PackageName, value); } + } + internal ResourcePackage(string packageName) { diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 1e199266..eee3a65d 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -112,7 +112,7 @@ namespace YooAsset /// /// 包裹名称 /// 包裹优先级(值越大越优先更新) - public static ResourcePackage CreatePackage(string packageName, int packagePriority) + public static ResourcePackage CreatePackage(string packageName, uint packagePriority) { CheckException(packageName); if (ContainsPackage(packageName))