void OnSelectImageClicked()
        {
            long ThumbnailLimitBytes = 5 * 1024 * 1024; // 5 MBs

            string path = EditorUtility.OpenFilePanel("Select thumbnail", "", "jpg,jpeg,png");

            if (path.Length == 0)
            {
                return;
            }

            FileInfo fileInfo = new FileInfo(path);

            if (fileInfo.Length > ThumbnailLimitBytes)
            {
                //[TODO] Just show the error without using the middleware?
                store.Dispatch(new OnErrorAction()
                {
                    errorMsg = $"Max. file size {SharePackageUtils.FormatBytes((ulong)ThumbnailLimitBytes)}"
                });
                return;
            }
            SharePackageUtils.SetThumbnailPath(path);
            SetupImage("imgThumbnail", path);
        }
 static void UpdateHeader()
 {
     gameTitle = SharePackageUtils.GetFilteredGameTitle(gameTitle);
     SetupLabel("lblProjectName", gameTitle, new SharePackageUtils.LeftClickManipulator(OnLinkLabelClick));
     SetupLabel("lblUserEmail", string.Format("By {0}", CloudProjectSettings.userName));
     SetupImage("imgThumbnail", SharePackageUtils.GetThumbnailPath());
 }
        void RebuildFrontend()
        {
            if (currentShareStep != store.state.shareState.step)
            {
                currentShareStep = store.state.shareState.step;
            }

            bool loggedOut = (currentShareStep == ShareStep.Login);

            if (loggedOut)
            {
                LoadTab(TAB_NOT_LOGGED_IN);
                return;
            }

            bool buildIsUnavailable = !SharePackageUtils.LastBuildIsValid();

            if (buildIsUnavailable)
            {
                LoadTab(TAB_NO_BUILD);
                return;
            }

            string projectUrl = store.state.shareState.url;

            if (!string.IsNullOrEmpty(projectUrl))
            {
                LoadTab(TAB_SUCCESS);
                return;
            }

            string errorMsg = store.state.shareState.errorMsg;

            if (!string.IsNullOrEmpty(errorMsg))
            {
                LoadTab(TAB_ERROR);
                return;
            }

            if (currentShareStep == ShareStep.Upload)
            {
                LoadTab(TAB_UPLOADING);
                return;
            }

            if (currentShareStep == ShareStep.Process)
            {
                LoadTab(TAB_PROCESSING);
                return;
            }

            LoadTab(TAB_UPLOAD);
        }
Exemple #4
0
        private static void CopyThumbnail(Store <AppState> store)
        {
            var buildOutputDir    = SharePackageUtils.GetBuildOutputDirectory();
            var thumbnailDestPath = Path.Combine(buildOutputDir, thumbnail);

            File.Delete(thumbnailDestPath);

            string thumbnailDir = SharePackageUtils.GetThumbnailPath();

            if (string.IsNullOrEmpty(thumbnailDir))
            {
                return;
            }

            FileUtil.CopyFileOrDirectory(thumbnailDir, thumbnailDestPath);
        }
Exemple #5
0
        public void OnPostprocessBuild(BuildReport report)
        {
            if (report.summary.platform != BuildTarget.WebGL)
            {
                return;
            }

            string buildOutputDir = report.summary.outputPath;
            string buildGUID      = report.summary.guid.ToString();

            SharePackageUtils.SetEditorPreference("buildOutputDir", buildOutputDir);
            SharePackageUtils.SetEditorPreference("buildGUID", buildGUID);

            StoreFactory.Get().Dispatch(new BuildFinishAction
            {
                outputDir = buildOutputDir,
                buildGUID = buildGUID
            });

            WriteMetadataFile(report.summary.outputPath);
        }
