public void SelectGUI() { if (m_avatar != null && m_avatar.Clips != null) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Select BlendShapeClip", EditorStyles.boldLabel); var array = m_avatar.Clips .Select(x => x != null ? BlendShapeKey.CreateFromClip(x).ToString() : "null" ).ToArray(); SelectedIndex = GUILayout.SelectionGrid(SelectedIndex, array, 4); } if (GUILayout.Button("Add BlendShapeClip")) { var dir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(m_avatar)); var path = EditorUtility.SaveFilePanel( "Create BlendShapeClip", dir, string.Format("BlendShapeClip#{0}.asset", m_avatar.Clips.Count), "asset"); if (!string.IsNullOrEmpty(path)) { var clip = BlendShapeAvatar.CreateBlendShapeClip(path.ToUnityRelativePath()); //clip.Prefab = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GetAssetPath(target)); m_avatar.Clips.Add(clip); } } }
protected override void OnEnable() { m_selector = new BlendShapeClipSelector((BlendShapeAvatar)target, OnSelected); 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) => { 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.onSelectCallback += (list) => { var a = list.serializedProperty; var selected = a.GetArrayElementAtIndex(list.index); OnSelected((BlendShapeClip)selected.objectReferenceValue); }; //m_clipList.onCanRemoveCallback += list => true; base.OnEnable(); OnSelected(m_selector.Selected); }
public BlendShapeClipSelector(BlendShapeAvatar avatar, Action <BlendShapeClip> onSelected) { avatar.RemoveNullClip(); m_avatar = avatar; m_onSelected = onSelected; onSelected(Selected); }
public BlendShapeClipSelector(BlendShapeAvatar avatar, SerializedObject serializedObject) { avatar.RemoveNullClip(); m_avatar = avatar; var prop = serializedObject.FindProperty("Clips"); m_clipList = new ReorderableBlendShapeClipList(serializedObject, prop, avatar); m_clipList.Selected += (selected) => { SelectedIndex = avatar.Clips.IndexOf(selected); }; }