void displayImportButton(bool isUserLoggedIn, bool modelIsAvailable) { string buttonText; if (!isUserLoggedIn) { buttonText = "You need to log in to download models"; GUI.enabled = false; } else if (modelIsAvailable) { buttonText = "Download model"; if (_currentModel.archiveSize > 0) { buttonText += " (" + Utils.humanifyFileSize(_currentModel.archiveSize) + ")"; } } else { buttonText = "Model not yet available"; } Color old = GUI.color; GUI.color = SketchfabUI.SKFB_BLUE; GUILayout.FlexibleSpace(); string htmlCaption = "<color=" + Color.white + ">" + buttonText + "</color>"; if (GUILayout.Button(htmlCaption, _ui.getSketchfabBigButton(), GUILayout.Height(64), GUILayout.Width(450))) { onImportModelClick(); } GUI.enabled = true; GUILayout.FlexibleSpace(); GUI.color = old; GUI.enabled = true; }
void displayImportSettings() { bool modelIsAvailable = _currentModel.archiveSize > 0; GUI.enabled = modelIsAvailable; GUILayout.BeginVertical("Box"); _ui.displayContent("Import into"); GUILayout.BeginHorizontal(); GUILayout.Label(GLTFUtils.getPathProjectFromAbsolute(_importDirectory), GUILayout.Height(18)); GUILayout.FlexibleSpace(); if (GUILayout.Button("Change", GUILayout.Width(80), GUILayout.Height(18))) { string newImportDir = EditorUtility.OpenFolderPanel("Choose import directory", Application.dataPath, ""); if (GLTFUtils.isFolderInProjectDirectory(newImportDir)) { _importDirectory = newImportDir; } else if (newImportDir != "") { EditorUtility.DisplayDialog("Error", "Please select a path within your current Unity project (with Assets/)", "Ok"); } else { // Path is empty, user canceled. Do nothing } } GUILayout.EndHorizontal(); _ui.displayContent("Options"); GUILayout.BeginHorizontal(); GUILayout.Label("Prefab name"); _prefabName = GUILayout.TextField(_prefabName, GUILayout.Width(200)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); _addToCurrentScene = GUILayout.Toggle(_addToCurrentScene, "Add to current scene"); GUILayout.BeginHorizontal(); Color old = GUI.color; GUI.color = SketchfabUI.SKFB_BLUE; GUI.contentColor = Color.white; GUILayout.FlexibleSpace(); string buttonCaption = ""; if (!_window._logger.isUserLogged()) { buttonCaption = "You need to be logged in to download assets"; GUI.enabled = false; } else if (modelIsAvailable) { buttonCaption = "<b>Download model</b> (" + Utils.humanifyFileSize(_currentModel.archiveSize) + ")"; } else { buttonCaption = "Model not yet available"; } buttonCaption = "<color=" + Color.white + ">" + buttonCaption + "</color>"; if (GUILayout.Button(buttonCaption, _ui.getSketchfabBigButton(), GUILayout.Height(64), GUILayout.Width(450))) { if (!assetAlreadyExists() || EditorUtility.DisplayDialog("Override asset", "The asset " + _prefabName + " already exists in project. Do you want to override it ?", "Override", "Cancel")) { // Reuse if still valid if (_currentModel.tempDownloadUrl.Length > 0 && EditorApplication.timeSinceStartup - _currentModel.downloadRequestTime < _currentModel.urlValidityDuration) { requestArchive(_currentModel.tempDownloadUrl); } else { fetchGLTFModel(_currentModel.uid, OnArchiveUpdate, _window._logger.getHeader()); } } } GUI.enabled = true; GUILayout.FlexibleSpace(); GUI.color = old; GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.EndVertical(); }