Example #1
0
        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();
        }
Example #2
0
        private CommandItem AddCommandElementAt(int index, PersistentSerializedProperty pProp)
        {
            var item = new CommandItem(Domain, this, pProp, Move);

            this.Insert(index, item);
            return(item);
        }
Example #3
0
 /// <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();
 }
Example #4
0
 /// <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();
 }
Example #5
0
 /// <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();
 }
Example #6
0
 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();
 }
Example #7
0
        private PersistentSerializedProperty GetDirectChild(string key)
        {
            if (Children.ContainsKey(key))
            {
                return(Children[key]);
            }
            var n = new PersistentSerializedProperty(this, key);

            Children.Add(key, n);
            return(n);
        }
Example #8
0
        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));
        }
Example #9
0
        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);
        }
Example #10
0
        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();
        }