Exemple #1
0
        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
            }
        }
Exemple #2
0
        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
        }