コード例 #1
0
        protected virtual void LayoutProfileInitialization()
        {
            EditorGUILayout.LabelField("Initialize Mod Profile");

            // ---[ DISPLAY ]---
            EditorGUILayout.Space();

            if (GUILayout.Button("Create New"))
            {
                EditorApplication.delayCall += () =>
                {
                    ScriptableModProfile smp = this.target as ScriptableModProfile;
                    Undo.RecordObject(smp, "Initialize Mod Profile");

                    smp.modId = 0;
                    smp.editableModProfile = new EditableModProfile();

                    OnDisable();
                    OnEnable();
                    isRepaintRequired = true;
                };
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("---- OR ----");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Load Existing Profile");

            if (user == null)
            {
                EditorGUILayout.HelpBox("Log in required to load existing mods",
                                        MessageType.Info);
                if (GUILayout.Button("Log In to mod.io"))
                {
                    LoginWindow.GetWindow <LoginWindow>("Login to mod.io");
                }
            }
            else if (modOptions.Length > 0)
            {
                using (new EditorGUI.DisabledScope(isModListLoading))
                {
                    modInitializationOptionIndex = EditorGUILayout.Popup("Select Mod", modInitializationOptionIndex, modOptions);
                    if (GUILayout.Button("Load"))
                    {
                        ModProfile profile = modList[modInitializationOptionIndex];
                        EditorApplication.delayCall += () =>
                        {
                            ScriptableModProfile smp = this.target as ScriptableModProfile;
                            Undo.RecordObject(smp, "Initialize Mod Profile");

                            smp.modId = profile.id;
                            smp.editableModProfile = EditableModProfile.CreateFromProfile(profile);

                            string smpFilePath = AssetDatabase.GetAssetPath(smp);
                            string smpDir      = Path.GetDirectoryName(smpFilePath);

                            int profileCount
                                = LocalDataStorage.GetFiles(smpDir, profile.name + "*.asset", false).Count;

                            string fileNameAddition = (profileCount > 0
                                                       ? " (" + profileCount.ToString() + ")"
                                                       : "");

                            AssetDatabase.RenameAsset(smpFilePath, profile.name + fileNameAddition + ".asset");

                            OnDisable();
                            OnEnable();
                            isRepaintRequired = true;
                        };
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("No loadable mod profiles detected.",
                                        MessageType.Info);
            }
        }
コード例 #2
0
        private void ModProfileSubmissionSucceeded(ModProfile updatedProfile,
                                                   string profileFilePath)
        {
            if (updatedProfile == null)
            {
                isAwaitingServerResponse = false;
                return;
            }


            uploadFailedMessage = null;

            // Update ScriptableModProfile
            profile.modId = updatedProfile.id;
            profile.editableModProfile = EditableModProfile.CreateFromProfile(updatedProfile);
            EditorUtility.SetDirty(profile);
            AssetDatabase.SaveAssets();

            // Upload Build
            #if UPLOAD_MOD_BINARY_AS_DIRECTORY
            if (Directory.Exists(buildFilePath))
            #else
            if (File.Exists(buildFilePath))
            #endif
            {
                Action <WebRequestError> onSubmissionFailed = (e) =>
                {
                    EditorUtility.DisplayDialog("Upload Failed",
                                                "Failed to upload the mod build to the server.\n"
                                                + e.displayMessage,
                                                "Close");

                    uploadFailedMessage = e.displayMessage;
                    if (e.fieldValidationMessages != null &&
                        e.fieldValidationMessages.Count > 0)
                    {
                        foreach (var kvp in e.fieldValidationMessages)
                        {
                            uploadFailedMessage += "\n [" + kvp.Key + "]: " + kvp.Value;
                        }
                    }

                    isAwaitingServerResponse = false;
                    Repaint();
                };

                #if UPLOAD_MOD_BINARY_AS_DIRECTORY
                ModManager.UploadModBinaryDirectory(profile.modId,
                                                    buildProfile,
                                                    buildFilePath,
                                                    true,
                                                    mf => NotifySubmissionSucceeded(updatedProfile.name,
                                                                                    updatedProfile.profileURL),
                                                    onSubmissionFailed);
                #else
                ModManager.UploadModBinary_Unzipped(profile.modId,
                                                    buildProfile,
                                                    buildFilePath,
                                                    true,
                                                    mf => NotifySubmissionSucceeded(updatedProfile.name,
                                                                                    updatedProfile.profileURL),
                                                    onSubmissionFailed);
                #endif
            }
            else
            {
                NotifySubmissionSucceeded(updatedProfile.name, updatedProfile.profileURL);
            }
        }