Ejemplo n.º 1
0
        public static void CreateProject()
        {
            var obj  = Selection.activeObject;
            var path = ScriptTemplates.GetDirectoryFromAsset(obj);

            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";
            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);
            });

            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);
            ScriptTemplates.Create(path, projectName + ".asmdef", "00-asmdef", defines, allowRename: false);

            var guid = AssetDatabase.AssetPathToGUID(path + "/" + projectName + "Initializer.cs");

            if (string.IsNullOrEmpty(guid) == false)
            {
                ScriptTemplates.CreatePrefab(path, projectName + "Initializer", guid);
            }
        }
Ejemplo n.º 2
0
        public static void CreateProject()
        {
            var obj  = Selection.activeObject;
            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";
            }

            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, "Entities");
            ScriptTemplates.CreateEmptyDirectory(path, "Views");

            ScriptTemplates.Create(path, projectName + "State.cs", "00-StateTemplate", defines, allowRename: false);
            ScriptTemplates.Create(path, projectName + "Initializer.cs", "00-InitializerTemplate", 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(path, projectName + ".asmdef", "00-asmdef", defines, allowRename: false);

            var guid = AssetDatabase.AssetPathToGUID(path + "/" + projectName + "Initializer.cs");

            if (string.IsNullOrEmpty(guid) == false)
            {
                ScriptTemplates.CreatePrefab(path, projectName + "Initializer", guid);
            }
        }