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

Commit ff2bb2b

Browse files
committed
refactor(Unity): Rename base classes to handle and update property names
Renamed KeyCodeBase to KeyCodeHandle and GameObjectBase to GameObjectHandle. Updated property names from Base* to Native* for clarity. Adjusted related tests and adapters to use the new naming convention.
1 parent 5d285e3 commit ff2bb2b

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

Runtime/Adapters/InputAdapter.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@ namespace Lunar.Adapters.Unity
1010
{
1111
public class InputAdapter : IInput
1212
{
13-
public bool GetKeyDown(KeyCodeBase keycode)
13+
public bool GetKeyDown(KeyCodeHandle keycode)
1414
{
1515
return Input.GetKeyDown(keycode.ToUnity());
1616
}
1717

18-
public bool GetKey(KeyCodeBase keycode)
18+
public bool GetKey(KeyCodeHandle keycode)
1919
{
2020
return Input.GetKey(keycode.ToUnity());
2121
}
2222

23-
public bool GetKeyUp(KeyCodeBase keycode)
23+
public bool GetKeyUp(KeyCodeHandle keycode)
2424
{
2525
return Input.GetKeyUp(keycode.ToUnity());
2626
}
2727
}
2828

2929
public static class KeyCodeConverter
3030
{
31-
private static readonly ConcurrentDictionary<KeyCodeBase, UnityEngine.KeyCode> Cache = new();
31+
private static readonly ConcurrentDictionary<KeyCodeHandle, UnityEngine.KeyCode> Cache = new();
3232

3333
// If some key names are inconsistent on both sides, they can be overwritten here uniformly
34-
private static readonly Dictionary<KeyCodeBase, UnityEngine.KeyCode> Overrides
34+
private static readonly Dictionary<KeyCodeHandle, UnityEngine.KeyCode> Overrides
3535
= new()
3636
{
3737
// [KeyCode.SomeLunarName] = UnityEngine.KeyCode.SomeDifferentUnityName,
3838
};
3939

40-
public static UnityEngine.KeyCode ToUnity(this KeyCodeBase key)
40+
public static UnityEngine.KeyCode ToUnity(this KeyCodeHandle key)
4141
{
4242
if (Overrides.TryGetValue(key, out var overridden))
4343
{
@@ -61,16 +61,16 @@ public static UnityEngine.KeyCode ToUnity(this KeyCodeBase key)
6161
}
6262
public class InputActionsAdapter : IInputActions
6363
{
64-
public Dictionary<string, KeyCodeBase[]> Bindings { get; }
64+
public Dictionary<string, KeyCodeHandle[]> Bindings { get; }
6565
public IInput Input { get; }
6666

67-
public InputActionsAdapter(IInput input, Dictionary<string, KeyCodeBase[]> bindings)
67+
public InputActionsAdapter(IInput input, Dictionary<string, KeyCodeHandle[]> bindings)
6868
{
6969
Input = input;
7070
Bindings = bindings;
7171
}
7272

73-
public bool SetBinding(string action, params KeyCodeBase[] keys)
73+
public bool SetBinding(string action, params KeyCodeHandle[] keys)
7474
{
7575
if (string.IsNullOrWhiteSpace(action))
7676
{
@@ -82,7 +82,7 @@ public bool SetBinding(string action, params KeyCodeBase[] keys)
8282
return false;
8383
}
8484

85-
if (keys.Any(key => !Enum.IsDefined(typeof(KeyCodeBase), key)))
85+
if (keys.Any(key => !Enum.IsDefined(typeof(KeyCodeHandle), key)))
8686
{
8787
return false;
8888
}

Runtime/GameController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public static ServiceRegistry DefaultServicesFactory()
6767
ResourcesAsync = new ResourcesAdapter(),
6868
InputActions = new InputActionsAdapter(
6969
new InputAdapter(),
70-
new Dictionary<string, KeyCodeBase[]>
70+
new Dictionary<string, KeyCodeHandle[]>
7171
{
72-
["Play"] = new[] { KeyCodeBase.Space },
73-
["Pause"] = new[] { KeyCodeBase.P },
74-
["Resume"] = new[] { KeyCodeBase.R },
75-
["Cancel"] = new[] { KeyCodeBase.C }
72+
["Play"] = new[] { KeyCodeHandle.Space },
73+
["Pause"] = new[] { KeyCodeHandle.P },
74+
["Resume"] = new[] { KeyCodeHandle.R },
75+
["Cancel"] = new[] { KeyCodeHandle.C }
7676
}),
7777
Logger = new DebugLogAdapter()
7878
};

Runtime/GameControllerImplementation.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ protected override void SetEvents(World world)
4747
entity.Add(new TransformComponent());
4848
}
4949

50-
if (gameObjectComponent.GameObjectBase != null)
50+
if (gameObjectComponent.GameObjectHandle != null)
5151
{
5252
return;
5353
}
5454

5555
var unityGameObject = _gameObjectPool.Get();
5656
unityGameObject.transform.SetParent(_parent);
57-
entity.Set(new GameObjectComponent(new GameObjectBase(unityGameObject)));
57+
entity.Set(new GameObjectComponent(new GameObjectHandle(unityGameObject)));
5858
});
5959

6060

@@ -74,19 +74,19 @@ protected override void SetEvents(World world)
7474
if (unityGameObject.TryGetComponent<SpriteRenderer>(out var spriteRenderer))
7575
{
7676
spriteRenderer.enabled = true;
77-
spriteComponent.Sprite = new SpriteBase(spriteRenderer);
77+
spriteComponent.Sprite = new SpriteHandle(spriteRenderer);
7878
}
7979
else
8080
{
81-
spriteComponent.Sprite = new SpriteBase(unityGameObject.AddComponent<SpriteRenderer>());
81+
spriteComponent.Sprite = new SpriteHandle(unityGameObject.AddComponent<SpriteRenderer>());
8282
}
8383
});
8484

