diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs index ea7b4fd6..76ff96e5 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using nadena.dev.modular_avatar.animation; using nadena.dev.ndmf.preview; using UnityEngine; @@ -17,7 +16,7 @@ namespace nadena.dev.modular_avatar.core.editor 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); @@ -162,13 +161,14 @@ namespace nadena.dev.modular_avatar.core.editor private void FindMaterialSetters(Dictionary objectGroups, GameObject root) { - var materialSetters = root.GetComponentsInChildren(true); + var materialSetters = _computeContext.GetComponentsInChildren(root, true); foreach (var setter in materialSetters) { 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(obj.Object.Get(setter)); if (renderer == null || renderer.sharedMaterials.Length < obj.MaterialIndex) continue; @@ -197,13 +197,14 @@ namespace nadena.dev.modular_avatar.core.editor private void FindObjectToggles(Dictionary objectGroups, GameObject root) { - var toggles = root.GetComponentsInChildren(true); + var toggles = _computeContext.GetComponentsInChildren(root, true); foreach (var toggle in toggles) { 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); if (target == null) continue; diff --git a/Runtime/ReactiveObjects/ModularAvatarMaterialSetter.cs b/Runtime/ReactiveObjects/ModularAvatarMaterialSetter.cs index a6b949c2..28f4f9c0 100644 --- a/Runtime/ReactiveObjects/ModularAvatarMaterialSetter.cs +++ b/Runtime/ReactiveObjects/ModularAvatarMaterialSetter.cs @@ -11,6 +11,16 @@ namespace nadena.dev.modular_avatar.core public Material Material; public int MaterialIndex; + public MaterialSwitchObject Clone() + { + return new MaterialSwitchObject + { + Object = Object.Clone(), + Material = Material, + MaterialIndex = MaterialIndex + }; + } + public bool Equals(MaterialSwitchObject other) { return Equals(Object, other.Object) && Equals(Material, other.Material) && MaterialIndex == other.MaterialIndex; diff --git a/Runtime/ReactiveObjects/ModularAvatarObjectToggle.cs b/Runtime/ReactiveObjects/ModularAvatarObjectToggle.cs index 9756ea92..a105ed63 100644 --- a/Runtime/ReactiveObjects/ModularAvatarObjectToggle.cs +++ b/Runtime/ReactiveObjects/ModularAvatarObjectToggle.cs @@ -9,6 +9,15 @@ namespace nadena.dev.modular_avatar.core { public AvatarObjectReference Object; public bool Active; + + public ToggledObject Clone() + { + return new ToggledObject + { + Object = Object.Clone(), + Active = Active + }; + } } [AddComponentMenu("Modular Avatar/MA Object Toggle")]