Exemplo n.º 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");
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
                 */
            });
        }
Exemplo n.º 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);
        }
Exemplo n.º 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");
        }
Exemplo n.º 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");
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 public static void CreateFeature()
 {
     ScriptTemplates.Create("New Feature.cs", "61-FeatureTemplate");
 }
Exemplo n.º 10
0
 public static void CreateMarker()
 {
     ScriptTemplates.Create("New Marker.cs", "51-MarkerTemplate");
 }
Exemplo n.º 11
0
 public static void CreateComponentSharedCopyable()
 {
     ScriptTemplates.Create("New Shared Copyable Component.cs", "36-ComponentSharedCopyableTemplate");
 }
Exemplo n.º 12
0
 public static void CreateComponentCopyable()
 {
     ScriptTemplates.Create("New Copyable Component.cs", "35-ComponentCopyableTemplate");
 }
Exemplo n.º 13
0
 public static void CreateComponentOnce()
 {
     ScriptTemplates.Create("New Component.cs", "41-ComponentOnceTemplate");
 }
Exemplo n.º 14
0
 private static void OnScriptsReloaded()
 {
     ScriptTemplates.CreateFeatureComplex_AfterCompilation();
 }
Exemplo n.º 15
0
 public static void CreateComponent()
 {
     ScriptTemplates.Create("New Component.cs", "31-ComponentTemplate");
 }
Exemplo n.º 16
0
 public static void CreateSystemFilter()
 {
     ScriptTemplates.Create("New System with Filter.cs", "12-SystemFilterTemplate");
 }
Exemplo n.º 17
0
 public static void CreateSystem()
 {
     ScriptTemplates.Create("New System.cs", "11-SystemTemplate");
 }
Exemplo n.º 18
0
 public static void CreateModule()
 {
     ScriptTemplates.Create("New Module.cs", "01-ModuleTemplate");
 }
Exemplo n.º 19
0
 public static void CreateComponentSharedOnceRunnable()
 {
     ScriptTemplates.Create("New Shared Runnable Component.cs", "44-RunnableComponentOnceSharedTemplate");
 }
Exemplo n.º 20
0
 public static void CreateComponentOnceRunnable()
 {
     ScriptTemplates.Create("New Runnable Component.cs", "43-RunnableComponentOnceTemplate");
 }
Exemplo n.º 21
0
 public static void CreateStructComponent()
 {
     ScriptTemplates.Create("New Struct Component.cs", "37-ComponentStructTemplate");
 }
Exemplo n.º 22
0
 public static void CreateEntity()
 {
     ScriptTemplates.Create("New Entity.cs", "21-EntityTemplate");
 }
Exemplo n.º 23
0
 public static void CreateStructCopyableComponent()
 {
     ScriptTemplates.Create("New Component.cs", "38-ComponentStructCopyableTemplate");
 }
Exemplo n.º 24
0
 public static void CreateComponentShared()
 {
     ScriptTemplates.Create("New Shared Component.cs", "32-ComponentSharedTemplate");
 }