|
|
|
|
|
|
[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)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |