Skip to content

Commit

Permalink
Fixed nullpointer exception when rendering behavior in inspector from…
Browse files Browse the repository at this point in the history
… prefab & shortened the "VRCFury Material for " to VRCF on renamed materials
  • Loading branch information
bigibas123 committed Jul 22, 2024
1 parent ac69b47 commit 2265c58
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
30 changes: 25 additions & 5 deletions Editor/Model/DeduplicatedMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ namespace cc.dingemans.bigibas123.MaterialDedup.Editor.Model
{
public class DeduplicatedMaterial : MaterialContainer
{
private string _prefix = "Dedup:";
private static readonly string _prefix = "Dedup:";

private static readonly (string find, string replace)[] _subStringReplacements =
{ ("VRCFury Material for ", "VRCF") };

private List<MaterialTarget> _destinations;
public ImmutableList<MaterialTarget> Destinations => _destinations.ToImmutableList();
public int DestinationCount => _destinations.Count;

private Material _material;
[CanBeNull] private string _destName;

Expand All @@ -29,16 +33,32 @@ public override string Name
{
get
{
return _destName ??= $"{_prefix}{string.Join(";", _destinations.Select((matRef) => matRef.Name))}";
if (_destName == null)
{
IEnumerable<string> matNames = _destinations
.Select(matRef => matRef.Name)
.Select(name =>
_subStringReplacements
.Aggregate(name,
(current, tup) =>
current
.Replace(tup.find, tup.replace)
)
)
;
_destName = $"{_prefix}{string.Join(";", matNames)}";
}

return _destName;
}
}

public DeduplicatedMaterial(Material sourceMaterial)
{
_destinations = new List<MaterialTarget>();
_material = new Material(sourceMaterial);
}

public void AddRefForReplacement(MaterialTarget avatarMat)
{
_destinations.Add(avatarMat);
Expand Down
2 changes: 0 additions & 2 deletions Editor/Model/RendererMaterialReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public override TargetType Type

private Renderer _renderer;


[CanBeNull]
private Renderer Renderer
{
get => _renderer;
Expand Down
6 changes: 3 additions & 3 deletions Editor/VRCAvatarDescriptorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public static class VRCAvatarDescriptorExtensions
{
public static IEnumerable<MaterialTarget> GetMaterialTargetFromAnimationLayers(this VRCAvatarDescriptor descriptor)
{
return descriptor.baseAnimationLayers.GetAnimationControllers()
.Concat(descriptor.specialAnimationLayers.GetAnimationControllers())
.SelectMany(cont => cont.GetAllMaterialRefrences());
return descriptor?.baseAnimationLayers?.GetAnimationControllers()
.Concat(descriptor?.specialAnimationLayers?.GetAnimationControllers())
.SelectMany(cont => cont.GetAllMaterialRefrences()) ?? new List<MaterialTarget>();
}

public static IEnumerable<MaterialTarget> GetAllMaterialRefrences(this RuntimeAnimatorController cont)
Expand Down

0 comments on commit 2265c58

Please sign in to comment.