-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1008 from anatawa12/merge-1.6
Merge 1.6.13
- Loading branch information
Showing
7 changed files
with
125 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Editor/Processors/TraceAndOptimize/RequireComponentCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using JetBrains.Annotations; | ||
using UnityEngine; | ||
|
||
namespace Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes | ||
{ | ||
internal static class RequireComponentCache | ||
{ | ||
private static Dictionary<Type, HashSet<Type>> _requireComponentCache = new Dictionary<Type, HashSet<Type>>(); | ||
private static Dictionary<Type, HashSet<Type>> _dependantComponentCache = new Dictionary<Type, HashSet<Type>>(); | ||
|
||
[NotNull] | ||
[ItemNotNull] | ||
public static HashSet<Type> GetRequiredComponents([NotNull] Type type) | ||
{ | ||
if (type == null) throw new ArgumentNullException(nameof(type)); | ||
if (_requireComponentCache.TryGetValue(type, out var result)) return result; | ||
|
||
result = new HashSet<Type>(); | ||
|
||
foreach (var requireComponent in type.GetCustomAttributes<RequireComponent>(true)) | ||
{ | ||
if (requireComponent.m_Type0 != null) result.Add(requireComponent.m_Type0); | ||
if (requireComponent.m_Type1 != null) result.Add(requireComponent.m_Type1); | ||
if (requireComponent.m_Type2 != null) result.Add(requireComponent.m_Type2); | ||
} | ||
|
||
// add to dependantComponentCache | ||
foreach (var requiredComponent in result) | ||
{ | ||
if (!_dependantComponentCache.TryGetValue(requiredComponent, out var dependants)) | ||
_dependantComponentCache.Add(requiredComponent, dependants = new HashSet<Type>()); | ||
dependants.Add(type); | ||
} | ||
|
||
_requireComponentCache.Add(type, result); | ||
return result; | ||
} | ||
|
||
[NotNull] | ||
[ItemNotNull] | ||
public static HashSet<Type> GetDependantComponents([NotNull] Type type) | ||
{ | ||
if (type == null) throw new ArgumentNullException(nameof(type)); | ||
if (!_dependantComponentCache.TryGetValue(type, out var result)) | ||
_dependantComponentCache.Add(type, result = new HashSet<Type>()); | ||
return result; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Editor/Processors/TraceAndOptimize/RequireComponentCache.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.