Skip to content

Commit

Permalink
chore: make AsBone internal
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 1, 2023
1 parent e4695c5 commit ff47fc4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
2 changes: 0 additions & 2 deletions Editor/API-Proposal/ComponentInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public interface IComponentDependencyInfo
{
IComponentDependencyInfo EvenIfDependantDisabled();
IComponentDependencyInfo OnlyIfTargetCanBeEnable();

IComponentDependencyInfo AsBone();
}

public interface IComponentMutationsCollector
Expand Down
2 changes: 1 addition & 1 deletion Editor/APIBackend/ComponentInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
48 changes: 19 additions & 29 deletions Editor/Processors/TraceAndOptimize/ComponentDependencyCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Component, (DependencyFlags, DependencyType)> _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<Component, (DependencyFlags, DependencyType)> 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()
{
Expand All @@ -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();
}
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit ff47fc4

Please sign in to comment.