public static void Move(CommandItem source, CommandListView dest, int index) { //Debug.Log($"{source.GetIndex()} to {index}"); if (source.ParentList == dest && source.GetIndex() == index) { return; } PersistentSerializedProperty sourcePProp = source.CommandProperty; if (dest.CommandArrayProperty.AbsolutePath.StartsWith(sourcePProp.AbsolutePath)) { EditorUtility.DisplayDialog("", "コマンドをそれ自身の子に移動することはできません。", "OK"); return; } var destItem = dest.AddCommandAt(index, sourcePProp); //コピー元の削除 //データの削除 var sourceIndex = sourcePProp.GetArrayIndex(); source.ParentList.RemoveCommandAt(sourceIndex); //コピー先の選択 destItem.Select(); }
private CommandItem AddCommandElementAt(int index, PersistentSerializedProperty pProp) { var item = new CommandItem(Domain, this, pProp, Move); this.Insert(index, item); return(item); }
/// <summary> /// あるArrayのPersistentSerializedPropertyの子要素を取得する。 /// この方法で生成したPersistentSerializedPropertyは親要素のインデックス変更を追跡する。 /// </summary> /// <param name="array"></param> /// <param name="index"></param> private PersistentSerializedProperty(PersistentSerializedProperty array, int index) { this.PivotParent = array; this.SerializedObject = array.SerializedObject; SetArrayIndex(index); InitArray(); }
/// <summary> /// あるPersistentSerializedPropertyを起点として、そこからの相対パスでPersistentSerializedPropertyを生成する。 /// この方法で生成したPersistentSerializedPropertyは親要素のインデックス変更を追跡する。 /// </summary> /// <param name="pivotParent"></param> /// <param name="relativePath"></param> private PersistentSerializedProperty(PersistentSerializedProperty pivotParent, string relativePath) { this.PivotParent = pivotParent; this.RelativePath = relativePath; this.SerializedObject = pivotParent.SerializedObject; InitArray(); }
/// <summary> /// ルートListViewとしてセットアップします。 /// </summary> /// <param name="onItemSelected">アイテム選択時のコールバック。</param> internal CommandListView(CommandEditorDomain domain, SerializedProperty commandArray) { Domain = domain; CommandArrayProperty = new PersistentSerializedProperty(commandArray); if (!CommandArrayProperty.IsArray) { throw new ArgumentException("commandArray must be an array."); } BuildList(); }
public CommandListView(CommandListView parentList, PersistentSerializedProperty commandArray) { Domain = parentList.Domain; CommandArrayProperty = commandArray; if (!CommandArrayProperty.IsArray) { throw new ArgumentException("commandArray must be an array."); } ParentList = parentList; BuildList(); }
private PersistentSerializedProperty GetDirectChild(string key) { if (Children.ContainsKey(key)) { return(Children[key]); } var n = new PersistentSerializedProperty(this, key); Children.Add(key, n); return(n); }
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 PersistentSerializedProperty InsertArrayElementAt(int index) { EnsureThisIsArray(); CheckArraySizeCorruption(); var prop = GetProperty(); prop.InsertArrayElementAtIndex(index); //Apply insert prop.serializedObject.ApplyModifiedProperties(); var insertedElementProp = new PersistentSerializedProperty(this, ""); ArrayElements.Insert(index, insertedElementProp); //Rebind relativePath of children for (int i = 0; i < prop.arraySize; i++) { ArrayElements[i].SetArrayIndex(i); } return(insertedElementProp); }
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(); }