void OnEnable()
 {
     _settings = ConstantsGeneratorEditor.LoadSettings();
 }
        public static void GenerateConstantsCode(ConstantsGeneratorSettings settings)
        {
            string filePath = string.Empty;
            foreach (var file in Directory.GetFiles(Application.dataPath, "*.cs", SearchOption.AllDirectories))
            {
                if (Path.GetFileNameWithoutExtension(file) == CONSTANTS_FILE_NAME)
                {
                    filePath = file;
                    break;
                }
            }
            if (string.IsNullOrEmpty(filePath))
            {
                string directory = EditorUtility.OpenFolderPanel("Choose location for " + CONSTANTS_FILE_NAME + ".cs", Application.dataPath, "");
                if (string.IsNullOrEmpty(directory))
                {
                    return;
                }

                filePath = Path.Combine(directory, CONSTANTS_FILE_NAME + ".cs");
            }

            using (var writer = new StreamWriter(filePath))
            {
                writer.WriteLine("// This file is auto-generated. Modifications are not saved.");
                writer.WriteLine("using UnityEngine;");
                writer.WriteLine();
                writer.WriteLine("namespace " + CONSTANTS_FILE_NAME);
                writer.WriteLine("{");

                foreach (ConstantCategory category in settings.Categories)
                {

                    writer.WriteLine("    /// <summary>");
                    writer.WriteLine("    ///Category '{0}'.", category.Name);
                    writer.WriteLine("    /// </summary>");
                    string safeCategoryName = MakeSafeForCode(category.Name);
                    writer.WriteLine("    public static class {0}", safeCategoryName);
                    if (category.Name != safeCategoryName)
                    {
                        category.Name = safeCategoryName;
                    }
                    writer.WriteLine("    {");
                    foreach (ConstantValuePair constanValuePair in category.Constants)
                    {
                        string safeForCodeKey = MakeSafeForCode(constanValuePair.Key);
                        writer.WriteLine("        /// <summary>");
                        writer.WriteLine("        /// {0} Value for key '{1}'.", constanValuePair.ValueType.ToString(), safeForCodeKey);
                        writer.WriteLine("        /// </summary>");

                        switch (constanValuePair.ValueType)
                        {
                            case eConstantValueType.String:
                                {
                                    writer.WriteLine("        public const string {0} = \"{1}\";", safeForCodeKey, constanValuePair.StringValue);
                                    break;
                                }
                            case eConstantValueType.Int:
                                {
                                    writer.WriteLine("        public const int {0} = {1};", safeForCodeKey, constanValuePair.IntValue);
                                    break;
                                }
                            case eConstantValueType.Float:
                                {
                                    writer.WriteLine("        public const float {0} = {1}f;", safeForCodeKey, constanValuePair.FloatValue);
                                    break;
                                }
                            case eConstantValueType.Color:
                                {
                                    writer.WriteLine("        public static Color {0} = new Color({1}f,{2}f,{3}f,{4}f);", safeForCodeKey,
                                        constanValuePair.ColorValue.r, constanValuePair.ColorValue.g,
                                        constanValuePair.ColorValue.b, constanValuePair.ColorValue.a);

                                    break;
                                }
                            case eConstantValueType.Vector3:
                                {
                                    writer.WriteLine("        public static Vector3 {0} = new Vector3({1}f,{2}f,{3}f);", safeForCodeKey,
                                        constanValuePair.Vector3Value.x, constanValuePair.Vector3Value.y, constanValuePair.Vector3Value.z);
                                    break;
                                }
                            case eConstantValueType.Vector2:
                                {
                                    writer.WriteLine("        public static Vector2 {0} = new Vector2({1}f,{2}f);", safeForCodeKey,
                                        constanValuePair.Vector3Value.x, constanValuePair.Vector3Value.y);
                                    break;
                                }
                        }

                        if (safeForCodeKey != constanValuePair.Key)
                        {
                            constanValuePair.Key = safeForCodeKey;
                        }
                    }
                    writer.WriteLine("    }");
                    writer.WriteLine();
                }

                if (settings.GenerateTags)
                {
                    writer.WriteLine("    public static class Tags");
                    writer.WriteLine("    {");
                    foreach (var tag in UnityEditorInternal.InternalEditorUtility.tags)
                    {
                        writer.WriteLine("        /// <summary>");
                        writer.WriteLine("        /// Name of tag '{0}'.", tag);
                        writer.WriteLine("        /// </summary>");
                        writer.WriteLine("        public const string {0} = \"{1}\";", MakeSafeForCode(tag), tag);
                    }
                    writer.WriteLine("    }");
                    writer.WriteLine();
                }

                if (settings.GenerateLayers)
                {
                    writer.WriteLine("    public static class Layers");
                    writer.WriteLine("    {");
                    for (int i = 0; i < 32; i++)
                    {
                        string layer = UnityEditorInternal.InternalEditorUtility.GetLayerName(i);
                        if (!string.IsNullOrEmpty(layer))
                        {
                            writer.WriteLine("        /// <summary>");
                            writer.WriteLine("        /// Index of layer '{0}'.", layer);
                            writer.WriteLine("        /// </summary>");
                            writer.WriteLine("        public const int {0} = {1};", MakeSafeForCode(layer), i);
                        }
                    }
                    writer.WriteLine();
                    for (int i = 0; i < 32; i++)
                    {
                        string layer = UnityEditorInternal.InternalEditorUtility.GetLayerName(i);
                        if (!string.IsNullOrEmpty(layer))
                        {
                            writer.WriteLine("        /// <summary>");
                            writer.WriteLine("        /// Bitmask of layer '{0}'.", layer);
                            writer.WriteLine("        /// </summary>");
                            writer.WriteLine("        public const int {0}Mask = 1 << {1};", MakeSafeForCode(layer), i);
                        }
                    }
                    writer.WriteLine("    }");
                    writer.WriteLine();
                }

                if (settings.GenerateScenes)
                {
                    writer.WriteLine("    public static class Scenes");
                    writer.WriteLine("    {");
                    int sceneIndex = 0;
                    foreach (var scene in EditorBuildSettings.scenes)
                    {
                        if (!scene.enabled)
                        {
                            continue;
                        }

                        var sceneName = Path.GetFileNameWithoutExtension(scene.path);

                        writer.WriteLine("        /// <summary>");
                        writer.WriteLine("        /// ID of scene '{0}'.", sceneName);
                        writer.WriteLine("        /// </summary>");
                        writer.WriteLine("        public const int {0} = {1};", MakeSafeForCode(sceneName), sceneIndex);

                        sceneIndex++;
                    }

                    sceneIndex = 0;
                    foreach (var scene in EditorBuildSettings.scenes)
                    {
                        if (!scene.enabled)
                        {
                            continue;
                        }

                        var sceneName = Path.GetFileNameWithoutExtension(scene.path);

                        writer.WriteLine("        /// <summary>");
                        writer.WriteLine("        /// Name of scene '{0}'.", sceneName);
                        writer.WriteLine("        /// </summary>");
                        writer.WriteLine("        public const string {0} = \"{1}\";", MakeSafeForCode(sceneName) + "Name", sceneName);

                        sceneIndex++;
                    }

                    writer.WriteLine("    }");
                    writer.WriteLine();
                }

                if (settings.GenerateSortingLayers)
                {
                    writer.WriteLine("    public static class SortingLayers");
                    writer.WriteLine("    {");
                    foreach (var layer in SortingLayer.layers)
                    {
                        writer.WriteLine("        /// <summary>");
                        writer.WriteLine("        /// ID of sorting layer '{0}'.", layer.name);
                        writer.WriteLine("        /// </summary>");
                        writer.WriteLine("        public const int {0} = {1};", MakeSafeForCode(layer.name), layer.id);
                    }
                    writer.WriteLine("    }");
                    writer.WriteLine();
                }

                writer.WriteLine("    public static class PlayerSettings");
                writer.WriteLine("    {");

                if (settings.GenerateBundleIdentifier)
                {
                    writer.WriteLine("        /// <summary>");
                    writer.WriteLine("        /// Bundle Identifier");
                    writer.WriteLine("        /// </summary>");
                    writer.WriteLine("        public const string BundleIdentifier = \"{0}\";", PlayerSettings.bundleIdentifier);
                }

                if (settings.GenerateBundleVersion)
                {
                    writer.WriteLine("        /// <summary>");
                    writer.WriteLine("        /// Bundle Version");
                    writer.WriteLine("        /// </summary>");
                    writer.WriteLine("        public const string BundleVersion = \"{0}\";", PlayerSettings.bundleVersion);
                }

                writer.WriteLine("    }");
                writer.WriteLine();

                writer.WriteLine("}");
                writer.WriteLine();
            }

            AssetDatabase.Refresh();
        }