Skip to content

Commit 8137141

Browse files
Merge pull request #34 from CoderGamester/develop
Release 2.1.1
2 parents 989a210 + 6cb782a commit 8137141

7 files changed

Lines changed: 109 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [2.1.1] - 2026-07-04
8+
9+
**Changed**:
10+
- PlayMode tests updated to parameterless `FindObjectsByType<T>()` overload (Unity 6 API).
11+
- Removed redundant `[Serializable]` from `AddressableConfig` (already implicitly serializable as a reference type in Unity YAML).
12+
13+
**Fixed**:
14+
- `ServicesScaffolders` adapts to Unity 6000.4+ `AssetCreationEndAction` / `EntityId` API (guarded by `UNITY_6000_4_OR_NEWER`; pre-6000.4 path unchanged).
15+
716
## [2.1.0] - 2026-05-20
817

918
**New**:

Editor/GameLovers.Services.Editor.asmdef

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
"versionDefines": [],
2121
"noEngineReferences": false
2222
}
23+

Editor/Scaffolders/ServicesScaffolders.cs

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ private static void CreateFromTemplate(string templateFileName, string defaultNa
5252
var endAction = ScriptableObject.CreateInstance<ScriptNameEditAction>();
5353
endAction.TemplatePath = templatePath;
5454

55+
#if UNITY_6000_4_OR_NEWER
56+
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(
57+
default,
58+
endAction,
59+
defaultName,
60+
EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D,
61+
null);
62+
#else
5563
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(
5664
0,
5765
endAction,
5866
defaultName,
5967
EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D,
6068
null);
69+
#endif
6170
}
6271

6372
private static string FindTemplatePath(string fileName)
@@ -92,15 +101,21 @@ private static string FindTemplatePath(string fileName)
92101
return null;
93102
}
94103

95-
/// <summary>
96-
/// Called by <see cref="ProjectWindowUtil"/> after the user confirms the file name.
97-
/// Reads the template, replaces placeholders, and writes the final .cs file.
98-
/// </summary>
99-
private class ScriptNameEditAction : EndNameEditAction
104+
#if UNITY_6000_4_OR_NEWER
105+
private class ScriptNameEditAction : AssetCreationEndAction
100106
{
101107
public string TemplatePath;
102108

103-
public override void Action(int instanceId, string pathName, string resourceFile)
109+
public override void Action(EntityId entityId, string pathName, string resourceFile)
110+
{
111+
WriteScript(pathName);
112+
}
113+
114+
public override void Cancelled(EntityId entityId, string pathName, string resourceFile)
115+
{
116+
}
117+
118+
private void WriteScript(string pathName)
104119
{
105120
var scriptName = Path.GetFileNameWithoutExtension(pathName);
106121
var ns = DeriveNamespace(pathName);
@@ -117,10 +132,79 @@ public override void Action(int instanceId, string pathName, string resourceFile
117132
ProjectWindowUtil.ShowCreatedAsset(asset);
118133
}
119134

135+
private static string DeriveNamespace(string assetPath)
136+
{
137+
var rootNamespace = EditorSettings.projectGenerationRootNamespace;
138+
139+
if (string.IsNullOrEmpty(rootNamespace))
140+
{
141+
rootNamespace = "Game";
142+
}
143+
144+
var dir = Path.GetDirectoryName(assetPath);
145+
146+
if (string.IsNullOrEmpty(dir))
147+
{
148+
return rootNamespace;
149+
}
150+
151+
dir = dir.Replace('\\', '/');
152+
153+
const string assetsPrefix = "Assets/";
154+
155+
if (dir.StartsWith(assetsPrefix, StringComparison.Ordinal))
156+
{
157+
dir = dir.Substring(assetsPrefix.Length);
158+
}
159+
160+
var parts = dir.Split('/');
161+
var nsBuilder = new StringBuilder(rootNamespace);
162+
163+
foreach (var part in parts)
164+
{
165+
if (string.IsNullOrEmpty(part))
166+
{
167+
continue;
168+
}
169+
170+
nsBuilder.Append('.');
171+
nsBuilder.Append(part);
172+
}
173+
174+
return nsBuilder.ToString();
175+
}
176+
}
177+
#else
178+
private class ScriptNameEditAction : EndNameEditAction
179+
{
180+
public string TemplatePath;
181+
182+
public override void Action(int instanceId, string pathName, string resourceFile)
183+
{
184+
WriteScript(pathName);
185+
}
186+
120187
public override void Cancelled(int instanceId, string pathName, string resourceFile)
121188
{
122189
}
123190

191+
private void WriteScript(string pathName)
192+
{
193+
var scriptName = Path.GetFileNameWithoutExtension(pathName);
194+
var ns = DeriveNamespace(pathName);
195+
var template = File.ReadAllText(TemplatePath, Encoding.UTF8);
196+
197+
var content = template
198+
.Replace("$NAME$", scriptName)
199+
.Replace("$NAMESPACE$", ns);
200+
201+
File.WriteAllText(pathName, content, Encoding.UTF8);
202+
AssetDatabase.ImportAsset(pathName);
203+
204+
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(pathName);
205+
ProjectWindowUtil.ShowCreatedAsset(asset);
206+
}
207+
124208
private static string DeriveNamespace(string assetPath)
125209
{
126210
var rootNamespace = EditorSettings.projectGenerationRootNamespace;
@@ -163,5 +247,6 @@ private static string DeriveNamespace(string assetPath)
163247
return nsBuilder.ToString();
164248
}
165249
}
250+
#endif
166251
}
167252
}