8585
world.SubscribeComponentRemoved((in Entity entity, ref GameObjectComponent gameObjectComponent) =>
8686
{
87-
if (gameObjectComponent.GameObjectBase != null)
87+
if (gameObjectComponent.GameObjectHandle != null)
8888
{
89-
_gameObjectPool.Release(gameObjectComponent.GameObjectBase.BaseGameObject as UnityEngine.GameObject);
89+
_gameObjectPool.Release(gameObjectComponent.GameObjectHandle.NativeGameObject as UnityEngine.GameObject);
9090
}
9191
});
9292
}

Runtime/Utils/UnityConversionUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class UnityConversionUtils
77
public static bool TryParseToUnity(this GameObjectComponent gameObject,
88
out UnityEngine.GameObject unityGameObject)
99
{
10-
unityGameObject = gameObject.GameObjectBase.BaseGameObject as UnityEngine.GameObject;
10+
unityGameObject = gameObject.GameObjectHandle.NativeGameObject as UnityEngine.GameObject;
1111

1212
return unityGameObject;
1313

@@ -19,7 +19,7 @@ public static bool TryParseToUnity(this SpriteComponent sprite,
1919
{
2020
if (sprite.Sprite != null)
2121
{
22-
unitySpriteRenderer = sprite.Sprite.BaseSprite as UnityEngine.SpriteRenderer;
22+
unitySpriteRenderer = sprite.Sprite.NativeSprite as UnityEngine.SpriteRenderer;
2323

2424
return unitySpriteRenderer;
2525
}

Tests/KeyCodeConverterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void All_LunarKeyCodes_MapTo_UnityEngineKeyCode()
1313
{
1414
var failed = new List<string>();
1515

16-
foreach (KeyCodeBase lunarKey in Enum.GetValues(typeof(KeyCodeBase)))
16+
foreach (KeyCodeHandle lunarKey in Enum.GetValues(typeof(KeyCodeHandle)))
1717
{
1818
try
1919
{

0 commit comments

Comments
 (0)