Пример #1
0
        private static void CreateFeatureComplex_AfterCompilation()
        {
            var waitForCompilation = EditorPrefs.GetBool("Temp.EditorWaitCompilation.CreateFeatureComplex");

            if (waitForCompilation == true)
            {
                EditorPrefs.DeleteKey("Temp.EditorWaitCompilation.CreateFeatureComplex");

                var dir          = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Dir");
                var assetName    = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Name");
                var assetPath    = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.ScriptPath");
                var newAssetPath = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.NewScriptPath");

                AssetDatabase.MoveAsset(assetPath, newAssetPath);
                AssetDatabase.ImportAsset(newAssetPath, ImportAssetOptions.ForceSynchronousImport);

                var guid = AssetDatabase.AssetPathToGUID(newAssetPath);
                var defs = new Dictionary <string, string>()
                {
                    { "GUID", guid },
                };
                ScriptTemplates.Create(dir, assetName + "Feature.asset", "63-FeatureAsset", allowRename: false, customDefines: defs);

                ScriptTemplates.CreateEmptyDirectory(dir, "Modules");
                ScriptTemplates.CreateEmptyDirectory(dir, "Systems");
                ScriptTemplates.CreateEmptyDirectory(dir, "Components");
                ScriptTemplates.CreateEmptyDirectory(dir, "Markers");
                ScriptTemplates.CreateEmptyDirectory(dir, "Views");
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        public static void CreateFeatureComplex()
        {
            ScriptTemplates.Create("New Feature.cs", "61-FeatureTemplate", onCreated: (asset) => {
                var path      = ScriptTemplates.GetDirectoryFromAsset(asset);
                var assetName = asset.name;
                if (assetName.EndsWith("Feature") == true)
                {
                    assetName = assetName.Replace("Feature", string.Empty);
                }
                ScriptTemplates.CreateEmptyDirectory(path, assetName);
                var dir          = path + "/" + assetName;
                var newAssetPath = dir + "/" + assetName + "Feature.cs";

                EditorPrefs.SetBool("Temp.EditorWaitCompilation.CreateFeatureComplex", true);
                EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Dir", dir);
                EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Name", assetName);
                EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.ScriptPath", AssetDatabase.GetAssetPath(asset));
                EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.NewScriptPath", newAssetPath);

                //ScriptTemplates.CreateEmptyDirectory(dir, "Data");
                //ScriptTemplates.Create(dir + "/Data", "Feature" + assetName + "Data.cs", "62-FeatureData", allowRename: false);

                /*var featureName = assetName;
                 * var projectGuid = string.Empty;
                 * var projectPath = path.Replace("Assets/", "");
                 * var projectName = projectPath.Split('/')[0];
                 * var asmDefs = AssetDatabase.FindAssets("t:AssemblyDefinitionAsset");
                 * foreach (var asmGuid in asmDefs) {
                 *
                 *  var asmPath = AssetDatabase.GUIDToAssetPath(asmGuid);
                 *  var asm = AssetDatabase.LoadAssetAtPath<UnityEditorInternal.AssemblyDefinitionAsset>(asmPath);
                 *  if (asm.name == projectName) {
                 *
                 *      projectGuid = asmGuid;
                 *      break;
                 *
                 *  }
                 *
                 * }
                 *
                 * var defs = new Dictionary<string, string>() {
                 *  { "PROJECTNAME", featureName },
                 *  { "REFERENCES", @",""GUID:" + projectGuid + @"""" }
                 * };
                 * ScriptTemplates.Create(dir, featureName + ".asmdef", "00-asmdef", customDefines: defs, allowRename: false);
                 */
            });
        }
Пример #5
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);
        }
Пример #6
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");
        }
Пример #7
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");
        }
Пример #8
0
        private void CompileDefines(System.Collections.Generic.List <string> list)
        {
            var path = "Assets";
            var file = "csc.gen.rsp";

            var output = string.Empty;

            foreach (var d in list)
            {
                output += "-define:" + d + "\n";
            }

            var defines = new System.Collections.Generic.Dictionary <string, string>();

            {
                defines.Add("DEFINES", output);
            }
            ScriptTemplates.Create(path, file, "00-csc-gen.rsp", defines, allowRename: false);
        }
Пример #9
0
 public static void CreateMarker()
 {
     ScriptTemplates.Create("New Marker.cs", "51-MarkerTemplate");
 }
Пример #10
0
 public static void CreateComponentSharedCopyable()
 {
     ScriptTemplates.Create("New Shared Copyable Component.cs", "36-ComponentSharedCopyableTemplate");
 }
Пример #11
0
 public static void CreateComponentCopyable()
 {
     ScriptTemplates.Create("New Copyable Component.cs", "35-ComponentCopyableTemplate");
 }
Пример #12
0
 public static void CreateComponentShared()
 {
     ScriptTemplates.Create("New Shared Component.cs", "32-ComponentSharedTemplate");
 }
Пример #13
0
 public static void CreateComponentOnce()
 {
     ScriptTemplates.Create("New Component.cs", "41-ComponentOnceTemplate");
 }
Пример #14
0
 public static void CreateFeature()
 {
     ScriptTemplates.Create("New Feature.cs", "61-FeatureTemplate");
 }
Пример #15
0
 public static void CreateSystemFilter()
 {
     ScriptTemplates.Create("New System with Filter.cs", "12-SystemFilterTemplate");
 }
Пример #16
0
 public static void CreateSystem()
 {
     ScriptTemplates.Create("New System.cs", "11-SystemTemplate");
 }
Пример #17
0
 public static void CreateModule()
 {
     ScriptTemplates.Create("New Module.cs", "01-ModuleTemplate");
 }
Пример #18
0
 public static void CreateComponentSharedOnceRunnable()
 {
     ScriptTemplates.Create("New Shared Runnable Component.cs", "44-RunnableComponentOnceSharedTemplate");
 }
Пример #19
0
 public static void CreateComponentOnceRunnable()
 {
     ScriptTemplates.Create("New Runnable Component.cs", "43-RunnableComponentOnceTemplate");
 }
Пример #20
0
 public static void CreateComponent()
 {
     ScriptTemplates.Create("New Component.cs", "31-ComponentTemplate");
 }
Пример #21
0
 public static void CreateEntity()
 {
     ScriptTemplates.Create("New Entity.cs", "21-EntityTemplate");
 }
Пример #22
0
 public static void CreateStructCopyableComponent()
 {
     ScriptTemplates.Create("New Component.cs", "38-ComponentStructCopyableTemplate");
 }
Пример #23
0
 public static void CreateStructComponent()
 {
     ScriptTemplates.Create("New Struct Component.cs", "37-ComponentStructTemplate");
 }