示例#1
0
        void SelectGUI()
        {
            if (m_avatar != null && m_avatar.Clips != null)
            {
                var array = m_avatar.Clips
                            .Select(x => x != null
                        ? ExpressionKey.CreateFromClip(x).ToString()
                        : "null"
                                    ).ToArray();
                SelectedIndex = GUILayout.SelectionGrid(SelectedIndex, array, 4);
            }

            if (GUILayout.Button("Add Expression"))
            {
                var dir  = Path.GetDirectoryName(AssetDatabase.GetAssetPath(m_avatar));
                var path = EditorUtility.SaveFilePanel(
                    "Create Expression",
                    dir,
                    string.Format("Expression#{0}.asset", m_avatar.Clips.Count),
                    "asset");
                if (!string.IsNullOrEmpty(path))
                {
                    var clip = VRM10ExpressionAvatar.CreateExpression(path.ToUnityRelativePath());
                    //clip.Prefab = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GetAssetPath(target));

                    m_avatar.Clips.Add(clip);
                }
            }
        }
        public ReorderableExpressionList(SerializedObject serializedObject, SerializedProperty prop, UnityEngine.Object target)
        {
            m_list = new ReorderableList(serializedObject, prop);

            m_list.drawHeaderCallback = (rect) =>
                                        EditorGUI.LabelField(rect, "Expressions");

            m_list.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                var element = prop.GetArrayElementAtIndex(index);
                rect.height -= 4;
                rect.y      += 2;
                EditorGUI.PropertyField(rect, element);
            };

            m_list.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 Expression",
                    dir,
                    string.Format("Expression#{0}.asset", list.count),
                    "asset");
                if (!string.IsNullOrEmpty(path))
                {
                    var clip = VRM10ExpressionAvatar.CreateExpression(path.ToUnityRelativePath());
                    //clip.Prefab = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GetAssetPath(target));

                    element.objectReferenceValue = clip;
                }
            };

            m_list.onSelectCallback += (list) =>
            {
                var a        = list.serializedProperty;
                var selected = a.GetArrayElementAtIndex(list.index);
                RaiseSelected((VRM10Expression)selected.objectReferenceValue);
            };

            //m_clipList.onCanRemoveCallback += list => true;
        }