diff --git a/src/CodeTemplates/RunnerExtended.cs.txt.meta b/package.json.meta similarity index 75% rename from src/CodeTemplates/RunnerExtended.cs.txt.meta rename to package.json.meta index b6d30aa..75ab06c 100644 --- a/src/CodeTemplates/RunnerExtended.cs.txt.meta +++ b/package.json.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3c196b8082fad1f4ea6038a881414ce4 +guid: fea6f5ebb9d0faa45ae5c702895a98ea TextScriptImporter: externalObjects: {} userData: diff --git a/src/CodeTemplates.meta b/src/CodeTemplates.meta deleted file mode 100644 index 3a33ef8..0000000 --- a/src/CodeTemplates.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7675bea928846c54d9eaefb0905778b9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/CodeTemplates/Component.cs.txt b/src/CodeTemplates/Component.cs.txt deleted file mode 100644 index 4c620c1..0000000 --- a/src/CodeTemplates/Component.cs.txt +++ /dev/null @@ -1,10 +0,0 @@ -using UnityEngine; -using DCFApixels.DragonECS; - -namespace #NAMESPACE# -{ - public struct #SCRIPTNAME# - { - // add your data here - } -} diff --git a/src/CodeTemplates/Component.cs.txt.meta b/src/CodeTemplates/Component.cs.txt.meta deleted file mode 100644 index 5776180..0000000 --- a/src/CodeTemplates/Component.cs.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: d8dcd63282111b24a94372328500c37a -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/CodeTemplates/ComponentExtended.cs.txt b/src/CodeTemplates/ComponentExtended.cs.txt deleted file mode 100644 index ef17f2a..0000000 --- a/src/CodeTemplates/ComponentExtended.cs.txt +++ /dev/null @@ -1,20 +0,0 @@ -using UnityEngine; -using DCFApixels.DragonECS; - -namespace #NAMESPACE# -{ - // setting the color of the visualization in the debug window - //[DebugHide] - [DebugColor(DebugColor.Red)] - public struct #SCRIPTNAME# : IEcsComponentReset<#SCRIPTNAME#> - { - // add your data here - public float value; - - public void Reset(ref #SCRIPTNAME# component) - { - // setting custom default values - value = 5f; - } - } -} diff --git a/src/CodeTemplates/ComponentExtended.cs.txt.meta b/src/CodeTemplates/ComponentExtended.cs.txt.meta deleted file mode 100644 index 18a5ee9..0000000 --- a/src/CodeTemplates/ComponentExtended.cs.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 3dd75a8f9967d9440bbe2dcc30168b2f -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/CodeTemplates/Runner.cs.txt b/src/CodeTemplates/Runner.cs.txt deleted file mode 100644 index f59c162..0000000 --- a/src/CodeTemplates/Runner.cs.txt +++ /dev/null @@ -1,20 +0,0 @@ -using DCFApixels.DragonECS; - -namespace #NAMESPACE# -{ - public interface I#SCRIPTNAME# : IEcsSystem - { - public void Do(); - } - - public class #SCRIPTNAME#Runner : EcsRunner, I#SCRIPTNAME# - { - public void Do() - { - foreach (var target in targets) - { - target.Do(); - } - } - } -} diff --git a/src/CodeTemplates/Runner.cs.txt.meta b/src/CodeTemplates/Runner.cs.txt.meta deleted file mode 100644 index dd937ef..0000000 --- a/src/CodeTemplates/Runner.cs.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 67fb4cee9fff4bc48a1a6009a762959c -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/CodeTemplates/RunnerExtended.cs.txt b/src/CodeTemplates/RunnerExtended.cs.txt deleted file mode 100644 index a662392..0000000 --- a/src/CodeTemplates/RunnerExtended.cs.txt +++ /dev/null @@ -1,48 +0,0 @@ -using UnityEngine; -using DCFApixels.DragonECS; -#if DEBUG -using Unity.Profiling; -#endif - -namespace #NAMESPACE# -{ - public interface I#SCRIPTNAME# : IEcsSystem - { - public void Do(); - } - - // setting the color of the visualization in the debug window - //[DebugHide] - [DebugColor(DebugColor.Red)] - public class #SCRIPTNAME#Runner : EcsRunner, I#SCRIPTNAME# - { - private ProfilerMarker[] _profilerMarkers; - - public void Do() - { - for (int i = 0; i < targets.Length; i++) - { -#if DEBUG - _profilerMarkers[i].Begin(); -#endif - targets[i].Do(); -#if DEBUG - _profilerMarkers[i].End(); -#endif - } - } - -#if DEBUG - // will be called after changing "targets" - protected override void OnSetup() - { - // create an array of profiler markers for each system in "targets" - _profilerMarkers = new ProfilerMarker[targets.Length]; - for (int i = 0; i < targets.Length; i++) - { - _profilerMarkers[i] = new ProfilerMarker(ProfilerCategory.Scripts, $"EcsRunner.{targets[i].GetType().Name}.{nameof(Do)}"); - } - } -#endif - } -} diff --git a/src/CodeTemplates/Startup.cs.txt b/src/CodeTemplates/Startup.cs.txt deleted file mode 100644 index c5a2818..0000000 --- a/src/CodeTemplates/Startup.cs.txt +++ /dev/null @@ -1,66 +0,0 @@ -using UnityEngine; -using DCFApixels.DragonECS; - -namespace #NAMESPACE# -{ - sealed class #SCRIPTNAME# : MonoBehaviour - { - private EcsDefaultWrold _world; - private EcsPipeline _pipeline; - - private void Start() - { - // is needed to integrate the internal debugging tool with the unity environment - UnityDebugService.Init(); - - _world = new EcsDefaultWrold(); - _pipeline = EcsPipeline.New() - // register your systems here, for example: - // .Add (new TestSystem1 ()) - // .Add (new TestSystem2 ()) - - // inject worlds here, for example: - .Inject(_world) - //.Inject(new EcsWorld()) - - // with Inject you can also inject other data, for example: - //.Inject(new SharedData()) -#if UNITY_EDITOR - // add debug system for this EcsPipeline here - .Add(new PipelineDebugSystem()) -#endif - .BuildAndInit(); - } - - private void Update() - { - _pipeline?.Run(); - } - - private void LateUpdate() - { - _pipeline?.LateRun(); - } - - private void FixedUpdate() - { - _pipeline?.FixedRun(); - } - - private void OnDestroy() - { - // don't forget to clear data - if (_pipeline != null) - { - _pipeline.Destroy(); - _pipeline = null; - } - - if (_world != null) - { - _world.Destroy(); - _world = null; - } - } - } -} \ No newline at end of file diff --git a/src/CodeTemplates/Startup.cs.txt.meta b/src/CodeTemplates/Startup.cs.txt.meta deleted file mode 100644 index 29c847c..0000000 --- a/src/CodeTemplates/Startup.cs.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 5af8205794231544eafe9b43c30c5d83 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/CodeTemplates/System.cs.txt b/src/CodeTemplates/System.cs.txt deleted file mode 100644 index 0327bd0..0000000 --- a/src/CodeTemplates/System.cs.txt +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using DCFApixels.DragonECS; - -namespace #NAMESPACE# -{ - public class #SCRIPTNAME# : IEcsRunSystem, IEcsInject - { - private EcsDefaultWrold _world; - public void Inject(EcsDefaultWrold obj) => _world = obj; - - public void Run(EcsPipeline pipeline) - { - // will be called on each EcsPipeline.Run() call - } - } -} diff --git a/src/CodeTemplates/System.cs.txt.meta b/src/CodeTemplates/System.cs.txt.meta deleted file mode 100644 index 110bc68..0000000 --- a/src/CodeTemplates/System.cs.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 3bbff7d1071aadf4f93df0a0fb6078e9 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/CodeTemplates/SystemExtended.cs.txt b/src/CodeTemplates/SystemExtended.cs.txt deleted file mode 100644 index e23c94b..0000000 --- a/src/CodeTemplates/SystemExtended.cs.txt +++ /dev/null @@ -1,55 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using DCFApixels.DragonECS; - -namespace #NAMESPACE# -{ - // setting the color of the visualization in the debug window - //[DebugHide] - [DebugColor(DebugColor.Red)] - public class #SCRIPTNAME# : - IEcsPreInitSystem, - IEcsInitSystem, - IEcsRunSystem, - IEcsLateRunSystem, - IEcsFixedRunSystem, - IEcsDestroySystem, - IEcsInject - { - private EcsDefaultWrold _world; - public void Inject(EcsDefaultWrold obj) => _world = obj; - - public void PreInit(EcsPipeline pipeline) - { - // will be called once during EcsPipeline.Init() call and before Init(EcsPipeline pipeline). - } - - public void Init(EcsPipeline pipeline) - { - // will be called once during EcsPipeline.Init() call and after PreInit(EcsPipeline pipeline). - } - - public void Run(EcsPipeline pipeline) - { - // will be called on each EcsPipeline.Run() call - } - - public void LateRun(EcsPipeline pipeline) - { - // will be called on each EcsPipeline.LateRun() call - } - - public void FixedRun(EcsPipeline pipeline) - { - // will be called on each EcsPipeline.FixedRun() call - } - - public void Destroy(EcsPipeline pipeline) - { - // will be called once during EcsPipeline.Destroy() call - } - - //Use Runners to implement additional messages - } -} diff --git a/src/CodeTemplates/SystemExtended.cs.txt.meta b/src/CodeTemplates/SystemExtended.cs.txt.meta deleted file mode 100644 index 3e800cd..0000000 --- a/src/CodeTemplates/SystemExtended.cs.txt.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: fab30d6906127c040a3cbb3bd17e05c6 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/CodeTemplates/TemplateGenerator.cs b/src/CodeTemplates/TemplateGenerator.cs deleted file mode 100644 index 4bdcee4..0000000 --- a/src/CodeTemplates/TemplateGenerator.cs +++ /dev/null @@ -1,158 +0,0 @@ -#if UNITY_EDITOR -using System; -using System.IO; -using System.Runtime.Versioning; -using System.Text; -using UnityEditor; -using UnityEditor.ProjectWindowCallback; -using UnityEngine; - -namespace DCFApixels.DragonECS.Editors -{ - public sealed class TemplateGenerator - { - private const int MENU_ITEM_PRIORITY = -198; - - private const string TITLE = EcsConsts.FRAMEWORK_NAME + " Template Generator"; - - private const string MENU_ITEM_PATH = "Assets/Create/" + EcsConsts.FRAMEWORK_NAME + "/"; - - private const string NAMESPACE_TAG = "#NAMESPACE#"; - private const string SCRIPTANAME_TAG = "#SCRIPTNAME#"; - - #region Properties - private static Texture2D ScriptIcon => EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D; - private static string GetCurrentFilePath([System.Runtime.CompilerServices.CallerFilePath] string fileName = null) - { - return Path.GetFullPath(Path.Combine(fileName, "../")); - } - private static string TemplatesPath => GetCurrentFilePath(); - #endregion - - #region GenerateMethods - [MenuItem(MENU_ITEM_PATH + "[CodeTemplate]Startup", false, MENU_ITEM_PRIORITY)] - public static void CreateSturtupScript() => CreateScript("Startup"); - - [MenuItem(MENU_ITEM_PATH + "[CodeTemplate]System", false, MENU_ITEM_PRIORITY)] - public static void CreateSystemSimpleScript() => CreateScript("System"); - - [MenuItem(MENU_ITEM_PATH + "[CodeTemplate]Component", false, MENU_ITEM_PRIORITY)] - public static void CreateComponentSimpleScript() => CreateScript("Component"); - - [MenuItem(MENU_ITEM_PATH + "[CodeTemplate]Runner", false, MENU_ITEM_PRIORITY)] - public static void CreateRunnerSimpleScript() => CreateScript("Runner"); - - [MenuItem(MENU_ITEM_PATH + "[CodeTemplate]System Extended", false, MENU_ITEM_PRIORITY)] - public static void CreateSystemScript() => CreateScript("SystemExtended"); - - [MenuItem(MENU_ITEM_PATH + "[CodeTemplate]Component Extended", false, MENU_ITEM_PRIORITY)] - public static void CreateComponentScript() => CreateScript("ComponentExtended"); - - [MenuItem(MENU_ITEM_PATH + "[CodeTemplate]Runner Extended", false, MENU_ITEM_PRIORITY)] - public static void CreateRunnerScript() => CreateScript("RunnerExtended"); - - - private static void CreateScript(string templateName) - { - CreateAndRenameAsset($"{GetAssetPath()}/Ecs{templateName}.cs", name => GenerateEndWrtieScript($"{templateName}.cs.txt", name)); - } - #endregion - - private static void GenerateEndWrtieScript(string templateFileName, string generatedFileName) - { - string script; - try - { - script = File.ReadAllText(Path.Combine(TemplatesPath, templateFileName)); - } - catch (Exception exception) - { - EditorUtility.DisplayDialog(TITLE, $"[ERROR] Template {templateFileName} cannot be read.\r\n{exception.Message}", "Close"); - return; - } - - var ns = EditorSettings.projectGenerationRootNamespace.Trim(); - if (string.IsNullOrEmpty(ns)) - { - ns = "Client"; - } - - script = script.Replace(NAMESPACE_TAG, ns); - script = script.Replace(SCRIPTANAME_TAG, NormalizeClassName(Path.GetFileNameWithoutExtension(generatedFileName))); - - try - { - File.WriteAllText(AssetDatabase.GenerateUniqueAssetPath(generatedFileName), script); - } - catch (Exception exception) - { - EditorUtility.DisplayDialog(TITLE, $"[ERROR] The result was not written to the file.\r\n{exception.Message}", "Close"); - return; - } - if (EditorPrefs.GetBool("kAutoRefresh")) AssetDatabase.Refresh(); - } - - private static string NormalizeClassName(string className) - { - StringBuilder result = new StringBuilder(); - bool isUpper = true; - foreach (var c in className) - { - if (char.IsLetterOrDigit(c)) - { - result.Append(isUpper ? char.ToUpperInvariant(c) : c); - isUpper = false; - } - else - { - isUpper = true; - } - } - return result.ToString(); - } - - private static string GetAssetPath() - { - var path = AssetDatabase.GetAssetPath(Selection.activeObject); - if (!string.IsNullOrEmpty(path) && AssetDatabase.Contains(Selection.activeObject)) - { - if (!AssetDatabase.IsValidFolder(path)) - { - path = Path.GetDirectoryName(path); - } - } - else - { - path = "Assets"; - } - return path; - } - - private static void CreateAndRenameAsset(string pathName, Action onSuccess) - { - var action = ScriptableObject.CreateInstance(); - action.Callback = onSuccess; - ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, action, pathName, ScriptIcon, null); - } - - #region Utils - private sealed class CustomEndNameAction : EndNameEditAction - { - [NonSerialized] - public Action Callback; - - public override void Action(int instanceId, string pathName, string resourceFile) - { - if (string.IsNullOrEmpty(pathName)) - { - EditorUtility.DisplayDialog(TITLE, "Invalid filename", "Close"); - return; - } - Callback?.Invoke(pathName); - } - } - #endregion - } -} -#endif - diff --git a/src/CodeTemplates/TemplateGenerator.cs.meta b/src/CodeTemplates/TemplateGenerator.cs.meta deleted file mode 100644 index 7ddaa6a..0000000 --- a/src/CodeTemplates/TemplateGenerator.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 98b537892f3da62409c7f6322323af10 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: