コード例 #1
0
        private void DrawCustoms()
        {
            serializedSettings.UpdateIfRequiredOrScript();

            var customTypes = serializedSettings.FindProperty("customTypes");

            if (customTypes.arraySize == 0)
            {
                if (GUILayout.Button("Add", EditorStyles.miniButtonRight))
                {
                    customTypes.InsertArrayElementAtIndex(0);
                    serializedSettings.ApplyModifiedProperties();
                }
            }

            string[] customNames = new string[customTypes.arraySize];

            EditorGUI.indentLevel++;

            SerializedProperty customType  = null;
            SerializedProperty script      = null;
            Object             scriptValue = null;


            for (int i = 0; i < customTypes.arraySize; i++)
            {
                customType  = customTypes.GetArrayElementAtIndex(i);
                script      = customType.FindPropertyRelative("script");
                scriptValue = script.objectReferenceValue;

                string displayName = scriptValue == null ? "Empty Custom Element" : scriptValue.name;

                //Draw header for the custom type
                EditorGUILayout.BeginHorizontal();
                {
                    GUIHelper.GetSerializedFoldout(customType, displayName);

                    if (GUILayout.Button("Delete", EditorStyles.miniButtonLeft))
                    {
                        settings.customTypes.RemoveAt(i);
                    }
                    else
                    if (GUILayout.Button("Add", EditorStyles.miniButtonRight))
                    {
                        settings.customTypes.Insert(i + 1, null);
                    }
                }
                EditorGUILayout.EndHorizontal();

                //Drwa all children afterwards
                if (customType.isExpanded)
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        SerializedPropertyUtility.DrawChildrenProperties(customType, false);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedSettings.ApplyModifiedProperties();
                        settings.customTypes[i].UpdateScriptType();
                    }
                }
            }
            EditorGUI.indentLevel--;
        }