public override VisualElement CreateCommandEditorGUI() { var root = new VisualElement(); var target = CommandItem.CommandProperty.GetProperty().FindPropertyRelative("target"); var p = new TypeSelectableVariableReferencePropertyDrawer(); root.Add(p.CreatePropertyGUI(target)); return(root); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var tree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(uxml); var root = tree.CloneTree(); var a = root.Q("BoxA"); var b = root.Q("BoxB"); var c = root.Q("BoxC"); var p = new TypeSelectableVariableReferencePropertyDrawer(); var aField = new PropertyField(property.FindPropertyRelative("left")); var bField = new PropertyField(property.FindPropertyRelative("right0")); var cField = new PropertyField(property.FindPropertyRelative("right1")); var operatorButton = root.Q <Button>("OperatorButton");; var operatorProp = property.FindPropertyRelative("calculationOperator"); int operatorEnumValueIndex = operatorProp.enumValueIndex; var operatorEnumValue = Enum.GetValues(typeof(CalculationOperatorType)).GetValue(operatorEnumValueIndex); CalculationOperatorType[] types = new[] { CalculationOperatorType.Add, CalculationOperatorType.Subtract, CalculationOperatorType.Multiply, CalculationOperatorType.Divide }; string[] typeLabels = new[] { "+", "ー", "×", "/" }; var labelIndex = Array.IndexOf(types, operatorEnumValue); if (labelIndex == -1) { operatorButton.text = ""; } else { operatorButton.text = typeLabels[labelIndex]; } operatorButton.clickable.clicked += () => { var menu = new GenericMenu(); for (var i = 0; i < types.Length; i++) { Action <SerializedProperty, int> onItemSelected = (prop, index) => { menu.AddItem(new GUIContent(typeLabels[index]), false, () => { prop.enumValueIndex = (int)types[index]; prop.serializedObject.ApplyModifiedProperties(); operatorButton.text = typeLabels[index]; }); }; onItemSelected(operatorProp, i); } var menuPosition = new Vector2(operatorButton.layout.xMin, operatorButton.layout.height); menuPosition = operatorButton.LocalToWorld(menuPosition); var menuRect = new Rect(menuPosition, Vector2.zero); menu.DropDown(menuRect); }; a.Add(aField); b.Add(bField); c.Add(cField); return(root); }