static string[] initPhase<T>(out string[] availableTypes, out string[] availableNames) where T : ICodeGeneratorInterface {
            var instances = UnityCodeGenerator
                .GetTypes<T>()
                .Where(type => !type.IsAbstract)
                .Select(type => (T)Activator.CreateInstance(type));

            if(typeof(T) == typeof(ICodeGenFilePostProcessor)) {
                instances = instances
                    .OrderBy(instance => ((ICodeGenFilePostProcessor)instance).priority);
            } else {
                instances = instances
                    .OrderBy(instance => instance.name);
            }

            availableTypes = instances
                .Select(instance => instance.GetType().FullName)
                .ToArray();

            availableNames = instances
                .Select(instance => instance.name)
                .ToArray();

            return instances
                .Where(instance => instance.isEnabledByDefault)
                .Select(instance => instance.GetType().FullName)
                .ToArray();
        }
 void drawGenerateButton() {
     var bgColor = GUI.backgroundColor;
     GUI.backgroundColor = Color.green;
     if(GUILayout.Button("Generate", GUILayout.Height(32))) {
         UnityCodeGenerator.Generate();
     }
     GUI.backgroundColor = bgColor;
 }
Exemple #3
0
 static void drawGenerateButton()
 {
     EditorGUILayout.Space();
     if (GUILayout.Button("Generate"))
     {
         UnityCodeGenerator.Generate();
     }
 }
        void drawCodeGenerators()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Code Generators", EditorStyles.boldLabel);

            var enabledCodeGenerators = new HashSet <string>(_codeGeneratorConfig.enabledCodeGenerators);

            var availableGeneratorNames = new HashSet <string>();

            EntitasEditorLayout.BeginHorizontal();
            {
                var rect = EntitasEditorLayout.BeginVertical();
                if (rect.height > 0)
                {
                    _generatorsRectHeight = rect.height - 2;
                }
                {
                    foreach (var codeGenerator in _codeGenerators)
                    {
                        availableGeneratorNames.Add(codeGenerator.Name);
                        var isEnabled = enabledCodeGenerators.Contains(codeGenerator.Name);
                        isEnabled = EditorGUILayout.Toggle(codeGenerator.Name.Replace("Generator", string.Empty), isEnabled);
                        if (isEnabled)
                        {
                            enabledCodeGenerators.Add(codeGenerator.Name);
                        }
                        else
                        {
                            enabledCodeGenerators.Remove(codeGenerator.Name);
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();

                var bgColor = GUI.backgroundColor;
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Generate", GUILayout.Width(200), GUILayout.Height(_generatorsRectHeight)))
                {
                    UnityCodeGenerator.Generate();
                }
                GUI.backgroundColor = bgColor;
            }
            EntitasEditorLayout.EndHorizontal();

            foreach (var generatorName in _codeGeneratorConfig.enabledCodeGenerators.ToArray())
            {
                if (!availableGeneratorNames.Contains(generatorName))
                {
                    enabledCodeGenerators.Remove(generatorName);
                }
            }

            var sortedCodeGenerators = enabledCodeGenerators.ToArray();

            Array.Sort(sortedCodeGenerators);
            _codeGeneratorConfig.enabledCodeGenerators = sortedCodeGenerators;
        }
        void drawCodeGenerators()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Code Generators", EditorStyles.boldLabel);

            var enabledCodeGenerators = new HashSet <string>(_codeGeneratorConfig.enabledCodeGenerators);

            var availableGeneratorNames = new HashSet <string>();

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.BeginVertical();
                {
                    foreach (var codeGenerator in _codeGenerators)
                    {
                        availableGeneratorNames.Add(codeGenerator.Name);
                        var isEnabled = enabledCodeGenerators.Contains(codeGenerator.Name);
                        isEnabled = EditorGUILayout.Toggle(codeGenerator.Name, isEnabled);
                        if (isEnabled)
                        {
                            enabledCodeGenerators.Add(codeGenerator.Name);
                        }
                        else
                        {
                            enabledCodeGenerators.Remove(codeGenerator.Name);
                        }
                    }
                }
                EditorGUILayout.EndVertical();

                if (GUILayout.Button("Generate", GUILayout.Width(200), GUILayout.Height(68)))
                {
                    UnityCodeGenerator.Generate();
                }
            }
            EditorGUILayout.EndHorizontal();

            foreach (var generatorName in _codeGeneratorConfig.enabledCodeGenerators.ToArray())
            {
                if (!availableGeneratorNames.Contains(generatorName))
                {
                    enabledCodeGenerators.Remove(generatorName);
                }
            }

            var sortedCodeGenerators = enabledCodeGenerators.ToArray();

            Array.Sort(sortedCodeGenerators);
            _codeGeneratorConfig.enabledCodeGenerators = sortedCodeGenerators;
        }
        public void Initialize(EntitasPreferencesConfig config)
        {
            _codeGenerators = UnityCodeGenerator.GetCodeGenerators();
            var codeGeneratorNames = _codeGenerators.Select(cg => cg.Name).ToArray();

            _codeGeneratorConfig = new CodeGeneratorConfig(config, codeGeneratorNames);

            _pools = new List <string>(_codeGeneratorConfig.pools);

            _poolList = new UnityEditorInternal.ReorderableList(_pools, typeof(string), true, true, true, true);
            _poolList.drawHeaderCallback  = rect => EditorGUI.LabelField(rect, "Custom Pools");
            _poolList.drawElementCallback = (rect, index, isActive, isFocused) => {
                rect.width   -= 20;
                _pools[index] = EditorGUI.TextField(rect, _pools[index]);
            };
            _poolList.onAddCallback       = list => list.list.Add("New Pool");
            _poolList.onCanRemoveCallback = list => true;
            _poolList.onChangedCallback   = list => GUI.changed = true;
        }
