// Get dragged objects from DragAndDrop or null if none exists // or none is of the requried type. protected T[] GetDraggedObjects() { IEnumerable <object> items = DragAndDrop.GetGenericData(DATA_OBJECTS) as object[]; if (items == null || !items.Any()) { items = DragAndDrop.objectReferences; } return(items.OfType <T>().ToArray()); }
private void HandleDragAndDrop(SerializedProperty property, bool isDragging, bool isDropping, string guid) { var aaSettings = AddressableAssetSettingsDefaultObject.Settings; //During the drag, doing a light check on asset validity. The in-depth check happens during a drop, and should include a log if it fails. var rejectedDrag = false; if (isDragging) { if (aaSettings == null) { rejectedDrag = true; } else { var aaEntries = DragAndDrop.GetGenericData("AssetEntryTreeViewItem") as List <AssetEntryTreeViewItem>; rejectedDrag = AssetReferenceDrawerUtilities.ValidateDrag(m_AssetRefObject, Restrictions, aaEntries, DragAndDrop.objectReferences, DragAndDrop.paths); } DragAndDrop.visualMode = rejectedDrag ? DragAndDropVisualMode.Rejected : DragAndDropVisualMode.Copy; } if (!rejectedDrag && isDropping) { var aaEntries = DragAndDrop.GetGenericData("AssetEntryTreeViewItem") as List <AssetEntryTreeViewItem>; if (aaEntries != null) { if (aaEntries.Count == 1) { var item = aaEntries[0]; if (item.entry != null) { if (item.entry.IsInResources) { Addressables.LogWarning("Cannot use an AssetReference on an asset in Resources. Move asset out of Resources first."); } else { if (AssetReferenceDrawerUtilities.SetObject(ref m_AssetRefObject, ref m_ReferencesSame, property, item.entry.TargetAsset, fieldInfo, m_label.text, out guid)) { TriggerOnValidate(property); } } } } } else { if (DragAndDrop.paths != null && DragAndDrop.paths.Length == 1) { var path = DragAndDrop.paths[0]; DragAndDropNotFromAddressableGroupWindow(path, guid, property, aaSettings); } } } }
// Get the list index of the dragged item if the item is being // dragged from the current list or -1 otherwise. protected int GetListIndex() { if (DragAndDrop.GetGenericData(DATA_SOURCE) == List) { return((int?)DragAndDrop.GetGenericData(DATA_INDEX) ?? -1); } else { return(-1); } }
public bool CanDropInsert(int insertionIndex) { if (!ReorderableListControl.CurrentListPosition.Contains(Event.current.mousePosition)) { return(false); } // Drop insertion is possible if the current drag-and-drop operation contains // the supported type of custom data. return(DragAndDrop.GetGenericData(DraggedItem.TypeName) is DraggedItem); }
public bool CanDropInsert(int insertionIndex) { if (!ReorderableListControl.CurrentListPosition.Contains(Event.current.mousePosition)) { return(false); } var data = DragAndDrop.GetGenericData(DraggedListItem.TypeName); return(data is DraggedListItem && metadata.listElementType.IsInstanceOfType(((DraggedListItem)data).item)); }
public BehaviourGraphView(BaseBehaviourGraphEditor editor) { SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); this.AddManipulator(new ContentDragger()); this.AddManipulator(new SelectionDragger()); this.AddManipulator(new ClickSelector()); this.AddManipulator(new RectangleSelector()); this.contentViewContainer.RegisterCallback <GeometryChangedEvent>((evt) => { if (evt.oldRect.width == 0 && evt.oldRect.height == 0) { FrameAll(); } }); SetupSearchWindow(editor); SetupInspector(); this.graphViewChanged += SendPortChangeEvents; this.graphViewChanged += DisposeDeletedElements; this.graphViewChanged += UpdateModel; this.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(USS)); this.RegisterCallback <DragUpdatedEvent>((evt) => { var z = DragAndDrop.GetGenericData("DragSelection"); if (z is List <ISelectable> ) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; } }); this.RegisterCallback <DragPerformEvent>(evt => { if (DragAndDrop.GetGenericData("DragSelection") is List <ISelectable> selectables) { Vector2 offset = new Vector2(0, 0); var pos = evt.mousePosition; foreach (var selectable in selectables) { if (selectable is BlackboardField blackboardField && blackboardField.userData is VariableInfo variableInfo) { var entry = CreateVariable(variableInfo.fieldOffsetInfo, contentViewContainer.WorldToLocal(contentViewContainer.parent.ChangeCoordinatesTo(contentViewContainer.parent, evt.mousePosition)) + offset); variableInfo.model.Entries.Add(entry); var node = entry.CreateNode(this, variableInfo.model.Settings); if (node is IBehaviourGraphNode behaviourGraphNode) { behaviourGraphNode.Model = variableInfo.model; } this.AddElement(node); offset.y += blackboardField.worldBound.height + 2; } } } }); }
protected void OnDragPerformEvent(DragPerformEvent evt) { var selection = DragAndDrop.GetGenericData("DragSelection") as List <IGraphElementModel>; if (selection != null && CanAcceptDrop(selection) && m_InsertIndex != -1) { OnItemDropped(m_InsertIndex, selection); } HideDragIndicator(); evt.StopPropagation(); }
internal static void HandleDragAndDrop(int instanceId, Rect selectionRect) { // HACK: Uses EditorApplication.hierarchyWindowItemOnGUI. // Only works when there is at least one item in the scene. var current = UnityEngine.Event.current; var eventType = current.type; bool isDraggingEvent = eventType == EventType.DragUpdated; bool isDropEvent = eventType == EventType.DragPerform; if (isDraggingEvent || isDropEvent) { var mouseOverWindow = EditorWindow.mouseOverWindow; if (mouseOverWindow != null) { // One, existing, valid SkeletonDataAsset var references = UnityEditor.DragAndDrop.objectReferences; if (references.Length == 1) { var skeletonDataAsset = references[0] as SkeletonDataAsset; if (skeletonDataAsset != null && skeletonDataAsset.GetSkeletonData(true) != null) { // Allow drag-and-dropping anywhere in the Hierarchy Window. // HACK: string-compare because we can't get its type via reflection. const string HierarchyWindow = "UnityEditor.SceneHierarchyWindow"; const string GenericDataTargetID = "target"; if (HierarchyWindow.Equals(mouseOverWindow.GetType().ToString(), System.StringComparison.Ordinal)) { if (isDraggingEvent) { UnityEditor.DragAndDrop.visualMode = DragAndDropVisualMode.Copy; var mouseOverTarget = UnityEditor.EditorUtility.InstanceIDToObject(instanceId); if (mouseOverTarget) { DragAndDrop.SetGenericData(GenericDataTargetID, mouseOverTarget); } // note: do not use the current event, otherwise we lose the nice mouse-over highlighting. } else if (isDropEvent) { var parentGameObject = DragAndDrop.GetGenericData(GenericDataTargetID) as UnityEngine.GameObject; Transform parent = parentGameObject != null ? parentGameObject.transform : null; DragAndDropInstantiation.ShowInstantiateContextMenu(skeletonDataAsset, Vector3.zero, parent); UnityEditor.DragAndDrop.AcceptDrag(); current.Use(); return; } } } } } } }
protected override DragAndDropVisualMode HandleDragAndDrop(TreeView.DragAndDropArgs args) { var target = args.parentItem; if (target == null) { return(DragAndDropVisualMode.Rejected); } var targetData = this.idToDataMap[target.id]; // Eventually handle moving to other DataSets, but not yet if (!(targetData is TransformData)) { return(DragAndDropVisualMode.Rejected); } if (!args.performDrop) { return(DragAndDropVisualMode.Link); } foreach (var item in DragAndDrop.GetGenericData("Items") as List <int> ) { var data = this.idToDataMap[item] as TransformData; // Unity gets mad if we swap parent and child, so don't allow that. if (data == (targetData as TransformData).Parent) { return(DragAndDropVisualMode.Rejected); } data.Parent = targetData as TransformData; var sceneProxy = this.getSceneProxy(data.DataSetGuid, data.Name); if (sceneProxy == null) { continue; } var parentSceneProxy = this.getSceneProxy(data.Parent.DataSetGuid, data.Parent.Name); if (parentSceneProxy == null) { continue; } sceneProxy.transform.SetParent(parentSceneProxy.transform); } this.Reload(); DragAndDrop.AcceptDrag(); return(DragAndDropVisualMode.Link); }
public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos) { FooDragData genericData = DragAndDrop.GetGenericData("FooDragging") as FooDragData; FooTreeViewItem item = parentItem as FooTreeViewItem; if ((item != null) && (genericData != null)) { bool flag = this.ValidDrag(parentItem, genericData.m_DraggedItems); if (perform && flag) { if (< > f__am$cache0 == null) {
public DragAndDropData(DragAndDropArgs a) { args = a; draggedNodes = DragAndDrop.GetGenericData("AssetBundleModel.BundleInfo") as List <AssetBundleModel.BundleInfo>; targetNode = args.parentItem as AssetBundleModel.BundleTreeItem; paths = DragAndDrop.paths; if (draggedNodes != null) { foreach (var bundle in draggedNodes) { if ((bundle as AssetBundleModel.BundleFolderInfo) != null) { hasBundleFolder = true; } else { var dataBundle = bundle as AssetBundleModel.BundleDataInfo; if (dataBundle != null) { if (dataBundle.isSceneBundle) { hasScene = true; } else { hasNonScene = true; } if ((dataBundle as AssetBundleModel.BundleVariantDataInfo) != null) { hasVariantChild = true; } } } } } else if (DragAndDrop.paths != null) { foreach (var assetPath in DragAndDrop.paths) { if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(SceneAsset)) { hasScene = true; } else { hasNonScene = true; } } } }
protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) { var data = DragAndDrop.GetGenericData(typeof(StringTreeViewItem).FullName) as StringTreeViewItem; if (data == null) { return(DragAndDropVisualMode.None); } if (args.performDrop) { if (args.dragAndDropPosition == DragAndDropPosition.OutsideItems) { data.RemoveField(); ((StringTreeViewItem)rootItem).DropItemAt(rootItem.children.Count - 1, data); DragAndDrop.AcceptDrag(); } else if (args.dragAndDropPosition == DragAndDropPosition.BetweenItems) { var parent = args.parentItem as StringTreeViewItem; var index = args.insertAtIndex; // fix index when dragging within a single object if (parent.children.Contains(data) && parent.children.IndexOf(data) < index) { index--; } data.RemoveField(); parent.DropItemAt(index, data); DragAndDrop.AcceptDrag(); } else if (args.dragAndDropPosition == DragAndDropPosition.UponItem) { var parent = args.parentItem.parent as StringTreeViewItem; var index = args.parentItem.parent.children.IndexOf(args.parentItem); // fix index when dragging within a single object if (parent.children.Contains(data) && parent.children.IndexOf(data) < index) { index--; } data.RemoveField(); parent.DropItemAt(index, data); DragAndDrop.AcceptDrag(); } } return(DragAndDropVisualMode.Move); }
public override void OnInspectorGUI() { object[] DDInfo = (object[])DragAndDrop.GetGenericData("AKWwiseDDInfo"); if (DDInfo != null && DDInfo.Length >= 4) { string DDTypeName = (string)DDInfo[3]; if (Event.current.type == EventType.DragExited && m_isInDropArea && DDTypeName.Equals(m_typeName)) { Guid DDGuid = (Guid)DDInfo[4]; AkUtilities.SetByteArrayProperty(m_guidProperty[1], DDGuid.ToByteArray()); } } base.OnInspectorGUI(); }
/* * ----------------------- * UpdateDrag() * ----------------------- */ void UpdateDrag(Event e) { CustomDragData dragData = DragAndDrop.GetGenericData(dragDropIdentifier) as CustomDragData; if (dragData == null) { return; } int groupIndex = FindGroupIndex(e); switch (e.type) { case EventType.DragUpdated: if ((groupIndex >= 0) && (groupIndex != selectedGroup)) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } e.Use(); break; case EventType.Repaint: if ((DragAndDrop.visualMode == DragAndDropVisualMode.None) || (DragAndDrop.visualMode == DragAndDropVisualMode.Rejected)) { break; } if (groupIndex >= 0 && groupIndex < groups.size) { EditorGUI.DrawRect(groups[groupIndex].rect, new Color(0f, 1f, 0f, 0.1f)); } break; case EventType.DragPerform: DragAndDrop.AcceptDrag(); // queue the sound FX move QueueSoundFXMove(dragData.originalGroupIndex, dragData.originalIndex, groupIndex); e.Use(); break; case EventType.MouseUp: // in case MouseDrag never occurred: DragAndDrop.PrepareStartDrag(); break; } }
private static void OnDragPerform(DragPerformEvent evt) { if (evt.target is IDragReceiver receiver) { var objects = DragAndDrop.objectReferences; var data = DragAndDrop.GetGenericData(_dragData); if (receiver.IsDragValid(objects, data)) { DragAndDrop.AcceptDrag(); receiver.AcceptDrag(objects, data); } } }
void OnDragPerform(DragPerformEvent evt) { RemoveDragIndicator(); if (DragAndDrop.GetGenericData("DragSelection") != null) { Vector2 mousePosition = m_BlockContainer.WorldToLocal(evt.mousePosition); IEnumerable <VFXBlockUI> blocksUI = (DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>).Select(t => t as VFXBlockUI).Where(t => t != null); if (!CanDrop(blocksUI)) { return; } int blockIndex = GetDragBlockIndex(mousePosition); BlocksDropped(blockIndex, blocksUI, evt.ctrlKey); DragAndDrop.AcceptDrag(); m_DragStarted = false; RemoveFromClassList("dropping"); } else { var references = DragAndDrop.objectReferences.OfType <VisualEffectSubgraphBlock>(); if (references.Count() > 0 && (!controller.viewController.model.isSubgraph || !references.Any(t => t.GetResource().GetOrCreateGraph().subgraphDependencies.Contains(controller.viewController.model.subgraph) || t.GetResource() == controller.viewController.model))) { var context = references.First().GetResource().GetOrCreateGraph().children.OfType <VFXBlockSubgraphContext>().FirstOrDefault(); if (context != null && (context.compatibleContextType & controller.model.contextType) == controller.model.contextType) { DragAndDrop.AcceptDrag(); Vector2 mousePosition = m_BlockContainer.WorldToLocal(evt.mousePosition); int blockIndex = GetDragBlockIndex(mousePosition); VFXBlock newModel = ScriptableObject.CreateInstance <VFXSubgraphBlock>(); newModel.SetSettingValue("m_Subgraph", references.First()); controller.AddBlock(blockIndex, newModel); } evt.StopPropagation(); } } m_DragStarted = false; RemoveFromClassList("dropping"); }
public override void OnGUI() { if (this.button == null) { this.button = new GUIStyle(GUI.skin.button); } float w = this.button.CalcSize(this.content).x; if (this.image == null) { this.button.padding.left = GUI.skin.button.padding.left; } else { this.button.padding.left = (int)this.hub.height; w += 12F; // Remove texture width, because Button calculates using the whole height. } Rect r = GUILayoutUtility.GetRect(w, this.hub.height, GUI.skin.button); if (Event.current.type == EventType.MouseDrag && Utility.position2D != Vector2.zero && DragAndDrop.GetGenericData(Utility.DragObjectDataName) != null && (Utility.position2D - Event.current.mousePosition).sqrMagnitude >= Constants.MinStartDragDistance) { Utility.position2D = Vector2.zero; DragAndDrop.StartDrag("Drag Object"); Event.current.Use(); } else if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition) == true) { NGEditorGUILayout.PingObject(asset); Utility.position2D = Event.current.mousePosition; DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new Object[] { this.asset }; DragAndDrop.SetGenericData(Utility.DragObjectDataName, 1); } GUI.Button(r, this.content, this.button); if (this.image != null) { r = GUILayoutUtility.GetLastRect(); r.x += 4F; r.width = r.height; GUI.DrawTexture(r, this.image); } }
void OnDragUpdatedEvent(DragUpdatedEvent e) { m_DropArea.AddToClassList("dragover"); object draggedLabel = DragAndDrop.GetGenericData(DraggableLabel.s_DragDataType); if (draggedLabel != null) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; } else { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } }
public static void Update() { DragAndDropManager.AddAction = (DragAndDrop.GetGenericData("AddAction") as Type); if (DragAndDropManager.AddAction != null) { DragAndDropManager.mode = DragAndDropManager.DragMode.AddAction; return; } if (DragAndDrop.GetGenericData("MoveActions") != null) { DragAndDropManager.mode = DragAndDropManager.DragMode.MoveActions; return; } DragAndDropManager.mode = DragAndDropManager.DragMode.None; }
protected virtual void OnDragUpdatedEvent(DragUpdatedEvent evt) { VisualElement visualElement = evt.currentTarget as VisualElement; TreeViewItem tree = null; if (visualElement != null) { var trees = this.Query().Where(v => v is TreeViewItem item && item.HitTest( visualElement.ChangeCoordinatesTo(v, evt.localMousePosition)) ).ToList(); tree = trees.LastOrDefault() as TreeViewItem; } object dragData = DragAndDrop.GetGenericData("uNode"); if (dragData == null && DragAndDrop.objectReferences.Length > 0) { dragData = DragAndDrop.objectReferences[0]; } if (tree == null || dragData == null) { RemoveDragIndicator(); DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; return; } var mPos = visualElement.ChangeCoordinatesTo(tree.titleContainer, evt.localMousePosition); bool isTop = mPos.y <= tree.titleContainer.layout.height / 2; if (!CanAcceptDrop(tree, dragData)) { RemoveDragIndicator(); DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; return; } SetDragIndicator(tree, isTop); if (!m_DragStarted) { // TODO: Do something on first DragUpdated event (initiate drag) m_DragStarted = true; AddToClassList("dropping"); } else { // TODO: Do something on subsequent DragUpdated events DragAndDrop.visualMode = DragAndDropVisualMode.Generic; } }
void Awake() { // Need a minimum of 4 members in DragAndDrop generic data: // GenericData[0] contains the component's name (string) // GenericData[1] contains the component's Guid (Guid) // GenericData[2] contains the component's AkGameObjID (int) // GenericData[3] contains the object's type (string) // We need two more fields for states and switches: // GenericData[4] contains the state or switch group Guid (Guid) // GenericData[5] contains the state or switch group AkGameObjID (int) object[] DDInfo = (object[])DragAndDrop.GetGenericData("AKWwiseDDInfo"); if (DDInfo != null && DDInfo.Length >= 4) { Guid componentGuid = (Guid)DDInfo[1]; int ID = (int)DDInfo[2]; string type = (string)DDInfo[3]; switch (type) { case "AuxBus": CreateAuxBus(componentGuid, ID); break; case "Event": CreateAmbient(componentGuid, ID); break; case "Bank": CreateBank(componentGuid, (string)DDInfo[0]); break; case "State": if (DDInfo.Length == 6) { CreateState(componentGuid, ID, (Guid)DDInfo[4], (int)DDInfo[5]); } break; case "Switch": if (DDInfo.Length == 6) { CreateSwitch(componentGuid, ID, (Guid)DDInfo[4], (int)DDInfo[5]); } break; } GUIUtility.hotControl = 0; } }
private bool IsValidDragDrop(DragAndDropArgs args) { //can't drag onto none or >1 bundles if (m_SourceBundles.Count == 0 || m_SourceBundles.Count > 1) { return(false); } //can't drag nothing if (DragAndDrop.paths == null || DragAndDrop.paths.Length == 0) { return(false); } var data = m_SourceBundles[0] as BundleDataInfo; if (data == null) { return(false); // this should never happen. } var thing = DragAndDrop.GetGenericData("AssetListTreeSource") as AssetListTreeView; if (thing != null) { return(false); } if (data.IsEmpty()) { return(true); } if (data.isSceneBundle) { return(false); } foreach (var assetPath in DragAndDrop.paths) { if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(SceneAsset)) { return(false); } } return(true); }
protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) { var dropData = DragAndDrop.GetGenericData(kPlayerlooplistviewItemId); if (dropData == null) { return(DragAndDropVisualMode.None); } switch (args.dragAndDropPosition) { case DragAndDropPosition.OutsideItems: case DragAndDropPosition.UponItem: return(DragAndDropVisualMode.None); case DragAndDropPosition.BetweenItems: if (args.parentItem == rootItem) { return(DragAndDropVisualMode.None); } if (args.performDrop) { var itemId = (int)dropData; var item = FindItem(itemId, rootItem); if (item.parent == args.parentItem && item.parent.children.IndexOf(item) < args.insertAtIndex) { --args.insertAtIndex; } item.parent.children.Remove(item); item.parent = args.parentItem; args.parentItem.children.Insert(args.insertAtIndex, item); var selectedType = playerLoopSystemsByListID[itemId].type; var expandedTypes = GetExpandedTypes(); RecreatePlayerLoop(); SetExpandedFromTypes(expandedTypes); SetSelectionFromType(selectedType); } break; default: throw new ArgumentException("Unrecognized DragAndDropPosition"); } return(DragAndDropVisualMode.Move); }
protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) { Debug.Log("HandleDragAndDrop: " + args.dragAndDropPosition); base.HandleDragAndDrop(args); // Check if we can handle the current drag data (could be dragged in from other areas/windows in the editor) var draggedRows = DragAndDrop.GetGenericData(k_GenericDragID) as List <TreeViewItem>; if (draggedRows == null) { return(DragAndDropVisualMode.None); } // Parent item is null when dragging outside any tree view items. switch (args.dragAndDropPosition) { case DragAndDropPosition.UponItem: case DragAndDropPosition.BetweenItems: { bool validDrag = ValidDrag(args.parentItem, draggedRows); if (args.performDrop && validDrag) { Debug.Log("Drop"); MoveTreeViewItem(draggedRows[0], args.parentItem, args.insertAtIndex); } return(validDrag ? DragAndDropVisualMode.Move : DragAndDropVisualMode.None); } case DragAndDropPosition.OutsideItems: { if (args.performDrop) { Debug.Log("Drop"); //OnDropDraggedElementsAtIndex(draggedRows, m_TreeModel.root, m_TreeModel.root.children.Count); } return(DragAndDropVisualMode.Move); } default: Debug.LogError("Unhandled enum " + args.dragAndDropPosition); return(DragAndDropVisualMode.None); } }
private bool DropValidate(object listObject, string listPath) { DragData dragData = DragAndDrop.GetGenericData("ListDragData") as DragData; if (dragData != null) { if (dragData.Editor == Editor && dragData.ListPath == listPath) { return(true); } Type listType = Utilities.GetElementType(listObject); Type listType2 = Utilities.GetElementType(dragData.Object); return(listType != null && listType2 == listType); } return(false); }
protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) { if (DragAndDrop.GetGenericData(kIsFolderGenericData) as string == "isFolder") { if (args.dragAndDropPosition == DragAndDropPosition.UponItem) { if (args.performDrop) { VirtualFolderInfo info = m_Infos.Find(args.parentItem.id); info.path = DragAndDrop.paths[0]; } return(DragAndDropVisualMode.Link); } return(DragAndDropVisualMode.None); } var draggedRows = DragAndDrop.GetGenericData(kGenericDragId) as List <TreeViewItem>; if (draggedRows == null) { return(DragAndDropVisualMode.None); } switch (args.dragAndDropPosition) { case DragAndDropPosition.UponItem: case DragAndDropPosition.BetweenItems: { bool validDrag = ValidDrag(args.parentItem, draggedRows); if (args.performDrop && validDrag) { OnDropDraggedElementsAtIndex(draggedRows, args.parentItem, args.insertAtIndex == -1 ? 0 : args.insertAtIndex); } return(validDrag ? DragAndDropVisualMode.Move : DragAndDropVisualMode.None); } case DragAndDropPosition.OutsideItems: { return(DragAndDropVisualMode.None); } default: Debug.LogError("Unhandled enum " + args.dragAndDropPosition); return(DragAndDropVisualMode.None); } }
void OnDragUpdated(DragUpdatedEvent evt) { Vector2 mousePosition = m_BlockContainer.WorldToLocal(evt.mousePosition); int blockIndex = GetDragBlockIndex(mousePosition); if (DragAndDrop.GetGenericData("DragSelection") != null) { IEnumerable <VFXBlockUI> blocksUI = (DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>).Select(t => t as VFXBlockUI).Where(t => t != null); DragAndDrop.visualMode = evt.ctrlKey ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move; DraggingBlocks(blocksUI, blockIndex); if (!m_DragStarted) { // TODO: Do something on first DragUpdated event (initiate drag) m_DragStarted = true; AddToClassList("dropping"); } else { // TODO: Do something on subsequent DragUpdated events } } else { var references = DragAndDrop.objectReferences.OfType <VisualEffectSubgraphBlock>(); if (references.Count() > 0 && (!controller.viewController.model.isSubgraph || !references.Any(t => t.GetResource().GetOrCreateGraph().subgraphDependencies.Contains(controller.viewController.model.subgraph) || t.GetResource() == controller.viewController.model))) { var context = references.First().GetResource().GetOrCreateGraph().children.OfType <VFXBlockSubgraphContext>().FirstOrDefault(); if (context != null && (context.compatibleContextType & controller.model.contextType) == controller.model.contextType) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; evt.StopPropagation(); DraggingBlocks(Enumerable.Empty <VFXBlockUI>(), blockIndex); if (!m_DragStarted) { // TODO: Do something on first DragUpdated event (initiate drag) m_DragStarted = true; AddToClassList("dropping"); } } } } }
public void Drag(ref AssetDragAndDropArgs dragargs, ref DragAndDropVisualMode dragmd) { var draggedRows = DragAndDrop.GetGenericData("AssetTreeViewDragging") as List <TreeViewItem>; if (draggedRows != null) { switch (dragargs.dragAndDropPosition) { case AssetDragAndDropArgs.DragAndDropPosition.UponItem: case AssetDragAndDropArgs.DragAndDropPosition.BetweenItems: { bool validDrag = dragargs.parentItem.depth != 0; if (dragargs.performDrop && validDrag) { if (dragargs.parentItem.parent != null) { AssetTreeItem <SpriteTrackData> itemdata = dragargs.parentItem as AssetTreeItem <SpriteTrackData>; if (itemdata != null && itemdata.GetData().ShowMode == SpriteShowMode.Atlas && itemdata.depth == 1) { OnDropDraggedElements(draggedRows, itemdata); } } } dragmd = validDrag ? DragAndDropVisualMode.Move : DragAndDropVisualMode.None; break; } case AssetDragAndDropArgs.DragAndDropPosition.OutsideItems: { dragmd = DragAndDropVisualMode.Move; break; } default: Debug.LogError("Unhandled enum " + dragargs.dragAndDropPosition); dragmd = DragAndDropVisualMode.None; break; } } else { dragmd = DragAndDropVisualMode.None; } }
private void CustomDragUpdated(EditorControl c) { object dragObject = null; ListViewCtrl list = c as ListViewCtrl; if (null == list) { return; } if ( (m_DragBegionCtrl != null) && (m_DragBegionCtrl.Name == list.Name) ) { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } else { dragObject = DragAndDrop.GetGenericData(list.DragAcceptType); if (list.onTryAcceptCustomDrag != null) { if (list.onTryAcceptCustomDrag(list, dragObject)) { if (Event.current.control) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } else { DragAndDrop.visualMode = DragAndDropVisualMode.Move; } } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } } }
public DragAndDropData(DragAndDropArgs a) { args = a; draggedNodes = DragAndDrop.GetGenericData("GraphCollectionDetailTree.DraggedItems") as List <GraphCollectionDetailTreeItem>; foreach (var path in DragAndDrop.paths) { if (TypeUtility.GetMainAssetTypeAtPath(path) == typeof(Model.ConfigGraph)) { if (graphGuids == null) { graphGuids = new List <string>(); } graphGuids.Add(AssetDatabase.AssetPathToGUID(path)); } } }