diff --git a/Packages/nadena.dev.modular-avatar/Editor/Util.cs b/Packages/nadena.dev.modular-avatar/Editor/Util.cs index b9843e5f..4b105d3d 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/Util.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/Util.cs @@ -140,6 +140,20 @@ namespace nadena.dev.modular_avatar.core.editor SessionState.GetBool("MAIconsDisabled", true); } + internal static T GetOrAddComponent(this Component self) where T : Component + { + var component = self.GetComponent(); + if (component == null) component = self.gameObject.AddComponent(); + return component; + } + + internal static T GetOrAddComponent(this GameObject self) where T : Component + { + var component = self.GetComponent(); + if (component == null) component = self.AddComponent(); + return component; + } + public static string GenerateAssetPath() { return GetGeneratedAssetsFolder() + "/" + GUID.Generate() + ".asset";