Exemplo n.º 1
0
        internal static void Create(string fileName, string templateName, System.Collections.Generic.Dictionary <string, string> customDefines = null, bool allowRename = true, System.Action <Object> onCreated = null)
        {
            var obj  = ScriptTemplates.GetSelectedDirectory();
            var path = AssetDatabase.GetAssetPath(obj);

            if (System.IO.File.Exists(path) == true)
            {
                path = System.IO.Path.GetDirectoryName(path);
            }

            if (string.IsNullOrEmpty(path) == true)
            {
                path = "Assets/";
            }

            ScriptTemplates.Create(path, fileName, templateName, customDefines, allowRename, onCreated);
        }
Exemplo n.º 2
0
        public static void CreateSystemFilter()
        {
            var obj = ScriptTemplates.GetSelectedDirectory();

            if (obj != null)
            {
                if (ScriptTemplates.GetFeature(obj, out var featureName) == true)
                {
                    ScriptTemplates.Create("New System with Filter.cs", "12-SystemFilterFeatureTemplate", new Dictionary <string, string>()
                    {
                        { "FEATURE", featureName },
                    });
                    return;
                }
            }

            ScriptTemplates.Create("New System with Filter.cs", "12-SystemFilterTemplate");
        }
Exemplo n.º 3
0
        public static void CreateModule()
        {
            var obj = ScriptTemplates.GetSelectedDirectory();

            if (obj != null)
            {
                if (ScriptTemplates.GetFeature(obj, out var featureName) == true)
                {
                    ScriptTemplates.Create("New Module.cs", "01-ModuleFeatureTemplate", new Dictionary <string, string>()
                    {
                        { "FEATURE", featureName },
                    });
                    return;
                }
            }

            ScriptTemplates.Create("New Module.cs", "01-ModuleTemplate");
        }
Exemplo n.º 4
0
        public static void CreateProject()
        {
            var obj  = ScriptTemplates.GetSelectedDirectory();
            var path = ScriptTemplates.GetDirectoryFromAsset(obj);

            if (System.IO.Directory.GetFiles(path).Length > 0)
            {
                Debug.LogError($"Directory {path} is not empty! Target directory should be empty to start project initialization.");
                return;
            }

            var projectName = System.IO.Path.GetFileName(path);

            projectName = projectName.Replace(".", "");
            projectName = projectName.Replace(" ", "");
            projectName = projectName.Replace("_", "");
            var stateName = projectName + "State";
            var defines   = new Dictionary <string, string>()
            {
                { "STATENAME", stateName }, { "PROJECTNAME", projectName }
            };

            ScriptTemplates.CreateEmptyDirectory(path, "Modules");
            ScriptTemplates.CreateEmptyDirectory(path, "Systems");
            ScriptTemplates.CreateEmptyDirectory(path, "Components");
            ScriptTemplates.CreateEmptyDirectory(path, "Markers");
            ScriptTemplates.CreateEmptyDirectory(path, "Features");
            ScriptTemplates.CreateEmptyDirectory(path, "Views");
            ScriptTemplates.CreateEmptyDirectory(path, "Generator");

            ScriptTemplates.Create(path, projectName + "State.cs", "00-StateTemplate", defines, allowRename: false);
            ScriptTemplates.Create(path, "AssemblyInfo.cs", "00-AssemblyInfo", defines, allowRename: false);

            ScriptTemplates.CreateEmptyDirectory(path + "/Generator", "gen");
            var definesGen = defines.ToDictionary(x => x.Key, x => x.Value);

            definesGen["PROJECTNAME"] = projectName + ".gen";
            ScriptTemplates.Create(path, projectName + ".asmdef", "00-asmdef", defines, allowRename: false);
            var refGuid = AssetDatabase.AssetPathToGUID(path + "/" + projectName + ".asmdef");

            definesGen.Add("REFERENCES", @",""GUID:" + refGuid + @"""");
            ScriptTemplates.Create(path + "/Generator", projectName + ".gen.asmdef", "00-asmdef", definesGen, allowRename: false);
            ScriptTemplates.Create(path + "/Generator", projectName + "Initializer.cs", "00-InitializerTemplate", defines, allowRename: false, onCreated: (asset) => {
                var assetPath = AssetDatabase.GetAssetPath(asset);
                var meta      = assetPath + ".meta";
                var text      = System.IO.File.ReadAllText(meta);
                text          = text.Replace("icon: {instanceID: 0}", "icon: {fileID: 2800000, guid: 16b72cc483a6c4dbda2dc209982c422c, type: 3}");
                System.IO.File.WriteAllText(meta, text);
                AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);

                var guid = AssetDatabase.AssetPathToGUID(path + "/Generator/" + projectName + "Initializer.cs");
                if (string.IsNullOrEmpty(guid) == false)
                {
                    ScriptTemplates.CreatePrefab(path, projectName + "Initializer", guid);
                }
            });
            ScriptTemplates.Create(path + "/Generator", "csc.rsp", "00-csc.rsp", defines, allowRename: false);

            ScriptTemplates.Create(path, "Modules/FPSModule.cs", "00-FPSModuleTemplate", defines, allowRename: false);
            ScriptTemplates.Create(path, "Modules/NetworkModule.cs", "00-NetworkModuleTemplate", defines, allowRename: false);
            ScriptTemplates.Create(path, "Modules/StatesHistoryModule.cs", "00-StatesHistoryModuleTemplate", defines, allowRename: false);

            ScriptTemplates.Create(path, "csc.rsp", "00-csc.rsp", defines, allowRename: false);
            ScriptTemplates.Create("Assets", "csc.gen.rsp", "00-csc-gen-default.rsp", defines, allowRename: false);
        }