mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-20 09:47:56 -05:00
Added BlendShapeClipDrawer
This commit is contained in:
parent
f0064a2879
commit
91306f4a83
|
|
@ -60,29 +60,17 @@ namespace VRM
|
|||
Clips = Clips.OrderBy(x => BlendShapeKey.CreateFrom(x)).ToList();
|
||||
}
|
||||
|
||||
public void AddBlendShapeClip()
|
||||
static public BlendShapeClip CreateBlendShapeClip(string path)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(this));
|
||||
var path = EditorUtility.SaveFilePanel(
|
||||
"Create BlendShapeClip",
|
||||
dir,
|
||||
string.Format("BlendShapeClip#{0}.asset", Clips.Count),
|
||||
"asset");
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
path = path.ToUnityRelativePath();
|
||||
//Debug.LogFormat("{0}", path);
|
||||
var clip = ScriptableObject.CreateInstance<BlendShapeClip>();
|
||||
clip.BlendShapeName = Path.GetFileNameWithoutExtension(path);
|
||||
clip.Prefab = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GetAssetPath(this));
|
||||
AssetDatabase.CreateAsset(clip, path);
|
||||
AssetDatabase.ImportAsset(path);
|
||||
|
||||
Clips.Add(clip);
|
||||
EditorUtility.SetDirty(this);
|
||||
AssetDatabase.SaveAssets();
|
||||
return clip;
|
||||
//Clips.Add(clip);
|
||||
//EditorUtility.SetDirty(this);
|
||||
//AssetDatabase.SaveAssets();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace VRM
|
|||
public BlendShapePreset Preset;
|
||||
|
||||
/// <summary>
|
||||
/// BlendShapeに対する参照(indexベース)
|
||||
/// BlendShapeに対する参照(index ベース)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[SerializeField]
|
||||
|
|
@ -91,5 +91,8 @@ namespace VRM
|
|||
/// </summary>
|
||||
[SerializeField]
|
||||
public bool IsBinary;
|
||||
|
||||
[SerializeField]
|
||||
public Texture2D Thumbnail;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,74 +4,71 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
[CustomEditor(typeof(BlendShapeAvatar))]
|
||||
public class BlendShapeAvatarEditor : PreviewEditor
|
||||
public class BlendShapeAvatarEditor : Editor
|
||||
{
|
||||
static String[] Presets = ((BlendShapePreset[])Enum.GetValues(typeof(BlendShapePreset)))
|
||||
.Select(x => x.ToString()).ToArray();
|
||||
ReorderableList m_clipList;
|
||||
|
||||
BlendShapeClipSelector m_selector;
|
||||
|
||||
SerializedBlendShapeEditor m_clipEditor;
|
||||
|
||||
void OnPrefabChanged()
|
||||
void OnEnable()
|
||||
{
|
||||
if (m_selector != null)
|
||||
var prop = serializedObject.FindProperty("Clips");
|
||||
m_clipList = new ReorderableList(serializedObject, prop);
|
||||
|
||||
m_clipList.drawHeaderCallback = (rect) =>
|
||||
EditorGUI.LabelField(rect, "BlendShapeClips");
|
||||
|
||||
m_clipList.elementHeight = BlendShapeClipDrawer.Height;
|
||||
m_clipList.drawElementCallback = (rect, index, isActive, isFocused) =>
|
||||
{
|
||||
Bake(m_selector.Selected, 1.0f);
|
||||
}
|
||||
var element = prop.GetArrayElementAtIndex(index);
|
||||
rect.height -= 4;
|
||||
rect.y += 2;
|
||||
EditorGUI.PropertyField(rect, element);
|
||||
};
|
||||
|
||||
m_clipList.onAddCallback += (list) =>
|
||||
{
|
||||
// Add slot
|
||||
prop.arraySize++;
|
||||
// select last item
|
||||
list.index = prop.arraySize - 1;
|
||||
// get last item
|
||||
var element = prop.GetArrayElementAtIndex(list.index);
|
||||
element.objectReferenceValue = null;
|
||||
|
||||
var dir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(target));
|
||||
var path = EditorUtility.SaveFilePanel(
|
||||
"Create BlendShapeClip",
|
||||
dir,
|
||||
string.Format("BlendShapeClip#{0}.asset", list.count),
|
||||
"asset");
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
var clip = BlendShapeAvatar.CreateBlendShapeClip(path.ToUnityRelativePath());
|
||||
//clip.Prefab = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GetAssetPath(target));
|
||||
|
||||
element.objectReferenceValue = clip;
|
||||
}
|
||||
};
|
||||
|
||||
m_clipList.onCanRemoveCallback += list => true;
|
||||
}
|
||||
|
||||
void OnSelected(BlendShapeClip clip)
|
||||
void OnDisable()
|
||||
{
|
||||
Bake(clip, 1.0f);
|
||||
if (clip != null)
|
||||
{
|
||||
m_clipEditor = new SerializedBlendShapeEditor(clip, PreviewSceneManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_clipEditor = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
PrefabChanged += OnPrefabChanged;
|
||||
base.OnEnable();
|
||||
|
||||
m_selector = new BlendShapeClipSelector((BlendShapeAvatar)target, OnSelected);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
PrefabChanged -= OnPrefabChanged;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
m_selector.SelectGUI();
|
||||
|
||||
if (m_clipEditor != null)
|
||||
{
|
||||
Separator();
|
||||
|
||||
m_selector.DuplicateWarn();
|
||||
|
||||
var result = m_clipEditor.Draw();
|
||||
if (result.Changed)
|
||||
{
|
||||
Bake(result.BlendShapeBindings, result.MaterialValueBindings, result.Weight);
|
||||
}
|
||||
}
|
||||
serializedObject.Update();
|
||||
m_clipList.DoLayoutList();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
56
Scripts/BlendShape/Editor/BlendShapeClipDrawer.cs
Normal file
56
Scripts/BlendShape/Editor/BlendShapeClipDrawer.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(BlendShapeClip))]
|
||||
public class BlendShapeClipDrawer : PropertyDrawer
|
||||
{
|
||||
public const int Height = 72;
|
||||
|
||||
public override void OnGUI(Rect position,
|
||||
SerializedProperty property, GUIContent label)
|
||||
{
|
||||
using (new EditorGUI.PropertyScope(position, label, property))
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 80;
|
||||
|
||||
position.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
var halfWidth = position.width * 0.5f;
|
||||
|
||||
var rect = new Rect(position.x + 64, position.y, position.width - 64, position.height);
|
||||
EditorGUI.PropertyField(rect, property);
|
||||
|
||||
var clip = property.objectReferenceValue as BlendShapeClip;
|
||||
if (clip != null)
|
||||
{
|
||||
var clipObj = new SerializedObject(clip);
|
||||
var thumbnail = clipObj.FindProperty("Thumbnail");
|
||||
var blendShapeName = clipObj.FindProperty("BlendShapeName");
|
||||
var preset = clipObj.FindProperty("Preset");
|
||||
var isBinary = clipObj.FindProperty("IsBinary");
|
||||
|
||||
EditorGUI.ObjectField(new Rect(position)
|
||||
{
|
||||
width = 64,
|
||||
height = 64
|
||||
}, thumbnail.objectReferenceValue, typeof(Texture), false);
|
||||
|
||||
rect.y += (EditorGUIUtility.singleLineHeight + 2);
|
||||
EditorGUI.PropertyField(rect, blendShapeName);
|
||||
rect.y += (EditorGUIUtility.singleLineHeight + 2);
|
||||
EditorGUI.PropertyField(rect, preset);
|
||||
rect.y += (EditorGUIUtility.singleLineHeight + 2);
|
||||
EditorGUI.PropertyField(rect, isBinary);
|
||||
|
||||
clipObj.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Scripts/BlendShape/Editor/BlendShapeClipDrawer.cs.meta
Normal file
12
Scripts/BlendShape/Editor/BlendShapeClipDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a31667cfcf461c47b3b384211e2d9ff
|
||||
timeCreated: 1541179390
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -69,7 +69,7 @@ namespace VRM
|
|||
|
||||
if (GUILayout.Button("Add BlendShapeClip"))
|
||||
{
|
||||
m_avatar.AddBlendShapeClip();
|
||||
//m_avatar.AddBlendShapeClip();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace VRM
|
|||
SerializedObject m_serializedObject;
|
||||
|
||||
#region Properties
|
||||
SerializedProperty m_thumbnail;
|
||||
SerializedProperty m_blendShapeNameProp;
|
||||
SerializedProperty m_presetProp;
|
||||
|
||||
|
|
@ -63,6 +64,7 @@ namespace VRM
|
|||
this.m_serializedObject = serializedObject;
|
||||
this.m_targetObject = targetObject;
|
||||
|
||||
m_thumbnail = serializedObject.FindProperty("Thumbnail");
|
||||
m_blendShapeNameProp = serializedObject.FindProperty("BlendShapeName");
|
||||
m_presetProp = serializedObject.FindProperty("Preset");
|
||||
m_isBinaryProp = serializedObject.FindProperty("IsBinary");
|
||||
|
|
@ -131,6 +133,8 @@ namespace VRM
|
|||
m_targetObject, typeof(BlendShapeClip), false);
|
||||
GUI.enabled = true;
|
||||
|
||||
m_thumbnail.objectReferenceValue = EditorGUILayout.ObjectField(m_thumbnail.objectReferenceValue, typeof(Texture), false);
|
||||
EditorGUILayout.PropertyField(m_thumbnail, true);
|
||||
EditorGUILayout.PropertyField(m_blendShapeNameProp, true);
|
||||
EditorGUILayout.PropertyField(m_presetProp, true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user