fix: some issues with reactive objects not triggering pipeline refreshes (#1057)

Closes: #1054
This commit is contained in:
bd_ 2024-08-28 19:20:17 -07:00 committed by GitHub
parent f514a5e904
commit 369cc010c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 6 deletions

View File

@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using nadena.dev.modular_avatar.animation;
using nadena.dev.ndmf.preview; using nadena.dev.ndmf.preview;
using UnityEngine; using UnityEngine;
@ -17,7 +16,7 @@ namespace nadena.dev.modular_avatar.core.editor
return rule; return rule;
} }
private ReactionRule ObjectRule(TargetProp key, Component controllingObject, UnityEngine.Object value) private ReactionRule ObjectRule(TargetProp key, Component controllingObject, Object value)
{ {
var rule = new ReactionRule(key, value); var rule = new ReactionRule(key, value);
@ -162,13 +161,14 @@ namespace nadena.dev.modular_avatar.core.editor
private void FindMaterialSetters(Dictionary<TargetProp, AnimatedProperty> objectGroups, GameObject root) private void FindMaterialSetters(Dictionary<TargetProp, AnimatedProperty> objectGroups, GameObject root)
{ {
var materialSetters = root.GetComponentsInChildren<ModularAvatarMaterialSetter>(true); var materialSetters = _computeContext.GetComponentsInChildren<ModularAvatarMaterialSetter>(root, true);
foreach (var setter in materialSetters) foreach (var setter in materialSetters)
{ {
if (setter.Objects == null) continue; if (setter.Objects == null) continue;
foreach (var obj in _computeContext.Observe(setter, c => c.Objects.ToList(), Enumerable.SequenceEqual)) foreach (var obj in _computeContext.Observe(setter, c => c.Objects.Select(o => o.Clone()).ToList(),
Enumerable.SequenceEqual))
{ {
var renderer = _computeContext.GetComponent<Renderer>(obj.Object.Get(setter)); var renderer = _computeContext.GetComponent<Renderer>(obj.Object.Get(setter));
if (renderer == null || renderer.sharedMaterials.Length < obj.MaterialIndex) continue; if (renderer == null || renderer.sharedMaterials.Length < obj.MaterialIndex) continue;
@ -197,13 +197,14 @@ namespace nadena.dev.modular_avatar.core.editor
private void FindObjectToggles(Dictionary<TargetProp, AnimatedProperty> objectGroups, GameObject root) private void FindObjectToggles(Dictionary<TargetProp, AnimatedProperty> objectGroups, GameObject root)
{ {
var toggles = root.GetComponentsInChildren<ModularAvatarObjectToggle>(true); var toggles = _computeContext.GetComponentsInChildren<ModularAvatarObjectToggle>(root, true);
foreach (var toggle in toggles) foreach (var toggle in toggles)
{ {
if (toggle.Objects == null) continue; if (toggle.Objects == null) continue;
foreach (var obj in _computeContext.Observe(toggle, c => c.Objects.ToList(), Enumerable.SequenceEqual)) foreach (var obj in _computeContext.Observe(toggle, c => c.Objects.Select(o => o.Clone()).ToList(),
Enumerable.SequenceEqual))
{ {
var target = obj.Object.Get(toggle); var target = obj.Object.Get(toggle);
if (target == null) continue; if (target == null) continue;

View File

@ -11,6 +11,16 @@ namespace nadena.dev.modular_avatar.core
public Material Material; public Material Material;
public int MaterialIndex; public int MaterialIndex;
public MaterialSwitchObject Clone()
{
return new MaterialSwitchObject
{
Object = Object.Clone(),
Material = Material,
MaterialIndex = MaterialIndex
};
}
public bool Equals(MaterialSwitchObject other) public bool Equals(MaterialSwitchObject other)
{ {
return Equals(Object, other.Object) && Equals(Material, other.Material) && MaterialIndex == other.MaterialIndex; return Equals(Object, other.Object) && Equals(Material, other.Material) && MaterialIndex == other.MaterialIndex;

View File

@ -9,6 +9,15 @@ namespace nadena.dev.modular_avatar.core
{ {
public AvatarObjectReference Object; public AvatarObjectReference Object;
public bool Active; public bool Active;
public ToggledObject Clone()
{
return new ToggledObject
{
Object = Object.Clone(),
Active = Active
};
}
} }
[AddComponentMenu("Modular Avatar/MA Object Toggle")] [AddComponentMenu("Modular Avatar/MA Object Toggle")]