mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
Merge branch 'dev'
This commit is contained in:
commit
8e400eebed
24
package.json
Normal file
24
package.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "com.dcfa_pixels.dragonecs-unity",
|
||||||
|
"author":
|
||||||
|
{
|
||||||
|
"name": "DCFApixels",
|
||||||
|
"url": "https://github.com/DCFApixels-Unity"
|
||||||
|
},
|
||||||
|
"displayName": "DragonECS-Unity",
|
||||||
|
"description": "Integration with Unity for DragonECS",
|
||||||
|
"unity": "2020.3",
|
||||||
|
"version": "0.3.0",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/DCFApixels/DCFApixels-Unity.git"
|
||||||
|
},
|
||||||
|
"keywords":
|
||||||
|
[
|
||||||
|
"ecs",
|
||||||
|
"dragonecs",
|
||||||
|
"extension",
|
||||||
|
"add-on",
|
||||||
|
"unity"
|
||||||
|
]
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 3c196b8082fad1f4ea6038a881414ce4
|
guid: fea6f5ebb9d0faa45ae5c702895a98ea
|
||||||
TextScriptImporter:
|
TextScriptImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 7675bea928846c54d9eaefb0905778b9
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -1,10 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using DCFApixels.DragonECS;
|
|
||||||
|
|
||||||
namespace #NAMESPACE#
|
|
||||||
{
|
|
||||||
public struct #SCRIPTNAME#
|
|
||||||
{
|
|
||||||
// add your data here
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: d8dcd63282111b24a94372328500c37a
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 3dd75a8f9967d9440bbe2dcc30168b2f
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -1,20 +0,0 @@
|
|||||||
using DCFApixels.DragonECS;
|
|
||||||
|
|
||||||
namespace #NAMESPACE#
|
|
||||||
{
|
|
||||||
public interface I#SCRIPTNAME# : IEcsSystem
|
|
||||||
{
|
|
||||||
public void Do();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class #SCRIPTNAME#Runner : EcsRunner<I#SCRIPTNAME#>, I#SCRIPTNAME#
|
|
||||||
{
|
|
||||||
public void Do()
|
|
||||||
{
|
|
||||||
foreach (var target in targets)
|
|
||||||
{
|
|
||||||
target.Do();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 67fb4cee9fff4bc48a1a6009a762959c
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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#>, 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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<EventWorld>())
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 5af8205794231544eafe9b43c30c5d83
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -1,18 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using DCFApixels.DragonECS;
|
|
||||||
|
|
||||||
namespace #NAMESPACE#
|
|
||||||
{
|
|
||||||
public class #SCRIPTNAME# : IEcsRunSystem, IEcsInject<EcsDefaultWrold>
|
|
||||||
{
|
|
||||||
private EcsDefaultWrold _world;
|
|
||||||
public void Inject(EcsDefaultWrold obj) => _world = obj;
|
|
||||||
|
|
||||||
public void Run(EcsPipeline pipeline)
|
|
||||||
{
|
|
||||||
// will be called on each EcsPipeline.Run() call
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 3bbff7d1071aadf4f93df0a0fb6078e9
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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<EcsDefaultWrold>
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: fab30d6906127c040a3cbb3bd17e05c6
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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<string> onSuccess)
|
|
||||||
{
|
|
||||||
var action = ScriptableObject.CreateInstance<CustomEndNameAction>();
|
|
||||||
action.Callback = onSuccess;
|
|
||||||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, action, pathName, ScriptIcon, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Utils
|
|
||||||
private sealed class CustomEndNameAction : EndNameEditAction
|
|
||||||
{
|
|
||||||
[NonSerialized]
|
|
||||||
public Action<string> 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
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 98b537892f3da62409c7f6322323af10
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Reference in New Issue
Block a user