Files
2026-07-12 18:53:05 +04:00

81 lines
2.0 KiB
C#
Executable File

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public static class FindRealDuplicates
{
static readonly Regex DuplicateSuffix =
new Regex(@"\s\(\d+\)$");
[MenuItem("Tools/Find Real Duplicates")]
static void Find()
{
var transforms = Object.FindObjectsByType<Transform>(
FindObjectsSortMode.None);
var groups = new Dictionary<string, List<Transform>>();
foreach (var t in transforms)
{
string parentId = t.parent
? GetPath(t.parent)
: "<ROOT>";
string baseName =
DuplicateSuffix.Replace(t.name, "");
string key =
$"{parentId}|{baseName}|{t.position}";
if (!groups.TryGetValue(key, out var list))
{
list = new List<Transform>();
groups[key] = list;
}
list.Add(t);
}
int count = 0;
foreach (var pair in groups)
{
if (pair.Value.Count < 2)
continue;
count++;
var first = pair.Value[0];
Debug.Log(
$"=== DUPLICATE GROUP #{count} ===\n" +
$"Base name: {DuplicateSuffix.Replace(first.name, "")}\n" +
$"Parent: {(first.parent ? GetPath(first.parent) : "<ROOT>")}\n" +
$"Position: {first.position}\n" +
$"Objects: {pair.Value.Count}");
foreach (var t in pair.Value)
{
Debug.Log(
$"• {GetPath(t)}",
t.gameObject);
}
}
Debug.Log($"Found {count} duplicate groups.");
}
static string GetPath(Transform t)
{
string path = t.name;
while (t.parent != null)
{
t = t.parent;
path = t.name + "/" + path;
}
return path;
}
}