fix: issues with build failures when there are duplicate object paths (#398)

This commit is contained in:
bd_ 2023-08-20 14:15:10 +09:00 committed by GitHub
parent 5a5142bf62
commit 0335c31725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 7 deletions

View File

@ -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");
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3ef07dec7e1d439586f2b925d89483b8
timeCreated: 1692505855

View File

@ -1,18 +1,18 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2022 bd_ * Copyright (c) 2022 bd_
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -25,6 +25,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using NUnit.Framework; using NUnit.Framework;
using Serilog.Sinks.File;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using VRC.SDKBase.Editor.BuildPipeline; using VRC.SDKBase.Editor.BuildPipeline;
@ -150,7 +151,7 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
if (cache != null) return cache; if (cache != null) return cache;
ImmutableDictionary<string, string>.Builder builder = ImmutableDictionary.CreateBuilder<string, string>(); ImmutableDictionary<string, string> dict = ImmutableDictionary<string, string>.Empty;
foreach (var kvp in _objectToOriginalPaths) foreach (var kvp in _objectToOriginalPaths)
{ {
@ -168,11 +169,14 @@ namespace nadena.dev.modular_avatar.core.editor
var newPath = RuntimeUtil.AvatarRootPath(obj); var newPath = RuntimeUtil.AvatarRootPath(obj);
foreach (var origPath in paths) 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; return cache;
} }