RotateParticleRuntimeProvider

This commit is contained in:
ousttrue
2024-11-15 17:32:58 +09:00
parent 5a0e2be6c6
commit 894b00b805
8 changed files with 69 additions and 32 deletions

View File

@@ -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<Vrm10Instance>() != null;
}
/// <summary>
/// instance.SpringBone.Springs を rotate particle で置き換える。
/// UNDO 可能。
/// </summary>
[MenuItem(FROM_VRM10_MENU, false)]
public static void FromVrm10()
static void FromVrm10(Vrm10Instance instance)
{
var go = Selection.activeGameObject;
var instance = go.GetComponent<Vrm10Instance>();
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<Vrm10Instance>();
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();
}
}
}

View File

@@ -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;

View File

@@ -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<Warp> Warps = new();
[SerializeField]
public List<RectCloth> Cloths = new();
public IVrm10SpringBoneRuntime CreateSpringBoneRuntime()
{
return new RotateParticleSpringboneRuntime();
}
public void Reset()
{
Warps = GetComponentsInChildren<Warp>().ToList();
Cloths = GetComponentsInChildren<RectCloth>().ToList();
}
}
}

View File

@@ -63,5 +63,10 @@ namespace RotateParticle.Components
// TODO: 枝分かれを削除
// Debug.Log("Warp.OnValidate");
}
internal List<Warp> ToList()
{
throw new NotImplementedException();
}
}
}

View File

@@ -1,13 +0,0 @@
using UnityEngine;
using UniVRM10;
namespace RotateParticle
{
public class RotateParticleSpringboneRuntimeProvider : MonoBehaviour, IVrm10SpringBoneRuntimeProvider
{
public IVrm10SpringBoneRuntime CreateSpringBoneRuntime()
{
return new RotateParticleSpringboneRuntime();
}
}
}