예제 #1
0
        public void Edit(StringBuilder builder, ILoaderParameter parameter, int tab_num, string[] paths)
        {
            var    tab          = StringBuilderHelper.SetTab(tab_num);
            string type_name    = parameter.GetTypeName();
            string method_name  = parameter.GetName();
            string method_after = string.Empty;

            if (string.IsNullOrEmpty(type_name))
            {
                type_name    = "T";
                method_name += "<T>";
                method_after = " where T : Object";
            }

            builder.AppendLine(string.Format("{0}public static {1} Load{2}({3} {4}){5}",
                                             tab,
                                             type_name,
                                             method_name,
                                             ResourcesLoaderCreateUtility.GetEnumName(parameter),
                                             LoadEditor.argumentName,
                                             method_after));

            builder.AppendLine(tab + "{");
            tab = StringBuilderHelper.SetTab(tab_num + 1);
            {
                builder.AppendLine(string.Format("{0}return Resources.Load<{1}> ({2} ({3}));",
                                                 tab,
                                                 type_name,
                                                 ResourcesLoaderCreateUtility.GetPathMethodName(parameter),
                                                 LoadEditor.argumentName));
            }
            tab = StringBuilderHelper.SetTab(tab_num);
            builder.AppendLine(tab + "}");
        }
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="option">オプション</param>
        public void Create(ResourcesLoaderCreateOption option)
        {
            var builder = new StringBuilder();

            var class_name = Path.GetFileNameWithoutExtension(option.createPath);

            var tab_num = 0;
            var tab     = StringBuilderHelper.SetTab(tab_num);

            // Using記述
            EditUsings(builder, tab);

            // 改行
            builder.AppendLine();

            // クラス定義開始
            builder.AppendLine(string.Format("{0}public static class {1}", tab, class_name));
            builder.AppendLine(tab + "{");
            {
                tab_num++;
                tab = StringBuilderHelper.SetTab(tab_num);

                // パラメーターごとに処理
                foreach (var parameter in parameters)
                {
                    builder.AppendLine(string.Format("#region {0}", parameter.GetName()));

                    // パス取得
                    var paths = ResourcesLoaderCreateUtility.GetPathsInResourcesFolder(parameter.GetTargetExtensions());
                    if (paths.Length == 0)
                    {
                        paths = new string[] { ResourcesLoaderCreateUtility.dummyPath };
                    }

                    // エディタごとに処理
                    foreach (var editor in editors)
                    {
                        editor.Edit(builder, parameter, tab_num, paths);
                        builder.AppendLine();
                    }

                    builder.AppendLine(string.Format("#endregion"));
                    builder.AppendLine();
                }

                tab_num--;
                tab = StringBuilderHelper.SetTab(tab_num);
            }
            builder.AppendLine(tab + "}");

            // スクリプト生成
            StringBuilderHelper.CreateScript(option.createPath + ".cs", builder.ToString(), true);
            StringBuilderHelper.RefreshEditor();
        }
예제 #3
0
 public void Edit(StringBuilder builder, ILoaderParameter parameter, int tab_num, string[] paths)
 {
     StringBuilderHelper.EditEnum(
         builder,
         ResourcesLoaderCreateUtility.GetEnumName(parameter),
         paths
         .Select(p => Path.GetFileNameWithoutExtension(p))
         .Select(p => StringBuilderHelper.ReplaceEnumInvaild(p))
         .ToArray(),
         1);
 }
예제 #4
0
        public void Edit(StringBuilder builder, ILoaderParameter parameter, int tab_num, string[] paths)
        {
            string tab = StringBuilderHelper.SetTab(tab_num);

            if (paths[0] != ResourcesLoaderCreateUtility.dummyPath)
            {
                paths = paths
                        .Select(p => p.Substring(p.IndexOf(PathArrayEditor.removeWord) + PathArrayEditor.removeWordLength))
                        .Select(p => p.Remove(p.LastIndexOf(".")))
                        .ToArray();
            }

            builder.AppendLine(string.Format("{0}private static readonly string[] {1} = new string[]",
                                             tab,
                                             ResourcesLoaderCreateUtility.GetPathArrayName(parameter)));

            builder.AppendLine(tab + "{");
            builder.AppendLine(StringBuilderHelper.JoinStrings(paths, tab_num + 1, ",\n", "\"", "\""));
            builder.AppendLine(tab + "};");
        }
예제 #5
0
        public void Edit(StringBuilder builder, ILoaderParameter parameter, int tab_num, string[] paths)
        {
            string tab = StringBuilderHelper.SetTab(tab_num);

            builder.AppendLine(string.Format("{0}public static string {1}({2} {3})",
                                             tab,
                                             ResourcesLoaderCreateUtility.GetPathMethodName(parameter),
                                             ResourcesLoaderCreateUtility.GetEnumName(parameter),
                                             argumentEnumName));

            builder.AppendLine(tab + "{");
            tab_num++;
            tab = StringBuilderHelper.SetTab(tab_num);
            {
                builder.AppendLine(string.Format("{0}return {1}[(int){2}];",
                                                 tab,
                                                 ResourcesLoaderCreateUtility.GetPathArrayName(parameter),
                                                 argumentEnumName));
            }
            tab_num--;
            tab = StringBuilderHelper.SetTab(tab_num);
            builder.AppendLine(tab + "}");
        }