public static bool Validate() { // Validation try { var selectedGameObjects = Selection.gameObjects; if (selectedGameObjects.Length == 0) { throw new VCIValidatorException(ValidationErrorType.GameObjectNotSelected); } if (2 <= selectedGameObjects.Length) { throw new VCIValidatorException(ValidationErrorType.MultipleSelection); } var vciObject = selectedGameObjects[0].GetComponent <VCIObject>(); if (vciObject == null) { throw new VCIValidatorException(ValidationErrorType.VCIObjectNotAttached); } VCIValidator.ValidateVCIObject(vciObject); } catch (VCIValidatorException e) { var title = $"Error{(int)e.ErrorType}"; var text = ""; if (string.IsNullOrEmpty(e.Message)) { text = VCIConfig.GetText($"error{(int)e.ErrorType}"); } else { text = e.Message; } text = text.Replace("\\n", Environment.NewLine); if (e.ErrorType == ValidationErrorType.InvalidCharacter) { EditorGUILayout.HelpBox(e.Message, MessageType.Warning); } EditorUtility.DisplayDialog(title, text, "OK"); GUIUtility.ExitGUI(); return(false); } return(true); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(_scriptProp); // Version EditorGUI.BeginDisabledGroup(true); if (string.IsNullOrEmpty(_target.Meta.exporterVersion)) { _target.Meta.exporterVersion = VCIVersion.VERSION; } SetMetaPropertyField(_metaProp, "exporterVersion"); EditorGUI.EndDisabledGroup(); EditorGUILayout.Space(); // Information EditorGUILayout.LabelField("Information", EditorStyles.boldLabel); SetMetaPropertyField(_metaProp, "title"); SetMetaPropertyField(_metaProp, "version"); SetMetaPropertyField(_metaProp, "author"); SetMetaPropertyField(_metaProp, "contactInformation"); SetMetaPropertyField(_metaProp, "reference"); // Thumbnail SetMetaPropertyField(_metaProp, "thumbnail"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); _thumbnailProp.objectReferenceValue = (Texture2D)EditorGUILayout.ObjectField( _thumbnailProp.objectReferenceValue, typeof(Texture2D), false, GUILayout.Width(100), GUILayout.Height(100)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); // Description SetMetaPropertyField(_metaProp, "description"); EditorGUILayout.Space(); // License SetMetaPropertyField(_metaProp, "modelDataLicenseType"); SetMetaPropertyField(_metaProp, "modelDataOtherLicenseUrl"); EditorGUILayout.Space(); SetMetaPropertyField(_metaProp, "scriptLicenseType"); SetMetaPropertyField(_metaProp, "scriptOtherLicenseUrl"); EditorGUILayout.Space(); // Script settings SetMetaPropertyField(_metaProp, "scriptWriteProtected"); SetMetaPropertyField(_metaProp, "scriptEnableDebugging"); EditorGUILayout.Space(); if (_target.Scripts.Any()) { if (_target.Scripts[0].name != "main") { EditorGUILayout.HelpBox("The first script must be named \"main\".", MessageType.Warning); } var empties = _target.Scripts.Where(x => string.IsNullOrEmpty(x.name)); if (empties.Any()) { EditorGUILayout.HelpBox("Some have no script name.", MessageType.Warning); } var duplicates = _target.Scripts.GroupBy(script => script.name) .Where(n => n.Count() > 1) .Select(group => group.Key).ToList(); if (duplicates.Any()) { EditorGUILayout.HelpBox("Duplicate script name.", MessageType.Warning); } var invalidChars = Path.GetInvalidFileNameChars().Concat(new[] { '.' }).ToArray(); foreach (var script in _target.Scripts) { if (script.name.IndexOfAny(invalidChars) >= 0) { EditorGUILayout.HelpBox("Contains characters that can not be used as scriptName. " + script.name, MessageType.Warning); } } } // vci scripts EditorGUILayout.PropertyField(_vciScriptProp, true); serializedObject.ApplyModifiedProperties(); EditorGUILayout.Space(); // Export Button if (GUILayout.Button(VCIConfig.GetText("validate_button"), GUILayout.MinHeight(32))) { try { var rootGameObject = GameObjectSelectionService.GetSingleSelectedObject(); VCIValidator.ValidateVCIRequirements(rootGameObject); EditorUtility.DisplayDialog("Result", VCIConfig.GetText("no_error"), "OK"); } catch (VCIValidatorException e) { VCIValidationErrorDialog.ShowErrorDialog(e); GUIUtility.ExitGUI(); } } EditorGUILayout.Space(); // Export Button if (GUILayout.Button(VCIConfig.GetText("export_button"), GUILayout.MinHeight(32))) { #if UNITY_EDITOR_WIN VCIObjectExporterMenu.ExportObject(); #endif } }
public static void ExportObject() { #if UNITY_STANDALONE_WIN && UNITY_EDITOR EditorApplication.isPlaying = false; var rootGameObject = default(GameObject); try { rootGameObject = GameObjectSelectionService.GetSingleSelectedObject(); VCIValidator.ValidateVCIRequirements(rootGameObject); } catch (VCIValidatorException e) { VCIValidationErrorDialog.ShowErrorDialog(e); GUIUtility.ExitGUI(); return; } try { // save dialog var path = VCI.FileDialogForWindows.SaveDialog("Save " + VCIVersion.EXTENSION, rootGameObject.name + VCIVersion.EXTENSION); //var path = EditorUtility.SaveFilePanel( // "Save " + VCIVersion.EXTENSION, // null, // root.name + VCIVersion.EXTENSION, // VCIVersion.EXTENSION.Substring(1)); if (string.IsNullOrEmpty(path)) { return; } var bytes = ExportVci(rootGameObject); File.WriteAllBytes(path, bytes); if (path.StartsWithUnityAssetPath()) { AssetDatabase.ImportAsset(path.ToUnityRelativePath()); AssetDatabase.Refresh(); } // Show the file in the explorer. if (VCIConfig.IsOpenDirectoryAfterExport && Application.platform == RuntimePlatform.WindowsEditor) { System.Diagnostics.Process.Start("explorer.exe", " /e,/select," + path.Replace("/", "\\")); } } catch (Exception ex) { Debug.LogError(ex); } finally { // TODO: ツールバーからExport VCIを行うとExitGUIExceptionが飛ぶため、いったん握りつぶす try { GUIUtility.ExitGUI(); } catch { } } #else Debug.LogError("this function works only on Windows"); #endif }