2023-03-04 13:31:23 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Object = System.Object;
|
|
|
|
|
|
|
|
|
|
namespace nadena.dev.modular_avatar.core
|
|
|
|
|
{
|
|
|
|
|
[AddComponentMenu("Modular Avatar/MA Action Toggle Object")]
|
2023-04-15 17:11:30 +08:00
|
|
|
|
[RequireComponent(typeof(ActionController))]
|
2023-03-04 13:31:23 +08:00
|
|
|
|
public class ActionToggleObject : AvatarTagComponent, SwitchedMenuAction
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class ObjectEntry
|
|
|
|
|
{
|
2023-04-30 19:58:11 +08:00
|
|
|
|
public AvatarObjectReference target = new AvatarObjectReference();
|
2023-03-04 13:31:23 +08:00
|
|
|
|
public bool Active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ObjectEntry> Objects;
|
|
|
|
|
|
|
|
|
|
protected override void OnValidate()
|
|
|
|
|
{
|
|
|
|
|
base.OnValidate();
|
|
|
|
|
|
|
|
|
|
if (Objects == null)
|
|
|
|
|
{
|
|
|
|
|
Objects = new List<ObjectEntry>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetCurves()
|
|
|
|
|
{
|
|
|
|
|
return Objects.Select(obj =>
|
|
|
|
|
new KeyValuePair<MenuCurveBinding, AnimationCurve>(
|
2023-04-30 18:55:45 +08:00
|
|
|
|
new MenuCurveBinding(obj.target.Get(this), typeof(GameObject), "m_IsActive"),
|
2023-03-04 13:31:23 +08:00
|
|
|
|
AnimationCurve.Constant(0, 1, obj.Active ? 1 : 0))
|
|
|
|
|
).ToImmutableDictionary();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-30 19:08:31 +08:00
|
|
|
|
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves()
|
2023-03-04 13:31:23 +08:00
|
|
|
|
{
|
2023-04-30 18:55:45 +08:00
|
|
|
|
var builder = ImmutableDictionary<MenuCurveBinding, AnimationCurve>.Empty.ToBuilder();
|
|
|
|
|
|
|
|
|
|
foreach (var obj in Objects)
|
|
|
|
|
{
|
|
|
|
|
var target = obj.target?.Get(this);
|
|
|
|
|
|
|
|
|
|
if (target == null) continue;
|
2023-03-04 13:31:23 +08:00
|
|
|
|
|
2023-04-30 18:55:45 +08:00
|
|
|
|
builder.Add(
|
|
|
|
|
new MenuCurveBinding(target, typeof(GameObject), "m_IsActive"),
|
2023-04-30 19:08:31 +08:00
|
|
|
|
AnimationCurve.Constant(0, 1, 0)
|
2023-04-30 18:55:45 +08:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return builder.ToImmutable();
|
2023-03-04 13:31:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool BindsParameter(TargetParameter parameter)
|
|
|
|
|
{
|
|
|
|
|
return parameter == TargetParameter.BaseParameter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|