Skip to content

Commit 066308f

Browse files
committed
fix: Started updating asset title if it was renamed.
1 parent 9f88522 commit 066308f

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

GenericUnityEditorInternals.dll

1 KB
Binary file not shown.

GenericUnityInternals~/GenericUnityEditorInternals/GenericHeaderEditor.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using SolidUtilities.Helpers;
56
using UnityEditor;
67
using Util;
8+
using Object = UnityEngine.Object;
79

810
/// <summary>
911
/// An extension of Editor that changes name of <see cref="GenericScriptableObject"/> assets in the Inspector header.
1012
/// For all other assets, it draws header like before.
1113
/// </summary>
1214
public class GenericHeaderEditor : Editor
1315
{
14-
private static readonly Dictionary<UnityEngine.Object, string> _targetTitlesCache = new Dictionary<UnityEngine.Object, string>();
16+
private static readonly Dictionary<TargetInfo, string> _targetTitlesCache = new Dictionary<TargetInfo, string>();
1517
private static readonly Dictionary<Type, string> _typeNamesCache = new Dictionary<Type, string>();
1618

1719
internal override string targetTitle => GetTitle();
@@ -30,7 +32,9 @@ private string GetTitle()
3032

3133
private string GetOneTitle(Type genericType)
3234
{
33-
if (_targetTitlesCache.TryGetValue(target, out string title))
35+
var targetInfo = new TargetInfo(target);
36+
37+
if (_targetTitlesCache.TryGetValue(targetInfo, out string title))
3438
return title;
3539

3640
string typeName = GetTypeName(genericType);
@@ -40,7 +44,7 @@ private string GetOneTitle(Type genericType)
4044
return $"({typeName})";
4145

4246
title = $"{ObjectNames.NicifyVariableName(target.name)} ({typeName})";
43-
_targetTitlesCache.Add(target, title);
47+
_targetTitlesCache.Add(targetInfo, title);
4448
return title;
4549
}
4650

@@ -59,4 +63,39 @@ private static string GetTypeName(Type genericType)
5963
return typeName;
6064
}
6165
}
66+
67+
internal readonly struct TargetInfo : IEquatable<TargetInfo>
68+
{
69+
public readonly Object Target;
70+
public readonly string Name;
71+
72+
public TargetInfo(Object target)
73+
{
74+
Target = target;
75+
Name = target.name;
76+
}
77+
78+
public override bool Equals(object obj)
79+
{
80+
return obj is TargetInfo info && Equals(info);
81+
}
82+
83+
public bool Equals(TargetInfo p)
84+
{
85+
return (Target == p.Target) && (Name == p.Name);
86+
}
87+
88+
public override int GetHashCode()
89+
{
90+
int hash = 17;
91+
// ReSharper disable once Unity.NoNullPropagation
92+
hash = hash * 23 + Target?.GetHashCode() ?? 0;
93+
hash = hash * 23 + Name.GetHashCode();
94+
return hash;
95+
}
96+
97+
public static bool operator ==(TargetInfo lhs, TargetInfo rhs) => lhs.Equals(rhs);
98+
99+
public static bool operator !=(TargetInfo lhs, TargetInfo rhs) => ! lhs.Equals(rhs);
100+
}
62101
}

OdinInternals.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)