void Drop() { // Is there a droppable container? Collider col = UICamera.lastHit.collider; DragDropContainer container = (col != null) ? col.gameObject.GetComponent <DragDropContainer>() : null; Debug.Log(container); if (container != null) { // Container found -- parent this object to the container //mTrans.parent = container.transform; //Vector3 pos = mTrans.localPosition; //pos.z = 0f; //mTrans.localPosition = pos; } else { // No valid container under the mouse -- revert the item's parent //mTrans.parent = mParent; } // Notify the table of this change //UpdateTable(); // Make all widgets update their parents //BroadcastMessage("CheckParent", SendMessageOptions.DontRequireReceiver); }
/// <summary> /// Drop the dragged object. /// </summary> void Drop() { // Is there a droppable container? Collider col = UICamera.lastHit.collider; DragDropContainer container = (col != null) ? col.gameObject.GetComponent <DragDropContainer>() : null; if (container != null) { // Container found -- parent this object to the container mTrans.parent = container.transform; Vector3 pos = mTrans.localPosition; pos.z = 0f; mTrans.localPosition = pos; } else { // No valid container under the mouse -- revert the item's parent mTrans.parent = mParent; } // Notify the table of this change UpdateTable(); // Make all widgets update their parents NGUITools.MarkParentAsChanged(gameObject); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } if (this.dragStartPoint.HasValue) { // XamlWriter.Save() has limitations in exactly what is serialized, // see SDK documentation; short term solution only; string xamlString = XamlWriter.Save(this.Content); DragDropContainer dataObject = new DragDropContainer(); dataObject.Data = xamlString; WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel; if (panel != null) { // desired size for DesignerCanvas is the stretched Toolbox item size double scale = 1.3; dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale); } DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); e.Handled = true; } }
/// <summary> /// Drop the dragged object. /// </summary> void Drop() { // Is there a droppable container? Collider col = UICamera.lastHit.collider; DragDropContainer container = (col != null) ? col.gameObject.GetComponent <DragDropContainer>() : null; if (container != null) { // Container found -- parent this object to the container mTrans.parent = (container.reparentTarget != null) ? container.reparentTarget : container.transform; Vector3 pos = mTrans.localPosition; pos.z = 0f; mTrans.localPosition = pos; } else { // No valid container under the mouse -- revert the item's parent mTrans.parent = mParent; } // Restore the depth //UIWidget[] widgets = GetComponentsInChildren<UIWidget>(); //for (int i = 0; i < widgets.Length; ++i) widgets[i].depth = widgets[i].depth - 100; // Notify the table of this change UpdateTable(); // Make all widgets update their parents NGUITools.MarkParentAsChanged(gameObject); }
private void treeViewAss_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragDropContainer dataObject = new DragDropContainer(); dataObject.Data = (object)((TreeViewItem)this.treeViewAss.SelectedItem).Tag; DragDrop.DoDragDrop(this.treeViewAss, dataObject, DragDropEffects.Copy); e.Handled = true; } }
protected override void OnDrop(DragEventArgs e) { //base.OnDrop(e); DragDropContainer dragObject = e.Data.GetData(typeof(DragDropContainer)) as DragDropContainer; if (dragObject != null && dragObject.Data != null) { ReflectDesignItem newItem = null; Object content = dragObject.Data; if (content != null) { newItem = new ReflectDesignItem(); newItem.Style = (Style)Application.Current.FindResource(typeof(DesignerItem)); newItem.DataContext = content; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); } e.Handled = true; } }
private void Drop() { Collider collider = UICamera.lastHit.collider; DragDropContainer container = (collider == null) ? null : collider.gameObject.GetComponent <DragDropContainer>(); if (container != null) { this.mTrans.parent = container.transform; Vector3 localPosition = this.mTrans.localPosition; localPosition.z = 0f; this.mTrans.localPosition = localPosition; } else { this.mTrans.parent = this.mParent; } this.UpdateTable(); NGUITools.MarkParentAsChanged(base.gameObject); }