Exemple #1
0
        private void TypePane()
        {
            if (selectedType < 0)
            {
                return;
            }

            var style = EditorStyle.Get;

            var typeListItem = types[selectedType];
            var type         = typeListItem.type;

            typePaneScrollPos = EditorGUILayout.BeginScrollView(typePaneScrollPos, style.area);

            GUILayout.Label(typeListItem.name, style.subheading);
            GUILayout.Label(typeListItem.namespaceName);

            EditorGUILayout.BeginVertical(style.area);

            bool   hasParameterlessConstructor = ES3Reflection.HasParameterlessConstructor(type);
            string path = GetOutputPath(types[selectedType].type);

            // An ES3Type file already exists.
            if (File.Exists(path))
            {
                if (hasParameterlessConstructor)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Reset to Default"))
                    {
                        SelectNone(true, true);
                        AssetDatabase.MoveAssetToTrash("Assets" + path.Remove(0, Application.dataPath.Length));
                        SelectType(selectedType);
                    }
                    if (GUILayout.Button("Edit ES3Type Script"))
                    {
                        UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path, 1);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to modify the ES3Type script to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
                    if (GUILayout.Button("Click here to edit the ES3Type script"))
                    {
                        UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path, 1);
                    }
                    if (GUILayout.Button("Reset to Default"))
                    {
                        SelectAll(true, true);
                        File.Delete(path);
                        AssetDatabase.Refresh();
                    }
                }
            }
            // No ES3Type file and no fields.
            else if (fields.Length == 0)
            {
                if (!hasParameterlessConstructor)
                {
                    EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to create an ES3Type script and modify it to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
                }

                if (GUILayout.Button("Create ES3Type Script"))
                {
                    Generate();
                }
            }
            // No ES3Type file, but fields are selectable.
            else
            {
                if (!hasParameterlessConstructor)
                {
                    EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to select the fields you wish to serialize below, and then modify the generated ES3Type script to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
                    if (GUILayout.Button("Select all fields and generate ES3Type script"))
                    {
                        SelectAll(true, false);
                        Generate();
                    }
                }
            }

            EditorGUILayout.EndVertical();

            PropertyPane();

            EditorGUILayout.EndScrollView();
        }