diff --git a/Editor/API-Proposal/ComponentInformation.cs b/Editor/API-Proposal/ComponentInformation.cs index 45d4f50c1..b46285241 100644 --- a/Editor/API-Proposal/ComponentInformation.cs +++ b/Editor/API-Proposal/ComponentInformation.cs @@ -33,8 +33,6 @@ public interface IComponentDependencyInfo { IComponentDependencyInfo EvenIfDependantDisabled(); IComponentDependencyInfo OnlyIfTargetCanBeEnable(); - - IComponentDependencyInfo AsBone(); } public interface IComponentMutationsCollector diff --git a/Editor/APIBackend/ComponentInfos.cs b/Editor/APIBackend/ComponentInfos.cs index 1cedbe673..c7e59ad9f 100644 --- a/Editor/APIBackend/ComponentInfos.cs +++ b/Editor/APIBackend/ComponentInfos.cs @@ -100,7 +100,7 @@ protected override void CollectDependency(SkinnedMeshRenderer component, var meshInfo2 = casted.MeshInfo2Holder.GetMeshInfoFor(component); foreach (var bone in meshInfo2.Bones) - collector.AddDependency(bone.Transform).AsBone(); + casted.AddBoneDependency(bone.Transform); collector.AddDependency(meshInfo2.RootBone); } } diff --git a/Editor/Processors/TraceAndOptimize/ComponentDependencyCollector.cs b/Editor/Processors/TraceAndOptimize/ComponentDependencyCollector.cs index ee76ab1c1..e0a5b0121 100644 --- a/Editor/Processors/TraceAndOptimize/ComponentDependencyCollector.cs +++ b/Editor/Processors/TraceAndOptimize/ComponentDependencyCollector.cs @@ -63,13 +63,18 @@ public IComponentDependencyInfo AddDependency(Component component) { if (!component) return EmptyComponentDependencyInfo.Instance; - return new ComponentDependencyInfo(_dependencies, component); + return new ComponentDependencyInfo(_dependencies, component).SetFlags(); } public void AddParentDependency(Transform component) { var parent = component.parent; - if (parent) new ComponentDependencyInfo(_dependencies, parent).AsParent(); + if (parent) new ComponentDependencyInfo(_dependencies, parent, DependencyType.Parent).SetFlags(); + } + + public void AddBoneDependency(Transform bone) + { + if (bone) new ComponentDependencyInfo(_dependencies, bone, DependencyType.Bone).SetFlags(); } class EmptyComponentDependencyInfo : IComponentDependencyInfo @@ -82,36 +87,36 @@ private EmptyComponentDependencyInfo() public IComponentDependencyInfo EvenIfDependantDisabled() => this; public IComponentDependencyInfo OnlyIfTargetCanBeEnable() => this; - public IComponentDependencyInfo AsBone() => this; } - class ComponentDependencyInfo : IComponentDependencyInfo + private struct ComponentDependencyInfo : IComponentDependencyInfo { [NotNull] private readonly Dictionary _dependencies; private readonly Component _component; private readonly DependencyFlags _prevFlags; - private readonly DependencyType _prevTypes; private DependencyFlags _flags; - private DependencyType _type; + private readonly DependencyType _types; public ComponentDependencyInfo( [NotNull] Dictionary dependencies, - [NotNull] Component component) + [NotNull] Component component, + DependencyType type = DependencyType.Normal) { _dependencies = dependencies; _component = component; _dependencies.TryGetValue(component, out var pair); _prevFlags = pair.Item1; - _prevTypes = pair.Item2; _flags = DependencyFlags.EvenIfTargetIsDisabled; - _type = DependencyType.Normal; - - SetFlags(); + _types = pair.Item2 | type; } - private void SetFlags() => _dependencies[_component] = (_prevFlags | _flags, _prevTypes | _type); + internal ComponentDependencyInfo SetFlags() + { + _dependencies[_component] = (_prevFlags | _flags, _types); + return this; + } public IComponentDependencyInfo EvenIfDependantDisabled() { @@ -126,19 +131,6 @@ public IComponentDependencyInfo OnlyIfTargetCanBeEnable() SetFlags(); return this; } - - public IComponentDependencyInfo AsBone() - { - _type = DependencyType.Bone; - SetFlags(); - return this; - } - - public void AsParent() - { - _type = DependencyType.Parent; - SetFlags(); - } } } @@ -225,10 +217,8 @@ public IComponentDependencyInfo AddDependency(Component dependant, Component dep _collector.GetDependencies(dependant).AddDependency(dependency); public IComponentDependencyInfo AddDependency(Component dependency) => _deps.AddDependency(dependency); - public void AddParentDependency(Transform component) - { - _deps.AddParentDependency(component); - } + public void AddParentDependency(Transform component) => _deps.AddParentDependency(component); + public void AddBoneDependency(Transform bone) => _deps.AddBoneDependency(bone); } } }