diff --git a/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs b/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs new file mode 100644 index 00000000..e02d63d9 --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs @@ -0,0 +1,21 @@ +using modular_avatar_tests; +using nadena.dev.modular_avatar.core.editor; +using NUnit.Framework; + +namespace _ModularAvatar.EditModeTests +{ + public class DuplicateObjectNameTest : TestBase + { + [Test] + public void test_duplicate_object_names() + { + var avatar = CreateRoot("root"); + var c1 = CreateChild(avatar, "child"); + var c2 = CreateChild(avatar, "child"); + + PathMappings.Init(avatar); + c2.gameObject.name = "child2"; + Assert.AreEqual(PathMappings.MapPath("child"), "child"); + } + } +} \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs.meta b/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs.meta new file mode 100644 index 00000000..76d0de40 --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3ef07dec7e1d439586f2b925d89483b8 +timeCreated: 1692505855 \ No newline at end of file diff --git a/Packages/nadena.dev.modular-avatar/Editor/PathMappings.cs b/Packages/nadena.dev.modular-avatar/Editor/PathMappings.cs index 790d2b07..9bf32a51 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/PathMappings.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/PathMappings.cs @@ -1,18 +1,18 @@ /* * MIT License - * + * * Copyright (c) 2022 bd_ - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,6 +25,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using NUnit.Framework; +using Serilog.Sinks.File; using UnityEditor; using UnityEngine; using VRC.SDKBase.Editor.BuildPipeline; @@ -150,7 +151,7 @@ namespace nadena.dev.modular_avatar.core.editor { if (cache != null) return cache; - ImmutableDictionary.Builder builder = ImmutableDictionary.CreateBuilder(); + ImmutableDictionary dict = ImmutableDictionary.Empty; foreach (var kvp in _objectToOriginalPaths) { @@ -168,11 +169,14 @@ namespace nadena.dev.modular_avatar.core.editor var newPath = RuntimeUtil.AvatarRootPath(obj); foreach (var origPath in paths) { - builder.Add(origPath, newPath); + if (!dict.ContainsKey(origPath)) + { + dict = dict.Add(origPath, newPath); + } } } - cache = builder.ToImmutableDictionary(); + cache = dict; return cache; }