public override void OnInspectorGUI()
    {
        serializedObject.Update();

        // 数据
        if (EditorGUIHelper.DrawArrayHead(_dataProperty, "数据", true))
        {
            _dataProperty.InsertArrayElementAtIndex(_dataProperty.arraySize);   // 添加
        }

        int deleteIndex = -1;

        if (_dataProperty.isExpanded)
        {
            EditorGUILayout.BeginVertical("Box");
            {
                for (int i = 0; i < _dataProperty.arraySize; i++)
                {
                    DataProperty data;
                    GetDataProperty(_dataProperty.GetArrayElementAtIndex(i), out data);

                    if (EditorGUIHelper.DrawArrayItemHead(i, GetDataHead(ref data), Color.white))
                    {
                        deleteIndex = i;
                    }

                    DrawData(ref data);
                }
            }
            EditorGUILayout.EndVertical();
        }

        if (deleteIndex >= 0 && deleteIndex < _dataProperty.arraySize)
        {
            _dataProperty.DeleteArrayElementAtIndex(deleteIndex);
        }

        serializedObject.ApplyModifiedProperties();
    }
Пример #2
0
    /// <summary>
    /// draw element list
    /// </summary>
    void OnDrawElements()
    {
        SerializedProperty elements = serializedObject.FindProperty("Elements");

        if (elements == null)
        {
            return;
        }
        if (EditorGUIHelper.DrawArrayHead(elements, "连接节点列表", true))
        {
            // add element
            AddElement(elements);
        }

        int deleteIndex = -1;

        if (elements.isExpanded)
        {
            EditorGUILayout.BeginVertical("box");
            {
                for (int i = 0; i < _elemetList.Count; i++)
                {
                    SerializedProperty element = elements.GetArrayElementAtIndex(i);

                    if (EditorGUIHelper.DrawArrayItemHead(i))
                    {
                        deleteIndex = i;
                    }

                    EditorGUILayout.BeginHorizontal();
                    {
                        // component type popup
                        int selected = EditorGUILayout.Popup(_elemetList[i].CurrentType, _elemetList[i].TypeNameList.ToArray());
                        if (selected != _elemetList[i].CurrentType)
                        {
                            // change current type
                            _elemetList[i].CurrentType = selected;

                            // update property
                            OnChangeElementType(element, _elemetList[i].TypeList[selected]);
                        }

                        // object
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PropertyField(element.FindPropertyRelative("Component"), GUIContent.none);
                        if (EditorGUI.EndChangeCheck())
                        {
                            UpdateElement(elements, i);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
        }

        if (deleteIndex >= 0 && deleteIndex < elements.arraySize)
        {
            //elements.GetArrayElementAtIndex(deleteIndex).objectReferenceValue = null;
            elements.DeleteArrayElementAtIndex(deleteIndex);

            _elemetList.RemoveAt(deleteIndex);
        }
    }
    public override void OnInspectorGUI()
    {
        if (OnDrop())
        {
            return;
        }

        serializedObject.Update();
        //判断拖动掉落
        if (_dropIndex >= 0 && !string.IsNullOrEmpty(_dropResName))
        {
            SerializedProperty p = _dataProperty.GetArrayElementAtIndex(_dropIndex);
            p             = p.FindPropertyRelative("ResName");
            p.stringValue = _dropResName;
            _dropIndex    = -1;
            _dropResName  = null;
            //serializedObject.ApplyModifiedProperties();
        }

        //清理
        if (Event.current.type == EventType.Repaint)
        {
            _resNameRect.Clear();
        }

        //界面
        if (EditorGUIHelper.DrawArrayHead(_dataProperty, "音频数据", true))
        {
            _dataProperty.InsertArrayElementAtIndex(_dataProperty.arraySize);   // 添加
        }

        if (_dataProperty.isExpanded)
        {
            int deleteIndex = -1;

            EditorGUILayout.BeginVertical("Box");
            {
                for (int i = 0; i < _dataProperty.arraySize; i++)
                {
                    if (EditorGUIHelper.DrawArrayItemHead(i))
                    {
                        deleteIndex = i;
                    }

                    EditorGUILayout.BeginVertical("box");
                    {
                        DrawData(_dataProperty.GetArrayElementAtIndex(i));
                    }
                    EditorGUILayout.EndVertical();
                }
            }
            EditorGUILayout.EndVertical();

            if (deleteIndex >= 0 && deleteIndex < _dataProperty.arraySize)
            {
                _dataProperty.DeleteArrayElementAtIndex(deleteIndex);
            }
        }

        serializedObject.ApplyModifiedProperties();
    }