2023-02-27 23:00:22 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
2023-02-28 23:15:34 +09:00
|
|
|
|
using Object = System.Object;
|
2023-02-27 23:00:22 +09:00
|
|
|
|
|
|
|
|
|
namespace nadena.dev.modular_avatar.core
|
|
|
|
|
{
|
|
|
|
|
public sealed class MenuCurveBinding
|
|
|
|
|
{
|
|
|
|
|
public readonly GameObject target;
|
|
|
|
|
public readonly Type type;
|
|
|
|
|
public readonly string property;
|
|
|
|
|
|
|
|
|
|
public MenuCurveBinding(GameObject target, Type type, string property)
|
|
|
|
|
{
|
|
|
|
|
this.target = target;
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.property = property;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool Equals(MenuCurveBinding other)
|
|
|
|
|
{
|
|
|
|
|
return target == other.target && type == other.type && property == other.property;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(null, obj)) return false;
|
|
|
|
|
if (ReferenceEquals(this, obj)) return true;
|
|
|
|
|
if (obj.GetType() != this.GetType()) return false;
|
|
|
|
|
return Equals((MenuCurveBinding) obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
unchecked
|
|
|
|
|
{
|
|
|
|
|
var hashCode = (target != null ? target.GetHashCode() : 0);
|
|
|
|
|
hashCode = (hashCode * 397) ^ (type != null ? type.GetHashCode() : 0);
|
|
|
|
|
hashCode = (hashCode * 397) ^ (property != null ? property.GetHashCode() : 0);
|
|
|
|
|
return hashCode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface MenuAction
|
|
|
|
|
{
|
2023-02-28 23:15:34 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the curves applied when this action is active
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-02-27 23:00:22 +09:00
|
|
|
|
ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetCurves();
|
2023-02-28 23:15:34 +09:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the curves applied when this action is inactive (and no other actions override).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isDefault">True if this action is part of the default toggle option.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault);
|
2023-02-27 23:00:22 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(ModularAvatarMenuItem))]
|
|
|
|
|
public class ActionToggleObject : AvatarTagComponent, MenuAction
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class ObjectEntry
|
|
|
|
|
{
|
|
|
|
|
public GameObject target;
|
|
|
|
|
public bool Active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ObjectEntry> Objects;
|
|
|
|
|
|
|
|
|
|
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetCurves()
|
|
|
|
|
{
|
|
|
|
|
return Objects.Select(obj =>
|
|
|
|
|
new KeyValuePair<MenuCurveBinding, AnimationCurve>(
|
|
|
|
|
new MenuCurveBinding(obj.target, typeof(GameObject), "m_IsActive"),
|
|
|
|
|
AnimationCurve.Constant(0, 1, obj.Active ? 1 : 0))
|
|
|
|
|
).ToImmutableDictionary();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-28 23:15:34 +09:00
|
|
|
|
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault)
|
2023-02-27 23:00:22 +09:00
|
|
|
|
{
|
|
|
|
|
return Objects.Select(obj =>
|
2023-02-28 23:15:34 +09:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new KeyValuePair<MenuCurveBinding, AnimationCurve>(
|
|
|
|
|
new MenuCurveBinding(obj.target, typeof(GameObject), "m_IsActive"),
|
|
|
|
|
AnimationCurve.Constant(0, 1, active ? 1 : 0));
|
|
|
|
|
}
|
2023-02-27 23:00:22 +09:00
|
|
|
|
).ToImmutableDictionary();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|