diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs index 708c651a4..93d1b972c 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs @@ -48,18 +48,30 @@ namespace RotateParticle.Components for (int i = 0; i < joints.Length; ++i) { var joint = joints[i]; - warp.Particles.Add(new Warp.Particle + var settings = new Warp.ParticleSettings { - OverrideSettings = new Warp.ParticleSettings + DragForce = joint.m_dragForce, + GravityDir = joint.m_gravityDir, + GravityPower = joint.m_gravityPower, + StiffnessForce = joint.m_stiffnessForce, + }; + if (i == 0) + { + settings.HitRadius = joints[0].m_jointRadius; + warp.BaseSettings = settings; + } + else + { + // breaking change from vrm-1.0 + settings.HitRadius = joints[i - 1].m_jointRadius; + var useInheritSettings = warp.BaseSettings.Equals(settings); + warp.Particles.Add(new Warp.Particle { - DragForce = joint.m_dragForce, - GravityDir = joint.m_gravityDir, - GravityPower = joint.m_gravityPower, - StiffnessForce = joint.m_stiffnessForce, - // breaking change from vrm-1.0 - HitRadius = i > 0 ? joints[i - 1].m_jointRadius : joints[i].m_jointRadius, - }, - }); + useInheritSettings = useInheritSettings, + OverrideSettings = settings, + Transform = joint.transform, + }); + } Undo.DestroyObjectImmediate(joint); } spring.Joints.Clear(); diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs index 6c0e3ea7d..fc4d3f71d 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs @@ -10,7 +10,7 @@ namespace RotateParticle.Components public class Warp : MonoBehaviour { [Serializable] - public class ParticleSettings + public class ParticleSettings : IEquatable { [SerializeField] public float StiffnessForce = 1.0f; @@ -26,6 +26,27 @@ namespace RotateParticle.Components [SerializeField] public float HitRadius = 0.02f; + + public override bool Equals(object obj) // Object.Equals(Object)のオーバーライド + { + return Equals(obj as ParticleSettings); + } + + public bool Equals(ParticleSettings other) + { + return + StiffnessForce == other.StiffnessForce + && GravityPower == other.GravityPower + && GravityDir == other.GravityDir + && DragForce == other.DragForce + && HitRadius == other.HitRadius + ; + } + + public override int GetHashCode() + { + return GravityDir.GetHashCode(); + } } /// @@ -34,8 +55,14 @@ namespace RotateParticle.Components [Serializable] public class Particle { - public bool useInheritSettings; - public ParticleSettings OverrideSettings; + public bool useInheritSettings = true; + public ParticleSettings OverrideSettings = new(); + public Transform Transform; + + public ParticleSettings GetSettings(ParticleSettings baseSettings) + { + return useInheritSettings ? baseSettings : OverrideSettings; + } } [SerializeField] @@ -68,5 +95,25 @@ namespace RotateParticle.Components { throw new NotImplementedException(); } + + public void OnDrawGizmosSelected() + { + Gizmos.DrawSphere(transform.position, BaseSettings.HitRadius); + + Transform prev = transform; + foreach (var p in Particles) + { + if (p != null && p.Transform != null) + { + Gizmos.DrawWireSphere(p.Transform.position, p.GetSettings(BaseSettings).HitRadius); + + if (prev != null) + { + Gizmos.DrawLine(prev.position, p.Transform.position); + } + } + prev = p.Transform; + } + } } -} +} \ No newline at end of file