compat/feat: use AvatarObjectReference for action paths

This commit is contained in:
bd_ 2023-04-30 19:55:45 +09:00
parent 47a1e8393c
commit cae4622bfc
4 changed files with 36 additions and 22 deletions

View File

@ -171,7 +171,7 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
if (obj != null && obj.target != null) if (obj != null && obj.target != null)
{ {
currentObjects.Add(obj.target); currentObjects.Add(obj.target.Get(targetObj));
} }
} }
@ -183,7 +183,10 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
objects.Add(new ActionToggleObject.ObjectEntry() objects.Add(new ActionToggleObject.ObjectEntry()
{ {
target = go, target = new AvatarObjectReference()
{
referencePath = RuntimeUtil.AvatarRootPath(go)
},
Active = go.activeSelf Active = go.activeSelf
}); });
} }

View File

@ -14,7 +14,7 @@ namespace nadena.dev.modular_avatar.core
[Serializable] [Serializable]
public class ObjectEntry public class ObjectEntry
{ {
public GameObject target; public AvatarObjectReference target;
public bool Active; public bool Active;
} }
@ -34,15 +34,21 @@ namespace nadena.dev.modular_avatar.core
{ {
return Objects.Select(obj => return Objects.Select(obj =>
new KeyValuePair<MenuCurveBinding, AnimationCurve>( new KeyValuePair<MenuCurveBinding, AnimationCurve>(
new MenuCurveBinding(obj.target, typeof(GameObject), "m_IsActive"), new MenuCurveBinding(obj.target.Get(this), typeof(GameObject), "m_IsActive"),
AnimationCurve.Constant(0, 1, obj.Active ? 1 : 0)) AnimationCurve.Constant(0, 1, obj.Active ? 1 : 0))
).ToImmutableDictionary(); ).ToImmutableDictionary();
} }
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault) public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault)
{ {
return Objects.Select(obj => var builder = ImmutableDictionary<MenuCurveBinding, AnimationCurve>.Empty.ToBuilder();
foreach (var obj in Objects)
{ {
var target = obj.target?.Get(this);
if (target == null) continue;
bool active; bool active;
if (isDefault) if (isDefault)
{ {
@ -50,14 +56,16 @@ namespace nadena.dev.modular_avatar.core
} }
else else
{ {
active = obj.target.activeSelf; // inactive state is the current state active = target.activeSelf; // inactive state is the current state
} }
return new KeyValuePair<MenuCurveBinding, AnimationCurve>( builder.Add(
new MenuCurveBinding(obj.target, typeof(GameObject), "m_IsActive"), new MenuCurveBinding(target, typeof(GameObject), "m_IsActive"),
AnimationCurve.Constant(0, 1, active ? 1 : 0)); AnimationCurve.Constant(0, 1, active ? 1 : 0)
);
} }
).ToImmutableDictionary();
return builder.ToImmutable();
} }
public bool BindsParameter(TargetParameter parameter) public bool BindsParameter(TargetParameter parameter)

View File

@ -77,6 +77,7 @@ namespace nadena.dev.modular_avatar.core
[CanBeNull] [CanBeNull]
public static string AvatarRootPath(GameObject child) public static string AvatarRootPath(GameObject child)
{ {
if (child == null) return null;
var avatar = FindAvatarInParents(child.transform); var avatar = FindAvatarInParents(child.transform);
if (avatar == null) return null; if (avatar == null) return null;
return RelativePath(avatar.gameObject, child); return RelativePath(avatar.gameObject, child);

View File

@ -73,8 +73,9 @@ MonoBehaviour:
labels: [] labels: []
MenuSource: 0 MenuSource: 0
menuSource_otherObjectChildren: {fileID: 0} menuSource_otherObjectChildren: {fileID: 0}
toggleGroup: {fileID: 0} controlGroup: {fileID: 0}
isDefault: 0 isSynced: 1
isSaved: 1
--- !u!114 &186869909411364114 --- !u!114 &186869909411364114
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -88,7 +89,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Objects: Objects:
- target: {fileID: 186869909814968463} - target:
referencePath: SimpleToggle/Cube
Active: 1 Active: 1
--- !u!1 &186869909814968463 --- !u!1 &186869909814968463
GameObject: GameObject: