mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-03-10 07:44:57 +08:00
compat/feat: use AvatarObjectReference for action paths
This commit is contained in:
parent
47a1e8393c
commit
cae4622bfc
@ -171,7 +171,7 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
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()
|
||||
{
|
||||
target = go,
|
||||
target = new AvatarObjectReference()
|
||||
{
|
||||
referencePath = RuntimeUtil.AvatarRootPath(go)
|
||||
},
|
||||
Active = go.activeSelf
|
||||
});
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace nadena.dev.modular_avatar.core
|
||||
[Serializable]
|
||||
public class ObjectEntry
|
||||
{
|
||||
public GameObject target;
|
||||
public AvatarObjectReference target;
|
||||
public bool Active;
|
||||
}
|
||||
|
||||
@ -34,30 +34,38 @@ namespace nadena.dev.modular_avatar.core
|
||||
{
|
||||
return Objects.Select(obj =>
|
||||
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))
|
||||
).ToImmutableDictionary();
|
||||
}
|
||||
|
||||
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault)
|
||||
{
|
||||
return Objects.Select(obj =>
|
||||
{
|
||||
bool active;
|
||||
if (isDefault)
|
||||
{
|
||||
active = !obj.Active; // inactive state is the opposite of the default state
|
||||
}
|
||||
else
|
||||
{
|
||||
active = obj.target.activeSelf; // inactive state is the current state
|
||||
}
|
||||
var builder = ImmutableDictionary<MenuCurveBinding, AnimationCurve>.Empty.ToBuilder();
|
||||
|
||||
return new KeyValuePair<MenuCurveBinding, AnimationCurve>(
|
||||
new MenuCurveBinding(obj.target, typeof(GameObject), "m_IsActive"),
|
||||
AnimationCurve.Constant(0, 1, active ? 1 : 0));
|
||||
foreach (var obj in Objects)
|
||||
{
|
||||
var target = obj.target?.Get(this);
|
||||
|
||||
if (target == null) continue;
|
||||
|
||||
bool active;
|
||||
if (isDefault)
|
||||
{
|
||||
active = !obj.Active; // inactive state is the opposite of the default state
|
||||
}
|
||||
).ToImmutableDictionary();
|
||||
else
|
||||
{
|
||||
active = target.activeSelf; // inactive state is the current state
|
||||
}
|
||||
|
||||
builder.Add(
|
||||
new MenuCurveBinding(target, typeof(GameObject), "m_IsActive"),
|
||||
AnimationCurve.Constant(0, 1, active ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
|
||||
public bool BindsParameter(TargetParameter parameter)
|
||||
|
@ -77,6 +77,7 @@ namespace nadena.dev.modular_avatar.core
|
||||
[CanBeNull]
|
||||
public static string AvatarRootPath(GameObject child)
|
||||
{
|
||||
if (child == null) return null;
|
||||
var avatar = FindAvatarInParents(child.transform);
|
||||
if (avatar == null) return null;
|
||||
return RelativePath(avatar.gameObject, child);
|
||||
|
@ -73,8 +73,9 @@ MonoBehaviour:
|
||||
labels: []
|
||||
MenuSource: 0
|
||||
menuSource_otherObjectChildren: {fileID: 0}
|
||||
toggleGroup: {fileID: 0}
|
||||
isDefault: 0
|
||||
controlGroup: {fileID: 0}
|
||||
isSynced: 1
|
||||
isSaved: 1
|
||||
--- !u!114 &186869909411364114
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -88,7 +89,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Objects:
|
||||
- target: {fileID: 186869909814968463}
|
||||
- target:
|
||||
referencePath: SimpleToggle/Cube
|
||||
Active: 1
|
||||
--- !u!1 &186869909814968463
|
||||
GameObject:
|
||||
|
Loading…
Reference in New Issue
Block a user