private CommandItem AddCommandAt(int index, PersistentSerializedProperty source) { var destPProp = CommandArrayProperty.InsertArrayElementAt(index); var destProp = destPProp.GetProperty(); destProp.managedReferenceValue = null; var sourceProp = source.GetProperty(); CopyCommandProperty(sourceProp, destProp); destProp.serializedObject.ApplyModifiedProperties(); return(AddCommandElementAt(index, destPProp)); }
public CommandItem(CommandEditorDomain domain, CommandListView parentList, PersistentSerializedProperty property, Action <CommandItem, CommandListView, int> onMove) : base() { Domain = domain; ParentList = parentList; CommandProperty = property; this.binding = new CommandItemBinding(() => { if (this != Domain.SelectedItem) { return; } UpdateCommandDetail(); }); VisualTreeAsset uiAsset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(visualTreeAssetPath); VisualElement root = uiAsset.CloneTree(); this.Add(root); this.AddManipulator(new CommandMovableManipulator(this)); this.AddManipulator(new CommandMoveTargetManipulator( ParentList, part => { switch (part) { case MovementPart.Top: return(GetIndex()); case MovementPart.Bottom: return(GetIndex() + 1); default: throw new ArgumentOutOfRangeException(nameof(part), part, null); } }, () => { this.style.borderBottomWidth = new StyleFloat(0f); this.style.borderTopWidth = new StyleFloat(3f); this.style.borderTopColor = new StyleColor(new Color(0.2f, 0.3411765f, 0.8509805f)); }, () => { this.style.borderTopWidth = new StyleFloat(0f); this.style.borderBottomWidth = new StyleFloat(3f); this.style.borderBottomColor = new StyleColor(new Color(0.2f, 0.3411765f, 0.8509805f)); }, () => { this.style.borderTopWidth = new StyleFloat(0f); this.style.borderBottomWidth = new StyleFloat(0f); })); this.RegisterCallback <MouseDownEvent>(evt => { evt.StopPropagation(); Select(); }); var enabledToggle = this.Q <Toggle>("CommandEnabled"); enabledToggle.RegisterCallback <ChangeEvent <bool> >(evt => { var prop = CommandProperty.GetProperty(); var propEnabled = prop.FindPropertyRelative("enabled"); propEnabled.boolValue = evt.newValue; propEnabled.serializedObject.ApplyModifiedProperties(); }); //string typeName = GetTypeName(); var customContentContainer = this.Q <VisualElement>("CommandCustomDetailContent"); customContentContainer.Clear(); Editor = CreateEditor(GetCommandType(), this, customContentContainer); UpdateCommandDetail(); }