浏览代码

Merge pull request #303 from Unity-Technologies/fix-empty-strings-blackboard

Blackboard Property fixes.
/main
GitHub 7 年前
当前提交
c268bca4
共有 2 个文件被更改,包括 27 次插入9 次删除
  1. 25
      com.unity.shadergraph/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 11
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs

25
com.unity.shadergraph/Editor/Data/Graphs/AbstractMaterialGraph.cs


if (m_Properties.Contains(property))
return;
property.displayName = property.displayName.Trim();
if (m_Properties.Any(p => p.displayName == property.displayName))
m_Properties.Add(property);
m_AddedProperties.Add(property);
}
public string SanitizePropertyName(string displayName, Guid guid = default(Guid))
{
displayName = displayName.Trim();
if (m_Properties.Any(p => p.displayName == displayName && p.guid != guid))
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();
// Strip out the " (n)" part of the name.
var baseRegex = new Regex(@"^(.*) \((\d+)\)$");
var baseMatch = baseRegex.Match(displayName);
if (baseMatch.Success)
displayName = baseMatch.Groups[1].Value;
var regex = new Regex(@"^" + Regex.Escape(displayName) + @" \((\d+)\)$");
var existingDuplicateNumbers = m_Properties.Where(p => p.guid != guid).Select(p => regex.Match(p.displayName)).Where(m => m.Success).Select(m => int.Parse(m.Groups[1].Value)).Where(n => n > 0).Distinct().ToList();
var duplicateNumber = 1;
existingDuplicateNumbers.Sort();

}
}
}
property.displayName = string.Format("{0} ({1})", property.displayName, duplicateNumber);
displayName = string.Format("{0} ({1})", displayName, duplicateNumber);
m_Properties.Add(property);
m_AddedProperties.Add(property);
return displayName;
}
public void RemoveShaderProperty(Guid guid)

11
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs


{
var field = (BlackboardField)visualElement;
var property = (IShaderProperty)field.userData;
if (newText != property.displayName)
if (!string.IsNullOrEmpty(newText) && newText != property.displayName)
newText = m_Graph.SanitizePropertyName(newText, property.guid);
public void HandleGraphChanges()
{

{
if (m_PropertyRows.ContainsKey(property.guid))
return;
if (create)
property.displayName = m_Graph.SanitizePropertyName(property.displayName);
var field = new BlackboardField(m_ExposedIcon, property.displayName, property.propertyType.ToString()) { userData = property };
var row = new BlackboardRow(field, new BlackboardFieldPropertyView(m_Graph, property));
row.userData = property;

if (create)
{
field.OpenTextEditor();
field.OpenTextEditor();
}
}

正在加载...
取消
保存