Runtime/AssetsImporter/AddressableConfig.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace GameLovers.Services.AssetsImporter
1010
/// Represents a configuration of an Addressable with all it's important data
1111
/// The Id is the int representation of the AddressableId generated by the AddressableIdsGenerator code generator
1212
/// </summary>
13-
[Serializable]
1413
public class AddressableConfig
1514
{
1615
public int Id;

Tests/PlayMode/Unit/CoroutineServiceTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,19 @@ public IEnumerator StopAllCoroutines_Successfully()
145145
[UnityTest]
146146
public IEnumerator Dispose_DestroysHostGameObject()
147147
{
148-
var initialCount = Object.FindObjectsByType<CoroutineServiceMonoBehaviour>(FindObjectsSortMode.None).Length;
148+
var initialCount = Object.FindObjectsByType<CoroutineServiceMonoBehaviour>().Length;
149149
var service = new CoroutineService();
150150

151151
Assert.AreEqual(
152152
initialCount + 1,
153-
Object.FindObjectsByType<CoroutineServiceMonoBehaviour>(FindObjectsSortMode.None).Length);
153+
Object.FindObjectsByType<CoroutineServiceMonoBehaviour>().Length);
154154

155155
service.Dispose();
156156
yield return null;
157157

158158
Assert.AreEqual(
159159
initialCount,
160-
Object.FindObjectsByType<CoroutineServiceMonoBehaviour>(FindObjectsSortMode.None).Length);
160+
Object.FindObjectsByType<CoroutineServiceMonoBehaviour>().Length);
161161
}
162162

163163
[UnityTest]

Tests/PlayMode/Unit/TickServiceTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ public IEnumerator UnsubscribeAll_BySubscriber_RemovesOnlyThatSubscriber()
141141
[UnityTest]
142142
public IEnumerator Dispose_DestroysGameObject()
143143
{
144-
var initialCount = Object.FindObjectsByType<TickServiceMonoBehaviour>(FindObjectsSortMode.None).Length;
144+
var initialCount = Object.FindObjectsByType<TickServiceMonoBehaviour>().Length;
145145
var tickService = new TickService();
146146

147-
Assert.AreEqual(initialCount + 1, Object.FindObjectsByType<TickServiceMonoBehaviour>(FindObjectsSortMode.None).Length);
147+
Assert.AreEqual(initialCount + 1, Object.FindObjectsByType<TickServiceMonoBehaviour>().Length);
148148

149149
tickService.Dispose();
150150
yield return null; // Allow Destroy to complete
151151

152-
Assert.AreEqual(initialCount, Object.FindObjectsByType<TickServiceMonoBehaviour>(FindObjectsSortMode.None).Length);
152+
Assert.AreEqual(initialCount, Object.FindObjectsByType<TickServiceMonoBehaviour>().Length);
153153
}
154154

155155
[UnityTest]
@@ -367,7 +367,7 @@ public TickService()
367367
var service1 = new TickService();
368368
var service2 = new TickService();
369369

370-
var objects = Object.FindObjectsByType<TickServiceMonoBehaviour>(FindObjectsSortMode.None);
370+
var objects = Object.FindObjectsByType<TickServiceMonoBehaviour>();
371371
Assert.GreaterOrEqual(objects.Length, 2);
372372

373373
service1.Dispose();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.gamelovers.services",
33
"displayName": "GameLovers Services",
44
"author": "Miguel Tomas",
5-
"version": "2.1.0",
5+
"version": "2.1.1",
66
"unity": "6000.3",
77
"license": "MIT",
88
"description": "Foundation services for a Unity based project (DI-lite, messaging, ticking, coroutines, pooling, persistence, RNG, time, commands, versioning) plus Addressables-based asset loading and importing tooling.",

0 commit comments

Comments
 (0)