mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-23 07:28:55 -05:00
feature (VRM1, SpringBone): add limit break slider to spring bone joint properties
This commit is contained in:
parent
9925b15b84
commit
3f9071f679
|
|
@ -0,0 +1,98 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
[CustomEditor(typeof(VRM10SpringBoneJoint))]
|
||||
class VRM10SpringBoneJointEditor : Editor
|
||||
{
|
||||
private VRM10SpringBoneJoint m_target;
|
||||
private SerializedProperty m_stiffnessForceProp;
|
||||
private SerializedProperty m_gravityPowerProp;
|
||||
private SerializedProperty m_gravityDirProp;
|
||||
private SerializedProperty m_dragForceProp;
|
||||
private SerializedProperty m_jointRadiusProp;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_target = (VRM10SpringBoneJoint)target;
|
||||
|
||||
m_stiffnessForceProp = serializedObject.FindProperty("m_stiffnessForce");
|
||||
m_gravityPowerProp = serializedObject.FindProperty("m_gravityPower");
|
||||
m_gravityDirProp = serializedObject.FindProperty("m_gravityDir");
|
||||
m_dragForceProp = serializedObject.FindProperty("m_dragForce");
|
||||
m_jointRadiusProp = serializedObject.FindProperty("m_jointRadius");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
|
||||
|
||||
LimitBreakSlider(m_stiffnessForceProp, 0.0f, 4.0f, 0.0f, Mathf.Infinity);
|
||||
LimitBreakSlider(m_gravityPowerProp, 0.0f, 2.0f, 0.0f, Mathf.Infinity);
|
||||
EditorGUILayout.PropertyField(m_gravityDirProp);
|
||||
EditorGUILayout.PropertyField(m_dragForceProp);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Collision", EditorStyles.boldLabel);
|
||||
|
||||
LimitBreakSlider(m_jointRadiusProp, 0.0f, 0.5f, 0.0f, Mathf.Infinity);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// スライダーと数値入力で限界値の違う、所謂「限界突破スライダー」を作成する
|
||||
/// `EditorGUILayout.PropertyField` の代替として利用する
|
||||
/// </summary>
|
||||
private static void LimitBreakSlider(SerializedProperty property, float sliderLeft, float sliderRight, float numberLeft, float numberRight)
|
||||
{
|
||||
var label = new GUIContent(property.displayName);
|
||||
var currentValue = property.floatValue;
|
||||
|
||||
var rect = EditorGUILayout.GetControlRect();
|
||||
|
||||
EditorGUI.BeginProperty(rect, label, property);
|
||||
|
||||
rect = EditorGUI.PrefixLabel(rect, label);
|
||||
|
||||
// slider
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var sliderRect = rect;
|
||||
sliderRect.width -= 55.0f;
|
||||
rect.xMin += rect.width - 50.0f;
|
||||
|
||||
var clampedvalue = Mathf.Clamp(currentValue, sliderLeft, sliderRight);
|
||||
var sliderValue = GUI.HorizontalSlider(sliderRect, clampedvalue, sliderLeft, sliderRight);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
property.floatValue = sliderValue;
|
||||
}
|
||||
}
|
||||
|
||||
// number
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var numberValue = Mathf.Clamp(EditorGUI.FloatField(rect, currentValue), numberLeft, numberRight);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
property.floatValue = numberValue;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cb6829ce1ea93194fbd08e175456a797
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -11,10 +11,10 @@ namespace UniVRM10
|
|||
[DisallowMultipleComponent]
|
||||
public class VRM10SpringBoneJoint : MonoBehaviour
|
||||
{
|
||||
[SerializeField, Range(0, 4), Header("Settings")]
|
||||
[SerializeField]
|
||||
public float m_stiffnessForce = 1.0f;
|
||||
|
||||
[SerializeField, Range(0, 2)]
|
||||
[SerializeField]
|
||||
public float m_gravityPower = 0;
|
||||
|
||||
[SerializeField]
|
||||
|
|
@ -23,7 +23,7 @@ namespace UniVRM10
|
|||
[SerializeField, Range(0, 1)]
|
||||
public float m_dragForce = 0.4f;
|
||||
|
||||
[SerializeField, Range(0, 0.5f), Header("Collision")]
|
||||
[SerializeField]
|
||||
public float m_jointRadius = 0.02f;
|
||||
|
||||
void AddJointRecursive(Transform t, VRM10SpringBoneJoint src)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user