modular-avatar/Runtime/ReactiveObjects/ModularAvatarMaterialSetter.cs
nekobako 8418f8e047
feat: change shape changer to support multiple target renderers (#1011)
* feat: add target renderer to ChangedShape

* chore: add test for ShapeChanger target renderer

* feat: add override target to MaterialSetter

* fix: resolve added AvatarObjectReference

* fix: record prefab instance property modifications

* refactor: remove unused setter for AvatarObjectReference

* refactor: change ChangedShape and MaterialSwitchObject from struct to class

* feat: remove override target from ShapeChanger and MaterialSetter

* refactor: align flow and code style of ShapeChanger and MaterialSetter

* feat: ShapeChanger target migration

* fix: add null check

* chore: added some comments and nullchecks

---------

Co-authored-by: bd_ <bd_@nadena.dev>
2024-08-21 20:27:10 -07:00

51 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
namespace nadena.dev.modular_avatar.core
{
[Serializable]
public class MaterialSwitchObject
{
public AvatarObjectReference Object;
public Material Material;
public int MaterialIndex;
public bool Equals(MaterialSwitchObject other)
{
return Equals(Object, other.Object) && Equals(Material, other.Material) && MaterialIndex == other.MaterialIndex;
}
public override bool Equals(object obj)
{
return obj is MaterialSwitchObject other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(Object, Material, MaterialIndex);
}
}
[AddComponentMenu("Modular Avatar/MA Material Setter")]
[HelpURL("https://modular-avatar.nadena.dev/docs/reference/material-setter?lang=auto")]
public class ModularAvatarMaterialSetter : ReactiveComponent
{
[SerializeField] private List<MaterialSwitchObject> m_objects = new();
public List<MaterialSwitchObject> Objects
{
get => m_objects;
set => m_objects = value;
}
public override void ResolveReferences()
{
foreach (var obj in m_objects)
{
obj.Object?.Get(this);
}
}
}
}