public void DrawField(Rect r, ImportAssetsWindow importAssetsWindow, NGRemoteHierarchyWindow hierarchy) { if (hierarchy.displayNonSuppported == false && this.importParameters.isSupported == false) { return; } //Rect r = GUILayoutUtility.GetRect(0F, Constants.SingleLineHeight); float x = r.x; float w = r.width; r.width = EditorGUIUtility.labelWidth; r.height = Constants.SingleLineHeight; if (this.children != null) { this.open = EditorGUI.Foldout(r, this.open, this.name, false); } else { EditorGUI.LabelField(r, this.name); } r.x += r.width; r.width = w - r.width; if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition) == true) { importAssetsWindow.selectedField = this; importAssetsWindow.Repaint(); } if (this.importParameters.finalized == true) { if (this.importParameters.finalObject != null) { EditorGUI.ObjectField(r, this.importParameters.finalObject, this.importParameters.realType, false); } else { EditorGUI.LabelField(r, "Null"); } } else { if (this.importParameters.isSupported == false) { EditorGUI.LabelField(r, "Not supported."); } else if (this.importParameters.importErrorMessage != null) { EditorGUI.HelpBox(r, "Import failed : " + this.importParameters.importErrorMessage, MessageType.Error); } else if (this.importParameters.ParametersConfirmed == true) { if (this.importParameters.totalBytes > 0) { if (importAssetsWindow.selectedField == this) { EditorGUI.LabelField(r, "Downloading"); } else { EditorGUI.LabelField(r, "Downloading (" + ((float)this.importParameters.bytesReceived / (float)this.importParameters.totalBytes * 100F).ToString("0.0") + "%)"); } importAssetsWindow.Repaint(); } else { EditorGUI.LabelField(r, "Waiting"); } } else { EditorGUI.LabelField(r, new GUIContent("Need attention /!\\", UtilityResources.WarningIcon)); } } if (importAssetsWindow.selectedField == this) { r.x = x + 3F; r.width = w - 3F; Rect r2 = r; r2.x -= 1F; r2.width = 5F; r2.height = 1F; EditorGUI.DrawRect(r2, Color.green); r.height += this.importParameters.GetHeight(); r2.height = r.height; r2.width = 1F; EditorGUI.DrawRect(r2, Color.green); r2.width = 5F; r2.y += r2.height; r2.height = 1F; EditorGUI.DrawRect(r2, Color.green); //r.height = r2.height - Constants.SingleLineHeight; r.y += Constants.SingleLineHeight; this.importParameters.DrawAssetImportParams(r, importAssetsWindow); } if (this.open == true) { r.xMin += 15F; r.y += r.height; //++EditorGUI.indentLevel; for (int i = 0; i < this.children.Count; i++) { r.height = this.children[i].GetHeight(importAssetsWindow, hierarchy); this.children[i].DrawField(r, importAssetsWindow, hierarchy); r.y += r.height; } //--EditorGUI.indentLevel; } }
public void DrawAssetImportParams(Rect r2, ImportAssetsWindow importAssetsWindow) { this.updateWindow = importAssetsWindow; //string gameObjectName = parameter.gameObjectName; //if (gameObjectName == null) // gameObjectName = parameter.gameObjectName = this.hierarchy.GetGameObjectName(parameter.gameObjectInstanceID); float w = r2.width; r2.height = Constants.SingleLineHeight; //Rect r2 = GUILayoutUtility.GetRect(22F, Constants.SingleLineHeight); bool canRemember = this.localAsset == null && this.isSupported == true; if (Event.current.type == EventType.MouseDown) { if (canRemember == true) { r2.width -= AssetImportParameters.RememberLabelWidth + AssetImportParameters.RememberSpacing + AssetImportParameters.LocationButtonWidth; } else { r2.width -= AssetImportParameters.LocationButtonWidth; } //if (r2.Contains(Event.current.mousePosition) == true) //{ // this.hierarchy.PingObject(this.gameObjectInstanceID); // Event.current.Use(); //} if (canRemember == true) { r2.width += AssetImportParameters.RememberLabelWidth + AssetImportParameters.RememberSpacing + AssetImportParameters.LocationButtonWidth; } else { r2.width += AssetImportParameters.LocationButtonWidth; } } GUI.Box(r2, string.Empty, GeneralStyles.Toolbar); //if (Event.current.type == EventType.Repaint) //{ // Rect r3 = r2; // r3.width = 1F; // r3.height = r3.height * 4F + 6F; // //EditorGUI.DrawRect(r3, Color.cyan); //} r2.width = ImportAssetsWindow.GameObjectIconWidth; GUI.DrawTexture(r2, AssetPreview.GetMiniTypeThumbnail(this.type), ScaleMode.ScaleToFit); r2.x += r2.width; string name = this.name ?? (this.name = this.hierarchy.GetResourceName(this.type, this.instanceID)); if (name == null) { GUI.Label(r2, GeneralStyles.StatusWheel); r2.x += r2.width; r2.width = w - r2.x; GUI.Label(r2, this.type.Name); importAssetsWindow.Repaint(); } else { r2.width = w - r2.x; GUI.Label(r2, this.type.Name + " : " + this.name); } r2.x = r2.width + ImportAssetsWindow.GameObjectIconWidth - AssetImportParameters.RememberLabelWidth - AssetImportParameters.RememberSpacing - AssetImportParameters.LocationButtonWidth; r2.width = AssetImportParameters.RememberLabelWidth; if (canRemember == true) { this.remember = GUI.Toggle(r2, this.remember, "Remember", GeneralStyles.ToolbarToggle); } r2.x += r2.width + AssetImportParameters.RememberSpacing; r2.width = AssetImportParameters.LocationButtonWidth; if (GUI.Button(r2, "Locations (" + this.originPath.Count + ")", GeneralStyles.ToolbarButton) == true) { PopupWindow.Show(r2, new AssetLocationsWindow(this.hierarchy, this.originPath)); //importAssets2.importingAssetsParams.Remove(this); } r2.y += r2.height + 2F; r2.x = 5F; r2.width = w - r2.x; using (LabelWidthRestorer.Get(120F)) { int pathsCount = this.originPath.Count; //if (pathsCount == 1) // EditorGUI.LabelField(r2, "Component Path", this.originPath[0]); //else if (pathsCount > 1) //{ // EditorGUI.LabelField(r2, "Component Path", string.Empty); // r2.xMin += EditorGUIUtility.labelWidth; // if (GUI.Button(r2, "Many (" + pathsCount + ")", GeneralStyles.ToolbarDropDown) == true) // { // } // r2.xMin -= EditorGUIUtility.labelWidth; //} r2.y += /*r2.height + */ 2F; if (this.localAsset != null) { EditorGUI.ObjectField(r2, "Asset", this.localAsset, this.type, false); } else if (this.isSupported == false) { r2.height = 24F; r2.xMin += 5F; r2.xMax -= 5F; EditorGUI.HelpBox(r2, "Not supported.", MessageType.Warning); } else { bool hasError = this.importMode == ImportMode.None; //EditorGUILayout.BeginHorizontal(); { using (LabelWidthRestorer.Get(100F)) { if (pathsCount > 0) { EditorGUI.BeginDisabledGroup(this.parametersConfirmed == true); { //r2.width = 182F/* - EditorGUI.indentLevel * 15F*/; this.importMode = (ImportMode)EditorGUI.EnumPopup(r2, "Import Mode", this.importMode); r2.y += r2.height; } EditorGUI.EndDisabledGroup(); } //EditorGUILayout.BeginVertical(); { EditorGUI.BeginDisabledGroup(this.parametersConfirmed == true); { if (this.importMode == ImportMode.Auto) { if (this.name == null) { this.name = this.hierarchy.GetResourceName(this.type, this.instanceID); } if (this.autoPath == null && this.name != null) { IObjectImporter importer = RemoteUtility.GetImportAssetTypeSupported(this.type); if (importer != null) { string path = this.prefabPath; string filename = string.Join("_", this.name.Split(Path.GetInvalidFileNameChars())) + importer.GetExtension(); if (string.IsNullOrEmpty(this.hierarchy.specificSharedSubFolder) == false) { path = this.hierarchy.specificSharedSubFolder; } //if (this.hierarchy.rawCopyAssetsToSubFolder == true) // path += "/" + .gameObjectName; //else if (this.hierarchy.prefixAsset == true) // filename = string.Join("_", (parameter.gameObjectName).Split(Path.GetInvalidFileNameChars())) + '_' + filename; this.autoPath = path + "/" + filename; } } if (/*parameter.gameObjectName != null && */ this.name != null) { if (this.autoPath == null) { r2.height = 24F; hasError = true; EditorGUI.HelpBox(r2, "Asset type is not supported, will not be imported.", MessageType.Warning); r2.y += r2.height; } else { EditorGUI.BeginChangeCheck(); this.autoPath = NGEditorGUILayout.SaveFileField(r2, "Output Path", this.autoPath); if (EditorGUI.EndChangeCheck() == true) { Uri pathUri; bool isValidUri = Uri.TryCreate(this.autoPath, UriKind.Relative, out pathUri); bool v = isValidUri && pathUri != null /* && pathUri.IsLoopback*/; //FileInfo fi = null; //try //{ // fi = new FileInfo(parameter.autoPath); //} //catch (System.ArgumentException) { } //catch (PathTooLongException) { } //catch (System.NotSupportedException) { } if (v == false) { //if (ReferenceEquals(fi, null)) this.autoPathError = "Path is invalid."; } // file name is not valid else { this.autoPathError = null; } // file name is valid... May check for existence by calling fi.Exists. } r2.y += r2.height; if (string.IsNullOrEmpty(this.autoPathError) == false) { r2.height = 24F; EditorGUI.HelpBox(r2, this.autoPathError, MessageType.Error); r2.y += r2.height; } } } else { Utility.content.text = "Waiting for server..."; EditorGUI.LabelField(r2, Utility.content, GeneralStyles.StatusWheel); r2.y += r2.height; importAssetsWindow.Repaint(); } } else if (this.importMode == ImportMode.UseGUID) { EditorGUI.BeginChangeCheck(); Object o = EditorGUI.ObjectField(r2, "Asset", this.guidAsset, this.type, false); if (EditorGUI.EndChangeCheck() == true) { this.guidAsset = o; this.guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(o)); } r2.y += r2.height; EditorGUI.LabelField(r2, "GUID", this.guid ?? "None"); r2.y += r2.height; if (string.IsNullOrEmpty(this.guid) == true) { hasError = true; } } else if (this.importMode == ImportMode.RawCopy) { EditorGUI.BeginChangeCheck(); string path = NGEditorGUILayout.SaveFileField(r2, "Output Path", this.outputPath); if (EditorGUI.EndChangeCheck() == true) { if (path.StartsWith(Application.dataPath) == true) { this.outputPath = path.Substring(Application.dataPath.Length - "Assets".Length); } else if (path.StartsWith("Assets") == true) { this.outputPath = path; } } r2.y += r2.height; if (string.IsNullOrEmpty(path) == false && path.StartsWith(Application.dataPath) == false && path.StartsWith("Assets") == false) { hasError = true; r2.height = 24F; EditorGUI.HelpBox(r2, "Path must be in Assets folder.", MessageType.Warning); r2.y += r2.height; } } } EditorGUI.EndDisabledGroup(); r2.y += 2F; r2.height = Constants.SingleLineHeight; if (this.parametersConfirmed == true) { if (this.importErrorMessage != null) { r2.xMin += 5F; r2.height = 32F; EditorGUI.HelpBox(r2, "Import failed : " + this.importErrorMessage, MessageType.Error); } else if (this.copyAsset != null && (this.importMode == ImportMode.RawCopy || this.importMode == ImportMode.Auto)) { EditorGUI.ObjectField(r2, "Created Asset", this.copyAsset, this.type, false); } else if (this.totalBytes > 0) { r2.xMin += 5F; if (this.bytesReceived == this.totalBytes) { EditorGUI.ProgressBar(r2, 1F, "Creating asset..."); } else { float rate = (float)this.bytesReceived / (float)this.totalBytes; string cacheFileSize; if (this.totalBytes >= 1024 * 1024) { cacheFileSize = ((float)(this.bytesReceived / (1024F * 1024F))).ToString("N1") + " / " + ((float)(this.totalBytes / (1024F * 1024F))).ToString("N1") + " MiB"; } else if (this.totalBytes >= 1024) { cacheFileSize = ((float)(this.bytesReceived / 1024F)).ToString("N1") + " / " + ((float)(this.totalBytes / 1024F)).ToString("N1") + " KiB"; } else { cacheFileSize = this.bytesReceived + " / " + this.totalBytes + " B"; } EditorGUI.ProgressBar(r2, rate, cacheFileSize + " (" + (rate * 100F).ToString("0.0") + "%)"); importAssetsWindow.Repaint(); } } } else { EditorGUI.BeginDisabledGroup(hasError); { r2.width = 100F; r2.x = w - r2.width - 10F; if (GUI.Button(r2, "Confirm") == true) { this.Confirm(); importAssetsWindow.Repaint(); } } EditorGUI.EndDisabledGroup(); } } } if (Conf.DebugMode != Conf.DebugState.None && this.importErrorMessage != null && GUI.Button(r2, "Retry Import") == true) { this.ResetImport(); } } } } }