Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 5d285e3

Browse files
committed
refactor(UnityAdapter): Update namespaces and types to use Lunar.Core.Base and Lunar.Core.ECS
1 parent 295b060 commit 5d285e3

14 files changed

+53
-39
lines changed

Runtime/Adapters/DebugLogAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using UnityEngine;
3-
using ILogger = Lunar.Interfaces.ILogger;
3+
using ILogger = Lunar.Core.Base.Interfaces.ILogger;
44
using Object = UnityEngine.Object;
55

66
namespace Lunar.Adapters.Unity

Runtime/Adapters/InputAdapter.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4-
using Lunar.Interfaces;
4+
using Lunar.Core.Base.Interfaces;
55
using UnityEngine;
66
using System.Linq;
7+
using Lunar.Core.Base;
78

89
namespace Lunar.Adapters.Unity
910
{
1011
public class InputAdapter : IInput
1112
{
12-
public bool GetKeyDown(KeyCode keycode)
13+
public bool GetKeyDown(KeyCodeBase keycode)
1314
{
1415
return Input.GetKeyDown(keycode.ToUnity());
1516
}
1617

17-
public bool GetKey(KeyCode keycode)
18+
public bool GetKey(KeyCodeBase keycode)
1819
{
1920
return Input.GetKey(keycode.ToUnity());
2021
}
2122

22-
public bool GetKeyUp(KeyCode keycode)
23+
public bool GetKeyUp(KeyCodeBase keycode)
2324
{
2425
return Input.GetKeyUp(keycode.ToUnity());
2526
}
2627
}
2728

2829
public static class KeyCodeConverter
2930
{
30-
private static readonly ConcurrentDictionary<KeyCode, UnityEngine.KeyCode> Cache = new();
31+
private static readonly ConcurrentDictionary<KeyCodeBase, UnityEngine.KeyCode> Cache = new();
3132

3233
// If some key names are inconsistent on both sides, they can be overwritten here uniformly
33-
private static readonly Dictionary<KeyCode, UnityEngine.KeyCode> Overrides
34+
private static readonly Dictionary<KeyCodeBase, UnityEngine.KeyCode> Overrides
3435
= new()
3536
{
3637
// [KeyCode.SomeLunarName] = UnityEngine.KeyCode.SomeDifferentUnityName,
3738
};
3839

39-
public static UnityEngine.KeyCode ToUnity(this KeyCode key)
40+
public static UnityEngine.KeyCode ToUnity(this KeyCodeBase key)
4041
{
4142
if (Overrides.TryGetValue(key, out var overridden))
4243
{
@@ -60,16 +61,16 @@ public static UnityEngine.KeyCode ToUnity(this KeyCode key)
6061
}
6162
public class InputActionsAdapter : IInputActions
6263
{
63-
public Dictionary<string, KeyCode[]> Bindings { get; }
64+
public Dictionary<string, KeyCodeBase[]> Bindings { get; }
6465
public IInput Input { get; }
6566

66-
public InputActionsAdapter(IInput input, Dictionary<string, KeyCode[]> bindings)
67+
public InputActionsAdapter(IInput input, Dictionary<string, KeyCodeBase[]> bindings)
6768
{
6869
Input = input;
6970
Bindings = bindings;
7071
}
7172

72-
public bool SetBinding(string action, params KeyCode[] keys)
73+
public bool SetBinding(string action, params KeyCodeBase[] keys)
7374
{
7475
if (string.IsNullOrWhiteSpace(action))
7576
{
@@ -81,7 +82,7 @@ public bool SetBinding(string action, params KeyCode[] keys)
8182
return false;
8283
}
8384

84-
if (keys.Any(key => !Enum.IsDefined(typeof(KeyCode), key)))
85+
if (keys.Any(key => !Enum.IsDefined(typeof(KeyCodeBase), key)))
8586
{
8687
return false;
8788
}

Runtime/Adapters/ResourcesAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Threading;
55
using System.Threading.Tasks;
6-
using Lunar.Interfaces;
6+
using Lunar.Core.Base.Interfaces;
77
using UnityEngine;
88
using Object = UnityEngine.Object;
99

Runtime/GameController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using Lunar.Core.Base;
34
using UnityEngine;
45
using UnityEngine.Pool;
56

@@ -66,12 +67,12 @@ public static ServiceRegistry DefaultServicesFactory()
6667
ResourcesAsync = new ResourcesAdapter(),
6768
InputActions = new InputActionsAdapter(
6869
new InputAdapter(),
69-
new Dictionary<string, KeyCode[]>
70+
new Dictionary<string, KeyCodeBase[]>
7071
{
71-
["Play"] = new[] { KeyCode.Space },
72-
["Pause"] = new[] { KeyCode.P },
73-
["Resume"] = new[] { KeyCode.R },
74-
["Cancel"] = new[] { KeyCode.C }
72+
["Play"] = new[] { KeyCodeBase.Space },
73+
["Pause"] = new[] { KeyCodeBase.P },
74+
["Resume"] = new[] { KeyCodeBase.R },
75+
["Cancel"] = new[] { KeyCodeBase.C }
7576
}),
7677
Logger = new DebugLogAdapter()
7778
};

Runtime/GameControllerImplementation.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using Arch.System;
44
using Lunar.Adapters.Unity.Systems;
55
using Lunar.Adapters.Unity.Utils;
6-
using Lunar.Components;
6+
using Lunar.Core.Base;
7+
using Lunar.Core.ECS;
8+
using Lunar.Core.ECS.Components;
79
using UnityEngine;
810
using UnityEngine.Pool;
911

@@ -45,14 +47,14 @@ protected override void SetEvents(World world)
4547
entity.Add(new TransformComponent());
4648
}
4749

48-
if (gameObjectComponent.GameObject != null)
50+
if (gameObjectComponent.GameObjectBase != null)
4951
{
5052
return;
5153
}
5254

5355
var unityGameObject = _gameObjectPool.Get();
5456
unityGameObject.transform.SetParent(_parent);
55-
entity.Set(new GameObjectComponent(new GameObject(unityGameObject)));
57+
entity.Set(new GameObjectComponent(new GameObjectBase(unityGameObject)));
5658
});
5759

5860

@@ -72,19 +74,19 @@ protected override void SetEvents(World world)
7274
if (unityGameObject.TryGetComponent<SpriteRenderer>(out var spriteRenderer))
7375
{
7476
spriteRenderer.enabled = true;
75-
spriteComponent.Sprite = new Sprite(spriteRenderer);
77+
spriteComponent.Sprite = new SpriteBase(spriteRenderer);
7678
}
7779
else
7880
{
79-
spriteComponent.Sprite = new Sprite(unityGameObject.AddComponent<SpriteRenderer>());
81+
spriteComponent.Sprite = new SpriteBase(unityGameObject.AddComponent<SpriteRenderer>());
8082
}
8183
});
8284

