unity-atoms/Packages/Core/Editor/Utils/AtomNameUtils.cs
Thimo 4912480957
#67 [FEATURE] Set event name suggestion on Variable Changed event creation (#317)
* [Added] Feature for #67 event name suggestion initial version

* [Refactored] Cleaned naming code to its own class

* [Fixed] c# range is not supported in 2019.4 LTS

* * Simplified logic for suggested name in AtomDrawer
* Simplified CleanPropertyName - first if-block was catched by second block
* Replaced FilterLastIndexOf with typeof(T).Name

---------

Co-authored-by: Thimo de Ram <tdram@esites.local>
Co-authored-by: Adam Ramberg <adam@mambojambostudios.com>
2023-07-22 18:54:35 +02:00

27 lines
837 B
C#

using System.Text.RegularExpressions;
using UnityEditor;
namespace UnityAtoms.Editor
{
public static class AtomNameUtils
{
public static string CleanPropertyName(string propertyName)
{
string cleanedProperty = propertyName;
if (Regex.Match(cleanedProperty, @"[a-zA-Z]").Success)
{
var index = Regex.Match(cleanedProperty, @"[a-zA-Z]").Index;
cleanedProperty = cleanedProperty[index].ToString().ToUpper() + cleanedProperty.Substring(index + 1);
}
return cleanedProperty;
}
public static string CreateUniqueName(string atomName)
{
var results = AssetDatabase.FindAssets(atomName);
return results.Length > 0 ? $"{atomName} ({results.Length})" : atomName;
}
}
}