Exemple #6
0
        private static void ZipAndShare(string title, Store <AppState> store)
        {
            store.Dispatch(new TitleChangeAction {
                title = title
            });

            if (!SharePackageUtils.LastBuildIsValid())
            {
                store.Dispatch(new OnErrorAction {
                    errorMsg = "Please build project first!"
                });
                return;
            }

            string buildOutputDir = SharePackageUtils.GetBuildOutputDirectory();

            if (!Zip(store, buildOutputDir))
            {
                return;
            }
            store.Dispatch(new UploadStartAction());
        }
        void OnShareClicked()
        {
            if (!SharePackageUtils.LastBuildIsValid() && !SharePackageUtils.WasBuildWarningDisplayed())
            {
                bool userWantsToBuild = DisplayDialogWindow
                                        (
                    "Are you sure?",
                    "Building the game may take several minutes, and the editor will not respond to any input in the meanwhile. Are you sure you want to build the game now?",
                    "Yes!",
                    "Not really"
                                        );
                if (!userWantsToBuild)
                {
                    return;
                }
            }

            if (!ModuleManagerProxy.IsBuildPlatformInstalled(BuildTarget.WebGL))
            {
                bool userWantsToInstallWebGL = DisplayDialogWindow
                                               (
                    "Missing Build Platform",
                    "Your Unity Editor does not have the WebGL module installed. Therefore, it is not possible to make a WebGL build.\nWould you like to install it now?",
                    "Yes!",
                    "Not really"
                                               );

                if (userWantsToInstallWebGL)
                {
                    SharePackageUtils.TellUnityHubToInstallWebGL();
                }
                return;
            }
            store.Dispatch(new ShareStartAction()
            {
                title = gameTitle
            });
        }
        void SetupUploadTab()
        {
            SetupButton("btnShare", OnShareClicked, true);
            SetupButton("btnSelectImage", OnSelectImageClicked, true);
            SetupImage("imgThumbnail", SharePackageUtils.GetThumbnailPath());

            TextField txtProjectName = root.Query <TextField>("txtProjectName");

            txtProjectName.RegisterValueChangedCallback(OnGameTitleChanged);
            txtProjectName.value = gameTitle;

            if (SharePackageUtils.LastBuildIsValid())
            {
                string lastOutputDirectory = SharePackageUtils.GetBuildOutputDirectory();
                SetupLabel(
                    "lblLastBuildInfo",
                    $"Last build located at {lastOutputDirectory}, created {File.GetLastWriteTime(lastOutputDirectory)}"
                    );
                return;
            }

            //[NOTE]: you should never get here
            SetupLabel("lblLastBuildInfo", "No previous build available...");
        }
Exemple #9
0
        private static bool Zip(Store <AppState> store, string buildOutputDir)
        {
            var projectDir = Directory.GetParent(Application.dataPath).FullName;
            var destPath   = Path.Combine(projectDir, zipName);

            File.Delete(destPath);

            CopyThumbnail(store);

            ZipFile.CreateFromDirectory(buildOutputDir, destPath);
            FileInfo fileInfo = new FileInfo(destPath);

            if (fileInfo.Length > ZipFileLimitBytes)
            {
                store.Dispatch(new OnErrorAction {
                    errorMsg = $"Max. allowed WebGL game .zip size is {SharePackageUtils.FormatBytes(ZipFileLimitBytes)}."
                });
                return(false);
            }
            store.Dispatch(new ZipPathChangeAction {
                zipPath = destPath
            });
            return(true);
        }
 public void OnBeforeAssemblyReload()
 {
     SharePackageUtils.SaveStateToSessionState();
 }
 void OnGameTitleChanged(ChangeEvent <string> changeEvent)
 {
     gameTitle = SharePackageUtils.GetFilteredGameTitle(changeEvent.newValue);
 }
Exemple #12
0
        private static void Upload(Store <AppState> store)
        {
            var token = UnityConnectSession.instance.GetAccessToken();

            if (token.Length == 0)
            {
                CheckLoginStatus(store);
                return;
            }

            var path      = store.state.shareState.zipPath;
            var title     = string.IsNullOrEmpty(store.state.shareState.title) ? "Untitled" : store.state.shareState.title;
            var buildGUID = SharePackageUtils.GetBuildGUID();

            var baseUrl      = GetAPIBaseUrl();
            var projectId    = GetProjectId();
            var formSections = new List <IMultipartFormSection>();

            formSections.Add(new MultipartFormDataSection("title", title));

            if (buildGUID.Length > 0)
            {
                formSections.Add(new MultipartFormDataSection("buildGUID", buildGUID));
            }

            if (projectId.Length > 0)
            {
                formSections.Add(new MultipartFormDataSection("projectId", projectId));
            }

            formSections.Add(new MultipartFormFileSection("file",
                                                          File.ReadAllBytes(path), Path.GetFileName(path), "application/zip"));

            uploadRequest = UnityWebRequest.Post(baseUrl + uploadEndpoint, formSections);
            uploadRequest.SetRequestHeader("Authorization", $"Bearer {token}");
            uploadRequest.SetRequestHeader("X-Requested-With", "XMLHTTPREQUEST");

            var op = uploadRequest.SendWebRequest();

            EditorCoroutineUtility.StartCoroutineOwnerless(UpdateProgress(store, uploadRequest));

            op.completed += operation =>
            {
                if (uploadRequest.isNetworkError || uploadRequest.isHttpError)
                {
                    if (uploadRequest.error != "Request aborted")
                    {
                        store.Dispatch(new OnErrorAction {
                            errorMsg = "Internal server error"
                        });
                    }
                }
                else
                {
                    var response = JsonUtility.FromJson <UploadResponse>(op.webRequest.downloadHandler.text);
                    if (!string.IsNullOrEmpty(response.key))
                    {
                        store.Dispatch(new QueryProgressAction {
                            key = response.key
                        });
                    }
                }
            };
        }