8385
world.SubscribeComponentRemoved((in Entity entity, ref GameObjectComponent gameObjectComponent) =>
8486
{
85-
if (gameObjectComponent.GameObject != null)
87+
if (gameObjectComponent.GameObjectBase != null)
8688
{
87-
_gameObjectPool.Release(gameObjectComponent.GameObject.BaseGameObject as UnityEngine.GameObject);
89+
_gameObjectPool.Release(gameObjectComponent.GameObjectBase.BaseGameObject as UnityEngine.GameObject);
8890
}
8991
});
9092
}

Runtime/ServiceRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Lunar.Interfaces;
1+
using Lunar.Core.Base.Interfaces;
22

33
namespace Lunar.Adapters.Unity
44
{

Runtime/Systems/DebugCreateObjectSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using Arch.Core;
22
using Arch.Core.Extensions;
33
using Arch.System;
4-
using Lunar.Components;
4+
5+
using Lunar.Core.ECS.Components;
56
using UnityEngine;
67

78
namespace Lunar.Adapters.Unity.Systems

Runtime/Systems/GameObjectSyncSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using Arch.Core;
33
using Lunar.Adapters.Unity.Utils;
4-
using Lunar.Components;
5-
using Lunar.Systems;
4+
using Lunar.Core.ECS.Components;
5+
using Lunar.Core.ECS.Systems;
66
using UnityEngine;
77

88
namespace Lunar.Adapters.Unity.Systems

Runtime/Systems/SpriteCleanSystem.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Arch.Core;
22
using Lunar.Adapters.Unity.Utils;
3-
using Lunar.Components;
4-
using Lunar.Systems;
3+
4+
using Lunar.Core.ECS.Components;
5+
using Lunar.Core.ECS.Systems;
6+
57
using UnityEngine;
68

79
namespace Lunar.Adapters.Unity.Systems

Runtime/Systems/SpriteSyncSystem.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System.Threading.Tasks;
44
using Arch.Core;
55
using Lunar.Adapters.Unity.Utils;
6-
using Lunar.Components;
7-
using Lunar.Interfaces;
8-
using Lunar.Systems;
6+
7+
using Lunar.Core.Base.Interfaces;
8+
using Lunar.Core.ECS.Components;
9+
using Lunar.Core.ECS.Systems;
10+
911

1012
namespace Lunar.Adapters.Unity.Systems
1113
{

0 commit comments

Comments
 (0)