浏览代码

using constants field instead of genericConstants property to get constants tooltips

/main
Steven Leal 4 年前
当前提交
1938ab19
共有 1 个文件被更改,包括 23 次插入20 次删除
  1. 43
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs

43
com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs


[CustomEditor(typeof(ScenarioBase), true)]
class ScenarioBaseEditor : UnityEditor.Editor
{
bool m_HasConstantsField;
ScenarioBase m_Scenario;
SerializedObject m_SerializedObject;
VisualElement m_Root;

SerializedProperty m_ConstantsProperty;
public override VisualElement CreateInspectorGUI()
{

var iterator = m_SerializedObject.GetIterator();
var foundProperties = false;
m_HasConstantsField = false;
if (iterator.NextVisible(true))
{
do

m_RandomizerListPlaceholder.Add(new RandomizerList(iterator.Copy()));
break;
case "constants":
m_ConstantsProperty = iterator.Copy();
m_ConstantsProperty.NextVisible(true);
do
{
var constantsPropertyField = new PropertyField(m_ConstantsProperty.Copy());
constantsPropertyField.Bind(m_SerializedObject);
var originalField = m_Scenario.genericConstants.GetType().GetField(m_ConstantsProperty.name);
var tooltipAttribute = originalField.GetCustomAttributes(true).ToList().Find(att => att.GetType() == typeof(TooltipAttribute));
if (tooltipAttribute != null)
{
constantsPropertyField.tooltip = (tooltipAttribute as TooltipAttribute)?.tooltip;
}
m_ConstantsListVisualContainer.Add(constantsPropertyField);
} while (m_ConstantsProperty.NextVisible(true));
m_HasConstantsField = true;
CreateConstantsFieldsWithToolTips(iterator.Copy());
break;
default:
{

void CheckIfConstantsExist()
{
m_ConstantsListVisualContainer = m_Root.Q<VisualElement>("constants-container");
if (m_ConstantsProperty == null)
if (!m_HasConstantsField)
}
void CreateConstantsFieldsWithToolTips(SerializedProperty constantsProperty)
{
constantsProperty.NextVisible(true);
do
{
var constantsPropertyField = new PropertyField(constantsProperty.Copy());
constantsPropertyField.Bind(m_SerializedObject);
var originalField = target.GetType().GetField("constants").FieldType.GetField(constantsProperty.name);
var tooltipAttribute = originalField.GetCustomAttributes(true).ToList().Find(att => att.GetType() == typeof(TooltipAttribute));
if (tooltipAttribute != null)
constantsPropertyField.tooltip = (tooltipAttribute as TooltipAttribute)?.tooltip;
m_ConstantsListVisualContainer.Add(constantsPropertyField);
} while (constantsProperty.NextVisible(true));
}
}
}
正在加载...
取消
保存