Exemple #7
0
        static string[] initPhase <T>(out string[] availableTypes, out string[] availableNames) where T : ICodeGeneratorInterface
        {
            var instances = UnityCodeGenerator
                            .GetTypes <T>()
                            .Where(type => !type.IsAbstract)
                            .Select(type => (T)Activator.CreateInstance(type))
                            .OrderBy(instance => instance.name);

            availableTypes = instances
                             .Select(instance => instance.GetType().Name)
                             .ToArray();

            availableNames = instances
                             .Select(instance => instance.name)
                             .ToArray();

            return(instances
                   .Where(instance => instance.isEnabledByDefault)
                   .Select(instance => instance.GetType().Name)
                   .ToArray());
        }
        void drawCodeGenerators()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Code Generators", EditorStyles.boldLabel);

            var enabledCodeGeneratorsMask = 0;

            for (int i = 0; i < _availableGeneratorNames.Length; i++)
            {
                if (_codeGeneratorConfig.enabledCodeGenerators.Contains(_availableGeneratorNames[i]))
                {
                    enabledCodeGeneratorsMask += (1 << i);
                }
            }

            enabledCodeGeneratorsMask = EditorGUILayout.MaskField("Code Generators", enabledCodeGeneratorsMask, _availableGeneratorNames);

            var enabledCodeGenerators = new List <string>();

            for (int i = 0; i < _availableGeneratorNames.Length; i++)
            {
                var index = 1 << i;
                if ((index & enabledCodeGeneratorsMask) == index)
                {
                    enabledCodeGenerators.Add(_availableGeneratorNames[i]);
                }
            }

            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("Generate", GUILayout.Height(32)))
            {
                UnityCodeGenerator.Generate();
            }
            GUI.backgroundColor = bgColor;

            _codeGeneratorConfig.enabledCodeGenerators = enabledCodeGenerators.ToArray();
        }
Exemple #9
0
        public void Draw(EntitasPreferencesConfig config)
        {
            EntitasEditorLayout.BeginVerticalBox();
            {
                EditorGUILayout.LabelField("Code Generator", EditorStyles.boldLabel);

                drawGeneratedFolderPath();
                drawContexts();

                _codeGeneratorConfig.dataProviders  = drawMaskField("Data Providers", _availableDataProviderTypes, _availableDataProviderNames, _codeGeneratorConfig.dataProviders);
                _codeGeneratorConfig.codeGenerators = drawMaskField("Code Generators", _availableGeneratorTypes, _availableGeneratorNames, _codeGeneratorConfig.codeGenerators);
                _codeGeneratorConfig.postProcessors = drawMaskField("Post Processors", _availablePostProcessorTypes, _availablePostProcessorNames, _codeGeneratorConfig.postProcessors);

                var bgColor = GUI.backgroundColor;
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Generate", GUILayout.Height(32)))
                {
                    UnityCodeGenerator.Generate();
                }
                GUI.backgroundColor = bgColor;
            }
            EntitasEditorLayout.EndVertical();
        }