浏览代码

Prevent GC allocation when popup doesnt need to be recreated

/main
Matt Dean 7 年前
当前提交
cb9ab96f
共有 1 个文件被更改,包括 15 次插入2 次删除
  1. 17
      com.unity.shadergraph/Editor/Drawing/Controls/ChannelEnumControl.cs

17
com.unity.shadergraph/Editor/Drawing/Controls/ChannelEnumControl.cs


PopupField<string> m_PopupField;
string[] m_ValueNames;
int m_PreviousChannelCount = -1;
public ChannelEnumControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
AddStyleSheetPath("Styles/Controls/ChannelEnumControlView");

void CreatePopup()
{
int channelCount = SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(m_SlotId).concreteValueType);
{
if(channelCount == m_PreviousChannelCount)
return;
}
int channelCount = SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(m_SlotId).concreteValueType);
m_PreviousChannelCount = channelCount;
m_PopupField = new PopupField<string>(popupEntries, (int)m_PropertyInfo.GetValue(m_Node, null));
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
if(value >= channelCount)
value = 0;
m_PopupField = new PopupField<string>(popupEntries, value);
m_PopupField.OnValueChanged(OnValueChanged);
Add(m_PopupField);
}
正在加载...
取消
保存