private void AutoImport(GenesisSettings settings)
        {
            if (!EditorUtility.DisplayDialog(
                    "Genesis - Auto Import",
                    "Auto Import will automatically find and set all plugins for you. It will search in folders and sub folders specified " +
                    "under the key 'Genesis.SearchPaths'.\n\nThis will overwrite your current plugin settings.\n\nDo you want to continue?",
                    "Continue and Overwrite",
                    "Cancel"))
            {
                return;
            }

            var searchPaths = CodeGeneratorTools.BuildSearchPaths(
                _codeGeneratorConfig.SearchPaths,
                new []
            {
                "./Assets",
                "./Library/ScriptAssemblies"
            });

            CodeGeneratorTools.AutoImport(_codeGeneratorConfig, searchPaths);

            EditorUtility.SetDirty(settings);

            Initialize(settings);

            _codeGeneratorConfig.PreProcessors  = _availablePreProcessorTypes;
            _codeGeneratorConfig.DataProviders  = _availableDataProviderTypes;
            _codeGeneratorConfig.CodeGenerators = _availableGeneratorTypes;
            _codeGeneratorConfig.PostProcessors = _availablePostProcessorTypes;
        }
        private static void SetTypesAndNames <T>(
            ICodeGenerationPlugin[] instances,
            out string[] availableTypes,
            out string[] availableNames)
            where T : ICodeGenerationPlugin
        {
            var orderedInstancesOf = CodeGeneratorTools.GetOrderedInstancesOf <T>(instances);

            availableTypes = orderedInstancesOf.Select(instance => instance.GetType().ToCompilableString()).ToArray();
            availableNames = orderedInstancesOf.Select(instance => instance.Name).ToArray();
        }
        public CodeGeneratorSettingsDrawer()
        {
            _codeGeneratorConfig = new CodeGeneratorConfig();

            // Add per plugin interface type preferences.
            var instances = CodeGeneratorTools.LoadFromPlugins();

            SetTypesAndNames <IPreProcessor>(instances, out _availablePreProcessorTypes, out _availablePreProcessorNames);
            SetTypesAndNames <IDataProvider>(instances, out _availableDataProviderTypes, out _availableDataProviderNames);
            SetTypesAndNames <ICodeGenerator>(instances, out _availableGeneratorTypes, out _availableGeneratorNames);
            SetTypesAndNames <IPostProcessor>(instances, out _availablePostProcessorTypes, out _availablePostProcessorNames);
        }
Esempio n. 4
0
        /// <summary>
        /// Generates code from all passed <see cref="GenesisSettings"/> assets in <paramref name="settingsData"/>
        /// </summary>
        /// <param name="settingsData"></param>
        private static void Generate(GenesisSettings[] settingsData)
        {
            LOGGER.Info("Generating...");
            var didSucceed = true;

            try
            {
                EditorApplication.LockReloadAssemblies();
                AssetDatabase.StartAssetEditing();

                for (var i = 0; i < settingsData.Length; i++)
                {
                    var settings       = settingsData[i];
                    var codeGenerator  = CodeGeneratorTools.CodeGeneratorFromPreferences(settings);
                    var progressOffset = 0.0f;
                    codeGenerator.OnProgress += (title, info, progress) =>
                    {
                        if (!EditorUtility.DisplayCancelableProgressBar(title, info, progressOffset + progress / 2f))
                        {
                            return;
                        }

                        codeGenerator.Cancel();
                    };

                    try
                    {
                        if (GenesisPreferences.ExecuteDryRun)
                        {
                            codeGenerator.DryRun();
                        }

                        progressOffset = 0.5f;
                        codeGenerator.Generate();
                    }
                    catch (Exception ex)
                    {
                        LOGGER.Error(ex, string.Format(EditorConstants.CODE_GENERATION_UPDATE_ERROR_FORMAT, settings.name));

                        didSucceed = false;
                        EditorUtility.DisplayDialog("Code Generation Error", ex.Message, "Ok");
                    }

                    EditorUtility.ClearProgressBar();
                }
            }
            catch (Exception ex)
            {
                LOGGER.Error(ex, EditorConstants.CODE_GENERATION_UPDATE_ERROR);
                didSucceed = false;
            }
            finally
            {
                AssetDatabase.StopAssetEditing();
                EditorApplication.UnlockReloadAssemblies();
                EditorUtility.ClearProgressBar();
            }

            if (didSucceed)
            {
                LOGGER.Info(EditorConstants.CODE_GENERATION_SUCCESS);
            }
            else
            {
                LOGGER.Warn(EditorConstants.CODE_GENERATION_FAILURE);
            }

            AssetDatabase.Refresh();
        }