modular-avatar/Runtime/ModularAvatarShapeChanger.cs
bd_ 8e7526e711
Connect reactive components to MenuItems (#944)
* refactor: generalize support for arbitrary parameters as conditions

* feat: automatically assign Menu Item parameters

* feat: ReactiveComponents respond to MenuItems

* feat: AvatarObjectReference tracks both paths and direct object references

* feat: set isSaved/isSynced/default values from MenuItem

* feat: Object Toggle preview supports menu items and manipulating parent objects

* feat: reactive previews respond to menu item default value states

* chore: update NDMF dependency
2024-08-04 19:31:43 -07:00

69 lines
1.7 KiB
C#

#region
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
#endregion
namespace nadena.dev.modular_avatar.core
{
[Serializable]
public enum ShapeChangeType
{
Delete,
Set
}
[Serializable]
public struct ChangedShape
{
public string ShapeName;
public ShapeChangeType ChangeType;
public float Value;
public bool Equals(ChangedShape other)
{
return ShapeName == other.ShapeName && ChangeType == other.ChangeType && Value.Equals(other.Value);
}
public override bool Equals(object obj)
{
return obj is ChangedShape other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(ShapeName, (int)ChangeType, Value);
}
public override string ToString()
{
return $"{ShapeName} {ChangeType} {Value}";
}
}
[AddComponentMenu("Modular Avatar/MA Shape Changer")]
[HelpURL("https://modular-avatar.nadena.dev/docs/reference/shape-changer?lang=auto")]
public class ModularAvatarShapeChanger : ReactiveComponent
{
[SerializeField] [FormerlySerializedAs("targetRenderer")]
private AvatarObjectReference m_targetRenderer;
public AvatarObjectReference targetRenderer
{
get => m_targetRenderer;
set => m_targetRenderer = value;
}
[SerializeField] [FormerlySerializedAs("Shapes")]
private List<ChangedShape> m_shapes = new();
public List<ChangedShape> Shapes
{
get => m_shapes;
set => m_shapes = value;
}
}
}