Skip to content

Commit

Permalink
chore: Directly set to PrefabSafeSet in InternalAutoFreezeMeaningless…
Browse files Browse the repository at this point in the history
…BlendShapeProcessor
  • Loading branch information
anatawa12 committed Oct 3, 2023
1 parent 3ee84c5 commit 92fc1a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ public override void Process(BuildContext context, MeshInfo2 target)
meaningfulBlendShapes.UnionWith(vertex.BlendShapes.Keys);

var freezeBlendShape = Target.GetComponent<FreezeBlendShape>();
var serialized = new SerializedObject(freezeBlendShape);
var editorUtil = PrefabSafeSet.EditorUtil<string>.Create(
serialized.FindProperty(nameof(FreezeBlendShape.shapeKeysSet)),
0, p => p.stringValue, (p, v) => p.stringValue = v);
foreach (var (meaningLess, _) in target.BlendShapes.Where(x => !meaningfulBlendShapes.Contains(x.name)))
editorUtil.GetElementOf(meaningLess).EnsureAdded();
serialized.ApplyModifiedPropertiesWithoutUndo();
var set = freezeBlendShape.shapeKeysSet.GetAsSet();
set.UnionWith(target.BlendShapes.Where(x => !meaningfulBlendShapes.Contains(x.name)).Select(x => x.name));
freezeBlendShape.shapeKeysSet.SetValueNonPrefab(set);
}

// nothing to do
Expand Down
11 changes: 11 additions & 0 deletions Internal/PrefabSafeSet/Runtime/PrefabSafeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ protected PrefabSafeSet(Object outerObject)
#endif
}

public void SetValueNonPrefab(IEnumerable<T> values)
{
#if UNITY_EDITOR
if (OuterObject && UnityEditor.PrefabUtility.IsPartOfPrefabInstance(OuterObject)
&& UnityEditor.PrefabUtility.IsPartOfAnyPrefab(OuterObject))
throw new InvalidOperationException("You cannot set value to Prefab Instance or Prefab");
Debug.Assert(prefabLayers.Length == 0);
#endif
mainSet = values.ToArray();
}

public HashSet<T> GetAsSet()
{
var result = new HashSet<T>(mainSet.Where(x => x.IsNotNull()));
Expand Down

0 comments on commit 92fc1a6

Please sign in to comment.