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>();
|
||||
|
@@ -10,7 +10,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
|
||||
public override int Priority { get { return -50; } }
|
||||
|
||||
static readonly Dictionary<string, int> _rulesetTabs = new Dictionary<string, int>();
|
||||
static readonly Dictionary<string, int> _rulesetTabs = new();
|
||||
|
||||
public override bool CanInvoke(Uri uri, IChartDetail resource) {
|
||||
return true;
|
||||
@@ -20,15 +20,13 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
}
|
||||
|
||||
public static bool HasTab(string ruleset) {
|
||||
int tabId;
|
||||
var master = ResourceBrowserMaster.Instance;
|
||||
if (master == null) return false;
|
||||
return _rulesetTabs.TryGetValue(ruleset, out tabId) && master.HasTab(tabId);
|
||||
return _rulesetTabs.TryGetValue(ruleset, out int tabId) && master.HasTab(tabId);
|
||||
}
|
||||
public static void Invoke(string ruleset, Action<RulesetConfig> overrides = null) {
|
||||
var master = ResourceBrowserMaster.Instance;
|
||||
int tabId;
|
||||
if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId))
|
||||
if (_rulesetTabs.TryGetValue(ruleset, out int tabId) && master.TryOpenTab(tabId))
|
||||
return;
|
||||
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent<RulesetConfigBrowser>();
|
||||
try {
|
||||
|
@@ -8,15 +8,15 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
public abstract bool CanInvoke(Uri uri, T resource);
|
||||
public bool CanInvoke(Uri uri, IResourceMeta resource) {
|
||||
if (resource == null) throw new ArgumentNullException("resource");
|
||||
if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
|
||||
return CanInvoke(uri, (T)resource);
|
||||
if (resource is not T res) throw new ArgumentException("Mismatched resource type.");
|
||||
return CanInvoke(uri, res);
|
||||
}
|
||||
|
||||
public abstract void Invoke(Uri uri, T resource);
|
||||
public void Invoke(Uri uri, IResourceMeta resource) {
|
||||
if (resource == null) throw new ArgumentNullException("resource");
|
||||
if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
|
||||
Invoke(uri, (T)resource);
|
||||
if (resource is not T res) throw new ArgumentException("Mismatched resource type.");
|
||||
Invoke(uri, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user