gg.easy.airship 0.1.2168 → 0.1.2170

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -285,7 +285,7 @@ namespace Editor.Accessories.Clothing {
285
285
  var buildOutputFile = $"bundles/gear/{airId}_{AirshipPlatformUtil.GetStringName(platform)}.bundle";
286
286
  var sourceFolderPath = Path.GetRelativePath(".", Directory.GetParent(AssetDatabase.GetAssetPath(manifest))!.FullName);
287
287
 
288
- List<AssetBundleBuild> builds = CreateAssetBundles.GetPackageAssetBundleBuilds();
288
+ List<AssetBundleBuild> builds = CreateAssetBundles.GetPackageAssetBundleBuilds(false);
289
289
 
290
290
  var assetGuids = AssetDatabase.FindAssets("*", new string[] {sourceFolderPath}).ToList();
291
291
  var assetPaths = assetGuids
@@ -176,7 +176,7 @@ public class AirshipComponentDropdown : AdvancedDropdown {
176
176
  foreach (var binaryFile in binaryFiles) {
177
177
  if (binaryFile.m_metadata == null) continue;
178
178
 
179
- var airshipComponentMenu = binaryFile.m_metadata.GetDecorators().Find(f => f.name == "AirshipComponentMenu");
179
+ var airshipComponentMenu = binaryFile.m_metadata.decorators.Find(f => f.name == "AirshipComponentMenu");
180
180
  if (airshipComponentMenu != null && airshipComponentMenu.parameters[0].TryGetString(out var customPath)) {
181
181
  if (customPath == "") continue; // ignore empty names :)
182
182
 
@@ -218,6 +218,30 @@ public class ScriptBindingEditor : UnityEditor.Editor {
218
218
 
219
219
  var metadata = serializedObject.FindProperty("metadata");
220
220
 
221
+ var originalMetadata = binding.script.m_metadata;
222
+
223
+ var originalDecorators = originalMetadata.decorators;
224
+ var serializedDecorators = binding.metadata.decorators;
225
+
226
+ if (serializedDecorators.Count != originalDecorators.Count) {
227
+ return true;
228
+ }
229
+
230
+ foreach (var serializedDecorator in serializedDecorators)
231
+ {
232
+ var decoratorName = serializedDecorator.name;
233
+ var originalDecorator = originalDecorators.Find(d => d.name == decoratorName);
234
+
235
+ if (originalDecorator == null) {
236
+ return true;
237
+ }
238
+
239
+ var serializedParameters = serializedDecorator.parameters;
240
+ if (serializedParameters.Count != originalDecorator.parameters.Count) {
241
+ return true;
242
+ }
243
+ }
244
+
221
245
  var metadataProperties = metadata.FindPropertyRelative("properties");
222
246
  var originalMetadataProperties = binding.script.m_metadata?.properties;
223
247
 
@@ -125,6 +125,7 @@ namespace Airship.Editor {
125
125
 
126
126
  if (scriptMetadata == null) return false;
127
127
  componentMetadata.name = scriptMetadata.name;
128
+ componentMetadata.decorators = new List<LuauMetadataDecoratorElement>(scriptMetadata.decorators);
128
129
 
129
130
  // Add missing properties
130
131
  foreach (var scriptProperty in scriptMetadata.properties) {
@@ -193,10 +194,108 @@ namespace Airship.Editor {
193
194
  }
194
195
  }
195
196
  #endif
197
+
198
+ // Add required components
199
+ var requireComponents = scriptMetadata.FindClassDecorators("RequireComponent");
200
+ foreach (var requireComponent in requireComponents) {
201
+ var parameter = requireComponent.parameters.FirstOrDefault();
202
+ if (parameter == null) continue;
203
+
204
+ var requiredComponentTypeName = parameter.value?.ToString();
205
+ if (string.IsNullOrEmpty(requiredComponentTypeName)) continue;
206
+
207
+ var gameObject = component.gameObject;
208
+ if (gameObject == null) continue;
209
+
210
+ var parameterType = parameter.type;
211
+
212
+ switch (parameterType)
213
+ {
214
+ case "object":
215
+ {
216
+ EnsureUnityComponent(gameObject, requiredComponentTypeName);
217
+ break;
218
+ }
219
+ case "AirshipBehaviour":
220
+ {
221
+ EnsureAirshipComponent(gameObject, requiredComponentTypeName, component.context);
222
+ break;
223
+ }
224
+ }
225
+ }
226
+
196
227
  // component.componentHash = component.script.sourceFileHash;
197
228
  return true;
198
229
  }
230
+
231
+ /// <summary>
232
+ /// Ensures that a Unity component is present on the GameObject, adding it if necessary
233
+ /// </summary>
234
+ /// <param name="gameObject">The GameObject to check</param>
235
+ /// <param name="componentTypeName">The name of the Unity component type</param>
236
+ private static void EnsureUnityComponent(GameObject gameObject, string componentTypeName) {
237
+ try {
238
+ var componentType = GetComponentTypeByName(componentTypeName);
239
+ if (componentType == null) {
240
+ Debug.LogWarning($"[RequireComponent] Could not find Unity component type: {componentTypeName}.", gameObject);
241
+ return;
242
+ }
243
+
244
+ var existingComponent = gameObject.GetComponent(componentType);
245
+ if (existingComponent != null) {
246
+ return;
247
+ }
248
+
249
+ gameObject.AddComponent(componentType);
250
+ #if AIRSHIP_DEBUG
251
+ Debug.Log($"[RequireComponent] Added Unity component '{componentTypeName}' to GameObject '{gameObject.name}'", gameObject);
252
+ #endif
253
+ }
254
+ catch (Exception ex) {
255
+ Debug.LogException(ex);
256
+ }
257
+ }
258
+
259
+ /// <summary>
260
+ /// Ensures that an AirshipComponent is present on the GameObject, adding it if necessary
261
+ /// </summary>
262
+ /// <param name="gameObject">The GameObject to check</param>
263
+ /// <param name="componentTypeName">The name of the AirshipComponent type</param>
264
+ /// <param name="context">The Luau context to use when creating the component</param>
265
+ private static void EnsureAirshipComponent(GameObject gameObject, string componentTypeName, LuauContext context) {
266
+ try {
267
+ var existingComponents = gameObject.GetComponents<AirshipComponent>();
268
+ foreach (var existingComponent in existingComponents) {
269
+ if (existingComponent.script == null || existingComponent.script.m_metadata == null) continue;
270
+
271
+ if (existingComponent.script.m_metadata.name != componentTypeName) continue;
272
+
273
+ return;
274
+ }
275
+
276
+ var buildInfo = AirshipBuildInfo.Instance;
277
+ if (buildInfo == null || !buildInfo.HasAirshipBehaviourClass(componentTypeName)) {
278
+ Debug.LogWarning($"[RequireComponent] AirshipComponent '{componentTypeName}' not found in build info", gameObject);
279
+ return;
280
+ }
281
+
282
+ var scriptPath = buildInfo.GetScriptPath(componentTypeName);
283
+ AirshipComponent.Create(gameObject, $"Assets/{scriptPath}", context);
284
+
285
+ #if AIRSHIP_DEBUG
286
+ Debug.Log($"[RequireComponent] Added AirshipComponent '{componentTypeName}' to GameObject '{gameObject.name}'", gameObject);
287
+ #endif
288
+ }
289
+ catch (Exception ex) {
290
+ Debug.LogException(ex);
291
+ }
292
+ }
199
293
 
294
+ private static Type GetComponentTypeByName(string name) {
295
+ var types = TypeCache.GetTypesDerivedFrom<Component>();
296
+ return types.FirstOrDefault(type => type.Name == name);
297
+ }
298
+
200
299
  /// <summary>
201
300
  /// Reconciles all queued components for the given script
202
301
  /// </summary>
@@ -381,4 +480,4 @@ namespace Airship.Editor {
381
480
  }
382
481
  }
383
482
  }
384
- #endif
483
+ #endif