예제 #1
0
        /// <inheritdoc />
        public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data)
        {
            var result = base.OnDragDrop(ref location, data);

            if (result != DragDropEffect.None)
            {
                return(result);
            }

            // Check if drag sth
            Vector3        hitLocation = ViewPosition;
            SceneGraphNode hit         = null;

            if (_dragHandlers.HasValidDrag())
            {
                // Get mouse ray and try to hit any object
                var   ray     = ConvertMouseToRay(ref location);
                float closest = float.MaxValue;
                hit = _window.Graph.Root.RayCast(ref ray, ref closest, SceneGraphNode.RayCastData.FlagTypes.SkipColliders);
                if (hit != null)
                {
                    // Use hit location
                    hitLocation = ray.Position + ray.Direction * closest;
                }
                else
                {
                    // Use area in front of the viewport
                    hitLocation = ViewPosition + ViewDirection * 100;
                }
            }

            // Drag assets
            if (_dragAssets.HasValidDrag)
            {
                result = _dragAssets.Effect;

                // Process items
                for (int i = 0; i < _dragAssets.Objects.Count; i++)
                {
                    var item = _dragAssets.Objects[i];
                    Spawn(item, hit, ref hitLocation);
                }
            }
            // Drag actor type
            else if (_dragActorType.HasValidDrag)
            {
                result = _dragActorType.Effect;

                // Process items
                for (int i = 0; i < _dragActorType.Objects.Count; i++)
                {
                    var item = _dragActorType.Objects[i];
                    Spawn(item, hit, ref hitLocation);
                }
            }

            return(result);
        }
예제 #2
0
        /// <inheritdoc />
        public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data)
        {
            ClearDragEffects();

            var result = base.OnDragDrop(ref location, data);

            if (result != DragDropEffect.None)
            {
                return(result);
            }

            // Check if drag sth
            Vector3        hitLocation = ViewPosition;
            SceneGraphNode hit         = null;

            if (DragHandlers.HasValidDrag())
            {
                GetHitLocation(ref location, out hit, out hitLocation);
            }

            // Drag assets
            if (_dragAssets.HasValidDrag)
            {
                result = _dragAssets.Effect;

                // Process items
                for (int i = 0; i < _dragAssets.Objects.Count; i++)
                {
                    var item = _dragAssets.Objects[i];
                    Spawn(item, hit, ref hitLocation);
                }
            }
            // Drag actor type
            else if (_dragActorType.HasValidDrag)
            {
                result = _dragActorType.Effect;

                // Process items
                for (int i = 0; i < _dragActorType.Objects.Count; i++)
                {
                    var item = _dragActorType.Objects[i];
                    Spawn(item, hit, ref hitLocation);
                }
            }

            DragHandlers.OnDragDrop(new DragDropEventArgs()
            {
                Hit = hit, HitLocation = hitLocation
            });

            return(result);
        }