浏览代码

Make sure that new properties do not alias the names of other properties (#fix 102)

/main
Peter Bay Bastian 7 年前
当前提交
27c461e8
共有 1 个文件被更改,包括 24 次插入0 次删除
  1. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs

24
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;

if (m_Properties.Contains(property))
return;
property.displayName = property.displayName.Trim();
if (m_Properties.Any(p => p.displayName == property.displayName))
{
var regex = new Regex(@"^" + Regex.Escape(property.displayName) + @" \((\d+)\)$");
var existingDuplicateNumbers = m_Properties.Select(p => regex.Match(p.displayName)).Where(m => m.Success).Select(m => int.Parse(m.Groups[1].Value)).Where(n => n > 0).ToList();
var duplicateNumber = 1;
existingDuplicateNumbers.Sort();
if (existingDuplicateNumbers.Any() && existingDuplicateNumbers.First() == 1)
{
duplicateNumber = existingDuplicateNumbers.Last() + 1;
for (var i = 1; i < existingDuplicateNumbers.Count; i++)
{
if (existingDuplicateNumbers[i - 1] != existingDuplicateNumbers[i] - 1)
{
duplicateNumber = existingDuplicateNumbers[i - 1] + 1;
break;
}
}
}
property.displayName = string.Format("{0} ({1})", property.displayName, duplicateNumber);
}
m_Properties.Add(property);
m_AddedProperties.Add(property);

正在加载...
取消
保存