diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs similarity index 61% rename from Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs rename to Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs index f229e82d9..708c651a4 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs @@ -6,9 +6,10 @@ using UniVRM10; namespace RotateParticle.Components { - public static class Converter + [CustomEditor(typeof(RotateParticleRuntimeProvider))] + public class RotateParticleRuntimeProviderEditor : Editor { - const string FROM_VRM10_MENU = "GameObject/CreateRotateParticleFromVrm10"; + const string FROM_VRM10_MENU = "Replace VRM10 Springs to RotateParticle Warps"; [MenuItem(FROM_VRM10_MENU, true)] public static bool IsFromVrm10() @@ -21,20 +22,8 @@ namespace RotateParticle.Components return go.GetComponent() != null; } - /// - /// instance.SpringBone.Springs を rotate particle で置き換える。 - /// UNDO 可能。 - /// - [MenuItem(FROM_VRM10_MENU, false)] - public static void FromVrm10() + static void FromVrm10(Vrm10Instance instance) { - var go = Selection.activeGameObject; - var instance = go.GetComponent(); - - Undo.IncrementCurrentGroup(); - Undo.SetCurrentGroupName(FROM_VRM10_MENU); - var undo = Undo.GetCurrentGroup(); - Undo.RegisterCompleteObjectUndo(instance, "RegisterCompleteObjectUndo"); foreach (var spring in instance.SpringBone.Springs) { @@ -77,9 +66,36 @@ namespace RotateParticle.Components } instance.SpringBone.Springs.Clear(); - Undo.RegisterFullObjectHierarchyUndo(go, "RegisterFullObjectHierarchyUndo"); + Undo.RegisterFullObjectHierarchyUndo(instance.gameObject, "RegisterFullObjectHierarchyUndo"); - Undo.CollapseUndoOperations(undo); + } + + public override void OnInspectorGUI() + { + var provider = target as RotateParticleRuntimeProvider; + if (provider == null) + { + return; + } + var instance = provider.GetComponent(); + using (new EditorGUI.DisabledScope(instance == null)) + { + if (GUILayout.Button("Replace VRM10 Springs to RotateParticle Warps")) + { + Undo.IncrementCurrentGroup(); + Undo.SetCurrentGroupName(FROM_VRM10_MENU); + var undo = Undo.GetCurrentGroup(); + + FromVrm10(instance); + + Undo.RegisterCompleteObjectUndo(provider, "RegisterCompleteObjectUndo"); + provider.Reset(); + + Undo.CollapseUndoOperations(undo); + } + } + + base.OnInspectorGUI(); } } } \ No newline at end of file diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs.meta b/Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs.meta similarity index 100% rename from Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/Converter.cs.meta rename to Assets/VRM10_Samples/ClothSample/RotateParticle/Editor/RotateParticleRuntimeProviderEditor.cs.meta diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Cloth.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RectCloth.cs similarity index 75% rename from Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Cloth.cs rename to Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RectCloth.cs index 77b9db313..078ad3abf 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Cloth.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RectCloth.cs @@ -5,9 +5,9 @@ using UnityEngine; namespace RotateParticle.Components { - [AddComponentMenu("RotateParticle/Cloth")] + [AddComponentMenu("RotateParticle/RectCloth")] [DisallowMultipleComponent] - public class Cloth : MonoBehaviour + public class RectCloth : MonoBehaviour { [SerializeField] public bool Loop = false; diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Cloth.cs.meta b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RectCloth.cs.meta similarity index 100% rename from Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Cloth.cs.meta rename to Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RectCloth.cs.meta diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs new file mode 100644 index 000000000..56f1b3ed3 --- /dev/null +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UniVRM10; + +namespace RotateParticle.Components +{ + [AddComponentMenu("RotateParticle/RotateParticleRuntimeProvider")] + [DisallowMultipleComponent] + public class RotateParticleRuntimeProvider : MonoBehaviour, IVrm10SpringBoneRuntimeProvider + { + [SerializeField] + public List Warps = new(); + + [SerializeField] + public List Cloths = new(); + + public IVrm10SpringBoneRuntime CreateSpringBoneRuntime() + { + return new RotateParticleSpringboneRuntime(); + } + + public void Reset() + { + Warps = GetComponentsInChildren().ToList(); + Cloths = GetComponentsInChildren().ToList(); + } + } +} \ No newline at end of file diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntimeProvider.cs.meta b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs.meta similarity index 100% rename from Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntimeProvider.cs.meta rename to Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/RotateParticleRuntimeProvider.cs.meta diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs index e2e585130..6c0e3ea7d 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Components/Warp.cs @@ -63,5 +63,10 @@ namespace RotateParticle.Components // TODO: 枝分かれを削除 // Debug.Log("Warp.OnValidate"); } + + internal List ToList() + { + throw new NotImplementedException(); + } } } diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntimeProvider.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntimeProvider.cs deleted file mode 100644 index 456d245ef..000000000 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSpringboneRuntimeProvider.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEngine; -using UniVRM10; - -namespace RotateParticle -{ - public class RotateParticleSpringboneRuntimeProvider : MonoBehaviour, IVrm10SpringBoneRuntimeProvider - { - public IVrm10SpringBoneRuntime CreateSpringBoneRuntime() - { - return new RotateParticleSpringboneRuntime(); - } - } -} \ No newline at end of file