refactor: Update Unity to 2022.3.62
This commit is contained in:
@@ -4,28 +4,27 @@ using System.Linq;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.Actions {
|
||||
public class ActionManager {
|
||||
readonly Dictionary<Type, List<IResourceAction>> _actions = new Dictionary<Type, List<IResourceAction>>();
|
||||
readonly Dictionary<IResourceAction, int> _refCounts = new Dictionary<IResourceAction, int>();
|
||||
readonly Dictionary<Type, List<IResourceAction>> _actions = new();
|
||||
readonly Dictionary<IResourceAction, int> _refCounts = new();
|
||||
|
||||
public event Action Changed;
|
||||
|
||||
class ActionPriorityComparer : IComparer<IResourceAction> {
|
||||
public static readonly ActionPriorityComparer Instance = new ActionPriorityComparer();
|
||||
public static readonly ActionPriorityComparer Instance = new();
|
||||
public int Compare(IResourceAction x, IResourceAction y) {
|
||||
return x.Priority.CompareTo(y.Priority);
|
||||
}
|
||||
}
|
||||
|
||||
void Register(Type type, IResourceAction action) {
|
||||
List<IResourceAction> actions;
|
||||
if (!_actions.TryGetValue(type, out actions)) {
|
||||
if (!_actions.TryGetValue(type, out List<IResourceAction> actions)) {
|
||||
_actions.Add(type, actions = new List<IResourceAction>());
|
||||
}
|
||||
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
|
||||
if (index < 0) index = ~index;
|
||||
actions.Insert(index, action);
|
||||
if (_refCounts.ContainsKey(action)) _refCounts[action]++;
|
||||
else _refCounts[action] = 0;
|
||||
else _refCounts[action] = 1;
|
||||
Changed?.Invoke();
|
||||
}
|
||||
public void Register(IResourceAction action) {
|
||||
@@ -36,8 +35,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
}
|
||||
|
||||
public void Unregister(Type type, IResourceAction action) {
|
||||
List<IResourceAction> actions;
|
||||
if (!_actions.TryGetValue(type, out actions)) return;
|
||||
if (!_actions.TryGetValue(type, out List<IResourceAction> actions)) return;
|
||||
if (--_refCounts[action] > 0) return;
|
||||
actions.Remove(action);
|
||||
Changed?.Invoke();
|
||||
@@ -54,9 +52,8 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
}
|
||||
IEnumerable<IResourceAction> GetActions(Uri uri, IResourceMeta res, Type type) {
|
||||
if (type == null) return Enumerable.Empty<IResourceAction>();
|
||||
List<IResourceAction> actions;
|
||||
IEnumerable<IResourceAction> result;
|
||||
if (_actions.TryGetValue(type, out actions))
|
||||
if (_actions.TryGetValue(type, out List<IResourceAction> actions))
|
||||
result = actions.Where(i => i.CanInvoke(uri, res));
|
||||
else
|
||||
result = Enumerable.Empty<IResourceAction>();
|
||||
|
Reference in New Issue
Block a user