diff --git a/AAC/AACCore/Editor/AACCore.cs b/AAC/AACCore/Editor/AACCore.cs index c1d0b50..b255b0e 100644 --- a/AAC/AACCore/Editor/AACCore.cs +++ b/AAC/AACCore/Editor/AACCore.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Diagnostics; using AnimatorAsCode.V1; using gay.lilyy.aaccore; +using gay.lilyy.Common; using nadena.dev.ndmf; using AnimatorAsCode.V1.ModularAvatar; using UnityEditor; @@ -164,7 +165,7 @@ namespace gay.lilyy.aaccore var overallStopwatch = Stopwatch.StartNew(); V5AACLogger.LogInfo("Starting Lillith V5 AAC generation..."); - var root = ctx.AvatarRootObject.GetComponent(); + var root = ComponentHelper.GetComponentInChildrenWithError(ctx.AvatarRootObject); if (root == null) { V5AACLogger.LogInfo("No LillithV5AACRoot component found. Skipping."); diff --git a/AAC/AACCore/Editor/AACCoreEditor.asmdef b/AAC/AACCore/Editor/AACCoreEditor.asmdef index 0e38024..87b668f 100644 --- a/AAC/AACCore/Editor/AACCoreEditor.asmdef +++ b/AAC/AACCore/Editor/AACCoreEditor.asmdef @@ -11,7 +11,8 @@ "GUID:901e56b065a857d4483a77f8cae73588", "GUID:04a7e5cf006503242b1db329a84d694d", "GUID:95124d49b8c897e4286f0bf6c6e57f4d", - "GUID:a65a5779a3702144986d83fca255f5da" + "GUID:a65a5779a3702144986d83fca255f5da", + "GUID:209cbd2a789c4f72963fdbf1f8a01909" ], "includePlatforms": [ "Editor" diff --git a/AAC/AACShared/Layers/AACSharedLayers.asmdef b/AAC/AACShared/Layers/AACSharedLayers.asmdef index 0336442..a9d6873 100644 --- a/AAC/AACShared/Layers/AACSharedLayers.asmdef +++ b/AAC/AACShared/Layers/AACSharedLayers.asmdef @@ -11,7 +11,8 @@ "GUID:04a7e5cf006503242b1db329a84d694d", "GUID:62ced99b048af7f4d8dfe4bed8373d76", "GUID:e73da13578f7b4d4fa785d6f8fe72ba3", - "GUID:fc900867c0f47cd49b6e2ae4ef907300" + "GUID:fc900867c0f47cd49b6e2ae4ef907300", + "GUID:209cbd2a789c4f72963fdbf1f8a01909" ], "includePlatforms": [ "Editor" diff --git a/AAC/AACShared/Layers/LanternFlicker.cs b/AAC/AACShared/Layers/LanternFlicker.cs index e82f8fc..29c5fdf 100644 --- a/AAC/AACShared/Layers/LanternFlicker.cs +++ b/AAC/AACShared/Layers/LanternFlicker.cs @@ -4,6 +4,7 @@ using AnimatorAsCode.V1; using System.Collections.Generic; using gay.lilyy.aaccore; using gay.lilyy.aacshared.runtimecomponents; +using gay.lilyy.Common; namespace gay.lilyy.aacshared.layers { @@ -30,7 +31,7 @@ namespace gay.lilyy.aacshared.layers public override bool IsApplicable(AACAssets assets) { - var definition = assets.ctx.AvatarRootObject.GetComponent(); + var definition = ComponentHelper.GetComponentInChildrenWithError(assets.ctx.AvatarRootObject); if (definition == null) return false; if (!definition.enabled) return false; var lamp = GetLantern(assets); diff --git a/Common.meta b/Common.meta new file mode 100644 index 0000000..786b1de --- /dev/null +++ b/Common.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1e2dd3118413d6c43a259b24869f8a9a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Common/Runtime.meta b/Common/Runtime.meta new file mode 100644 index 0000000..16ec9be --- /dev/null +++ b/Common/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0c8226e52ebf1fe47b6aea755b9d9bd7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Common/Runtime/CommonRuntime.asmdef b/Common/Runtime/CommonRuntime.asmdef new file mode 100644 index 0000000..fad07b8 --- /dev/null +++ b/Common/Runtime/CommonRuntime.asmdef @@ -0,0 +1,15 @@ +{ + "name": "CommonRuntime", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} + diff --git a/Common/Runtime/CommonRuntime.asmdef.meta b/Common/Runtime/CommonRuntime.asmdef.meta new file mode 100644 index 0000000..e5e8743 --- /dev/null +++ b/Common/Runtime/CommonRuntime.asmdef.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 209cbd2a789c4f72963fdbf1f8a01909 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: + diff --git a/Common/Runtime/ComponentHelper.cs b/Common/Runtime/ComponentHelper.cs new file mode 100644 index 0000000..2ed7203 --- /dev/null +++ b/Common/Runtime/ComponentHelper.cs @@ -0,0 +1,58 @@ +using UnityEngine; + +namespace gay.lilyy.Common +{ + public static class ComponentHelper + { + /// + /// Searches for a component in children of the root GameObject. + /// Returns null if no component is found. + /// Logs an error and returns null if multiple components are found. + /// + /// The component type to search for + /// The root GameObject to search in + /// The component if exactly one is found, null otherwise + public static T? GetComponentInChildrenWithError(GameObject root) where T : Component + { + if (root == null) return null; + + T[] components = root.GetComponentsInChildren(true); + if (components.Length == 0) + { + return null; + } + if (components.Length > 1) + { + Debug.LogError($"Multiple {typeof(T).Name} components found in children of {root.name}. Only one is allowed."); + return null; + } + return components[0]; + } + + /// + /// Searches for a component in children of the root Transform. + /// Returns null if no component is found. + /// Logs an error and returns null if multiple components are found. + /// + /// The component type to search for + /// The root Transform to search in + /// The component if exactly one is found, null otherwise + public static T? GetComponentInChildrenWithError(Transform root) where T : Component + { + if (root == null) return null; + + T[] components = root.GetComponentsInChildren(true); + if (components.Length == 0) + { + return null; + } + if (components.Length > 1) + { + Debug.LogError($"Multiple {typeof(T).Name} components found in children of {root.name}. Only one is allowed."); + return null; + } + return components[0]; + } + } +} + diff --git a/Common/Runtime/ComponentHelper.cs.meta b/Common/Runtime/ComponentHelper.cs.meta new file mode 100644 index 0000000..e11bf8f --- /dev/null +++ b/Common/Runtime/ComponentHelper.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 115183d8dc354ef7b1c43fb49aeaab2f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: + diff --git a/MenuIconRemover/Editor/MenuIconRemoverEditor.asmdef b/MenuIconRemover/Editor/MenuIconRemoverEditor.asmdef index a9ccd9c..cf5a0f8 100644 --- a/MenuIconRemover/Editor/MenuIconRemoverEditor.asmdef +++ b/MenuIconRemover/Editor/MenuIconRemoverEditor.asmdef @@ -5,7 +5,8 @@ "GUID:4713dd3cf2e7fa34cbc6bbb6fef3c7d0", "GUID:62ced99b048af7f4d8dfe4bed8373d76", "GUID:5718fb738711cd34ea54e9553040911d", - "GUID:901e56b065a857d4483a77f8cae73588" + "GUID:901e56b065a857d4483a77f8cae73588", + "GUID:209cbd2a789c4f72963fdbf1f8a01909" ], "includePlatforms": [ "Editor" diff --git a/MenuIconRemover/Editor/MenuIconRemoverPlugin.cs b/MenuIconRemover/Editor/MenuIconRemoverPlugin.cs index 642c1b0..3f974c3 100644 --- a/MenuIconRemover/Editor/MenuIconRemoverPlugin.cs +++ b/MenuIconRemover/Editor/MenuIconRemoverPlugin.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using gay.lilyy.Common; using gay.lilyy.MenuIconRemover; using nadena.dev.ndmf; using nadena.dev.ndmf.vrchat; @@ -20,7 +21,7 @@ namespace gay.lilyy.MenuIconRemover { InPhase(BuildPhase.Optimizing).BeforePlugin("gay.lilyy.MenuStyling").Run("RemoveMenuIcons", ctx => { - var obj = ctx.AvatarRootObject.GetComponent(); + var obj = ComponentHelper.GetComponentInChildrenWithError(ctx.AvatarRootObject); if (obj != null) { var shouldRemove = false; diff --git a/MenuIconReplacer/Editor/MenuIconReplacerEditor.asmdef b/MenuIconReplacer/Editor/MenuIconReplacerEditor.asmdef index c24bac5..b8b31e9 100644 --- a/MenuIconReplacer/Editor/MenuIconReplacerEditor.asmdef +++ b/MenuIconReplacer/Editor/MenuIconReplacerEditor.asmdef @@ -5,7 +5,8 @@ "GUID:108c6ed81f83e074fa168f7087c2a246", "GUID:62ced99b048af7f4d8dfe4bed8373d76", "GUID:5718fb738711cd34ea54e9553040911d", - "GUID:901e56b065a857d4483a77f8cae73588" + "GUID:901e56b065a857d4483a77f8cae73588", + "GUID:209cbd2a789c4f72963fdbf1f8a01909" ], "includePlatforms": [ "Editor" diff --git a/MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs b/MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs index 5cecf80..981fcae 100644 --- a/MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs +++ b/MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using gay.lilyy.Common; using gay.lilyy.MenuIconReplacer; using nadena.dev.ndmf; using nadena.dev.ndmf.vrchat; @@ -21,7 +22,7 @@ namespace gay.lilyy.MenuIconReplacer { InPhase(BuildPhase.Optimizing).BeforePlugin("gay.lilyy.MenuIconRemover").Run("ReplaceMenuIcons", ctx => { - var obj = ctx.AvatarRootObject.GetComponent(); + var obj = ComponentHelper.GetComponentInChildrenWithError(ctx.AvatarRootObject); if (obj != null) { var descriptor = ctx.VRChatAvatarDescriptor(); diff --git a/MenuStyling/Editor/MenuStylingEditorAsmdef.asmdef b/MenuStyling/Editor/MenuStylingEditorAsmdef.asmdef index 080d4e1..21f8ea4 100644 --- a/MenuStyling/Editor/MenuStylingEditorAsmdef.asmdef +++ b/MenuStyling/Editor/MenuStylingEditorAsmdef.asmdef @@ -5,7 +5,8 @@ "GUID:8a060350c9ddd424197c8fd1e0d63f72", "GUID:62ced99b048af7f4d8dfe4bed8373d76", "GUID:5718fb738711cd34ea54e9553040911d", - "GUID:901e56b065a857d4483a77f8cae73588" + "GUID:901e56b065a857d4483a77f8cae73588", + "GUID:209cbd2a789c4f72963fdbf1f8a01909" ], "includePlatforms": [ "Editor" diff --git a/MenuStyling/Editor/MenuStylingPlugin.cs b/MenuStyling/Editor/MenuStylingPlugin.cs index 5805d0d..79040b3 100644 --- a/MenuStyling/Editor/MenuStylingPlugin.cs +++ b/MenuStyling/Editor/MenuStylingPlugin.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Text.RegularExpressions; +using gay.lilyy.Common; using gay.lilyy.MenuStyling; using nadena.dev.ndmf; using nadena.dev.ndmf.vrchat; @@ -19,7 +20,7 @@ namespace gay.lilyy.MenuStyling { InPhase(BuildPhase.Optimizing).AfterPlugin("gay.lilyy.MenuIconRemover").Run("SetMenuStyling", ctx => { - var obj = ctx.AvatarRootObject.GetComponent(); + var obj = ComponentHelper.GetComponentInChildrenWithError(ctx.AvatarRootObject); if (obj != null) { var descriptor = ctx.VRChatAvatarDescriptor(); diff --git a/MeshCompression/Editor/MeshCompressionEditor.asmdef b/MeshCompression/Editor/MeshCompressionEditor.asmdef index b7c238b..efc431e 100644 --- a/MeshCompression/Editor/MeshCompressionEditor.asmdef +++ b/MeshCompression/Editor/MeshCompressionEditor.asmdef @@ -4,7 +4,8 @@ "references": [ "GUID:23e6cebda363f004aa6e529a95f8a6fc", "GUID:62ced99b048af7f4d8dfe4bed8373d76", - "GUID:5718fb738711cd34ea54e9553040911d" + "GUID:5718fb738711cd34ea54e9553040911d", + "GUID:209cbd2a789c4f72963fdbf1f8a01909" ], "includePlatforms": [ "Editor" diff --git a/MeshCompression/Editor/MeshCompressionPlugin.cs b/MeshCompression/Editor/MeshCompressionPlugin.cs index 2d3c44d..4362bf1 100644 --- a/MeshCompression/Editor/MeshCompressionPlugin.cs +++ b/MeshCompression/Editor/MeshCompressionPlugin.cs @@ -1,3 +1,4 @@ +using gay.lilyy.Common; using gay.lilyy.MeshCompression; using nadena.dev.ndmf; using UnityEditor; @@ -29,7 +30,7 @@ namespace gay.lilyy.MeshCompression InPhase(BuildPhase.Optimizing) .Run("Set Mesh Compression", ctx => { - var defaultConfig = ctx.AvatarRootObject.GetComponent(); + var defaultConfig = ComponentHelper.GetComponentInChildrenWithError(ctx.AvatarRootObject); var renderers = ctx.AvatarRootObject.GetComponentsInChildren(true); foreach (var renderer in renderers)