public void OnDrag(PointerEventData eventData)
 {
     if (isInteractable)
     {
         var worldPosition = Camera.main.ScreenToWorldPoint(eventData.position);
         var position      = new Vector3(worldPosition.x, buildingEntity.YOffset, worldPosition.y);
         draggableBuilding?.Drag(position);
     }
 }
Пример #2
0
        private void Update()
        {
            if (gameStateManager.State != GameState.Playing || !TurnManager.HasTurn)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                //set draggable if player clicked on it and is it draggable
                if (currentDraggable == null)
                {
                    Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, 1000f, LayerMask.GetMask("Pawn")))
                    {
                        IDraggable draggableObject = hit.collider.GetComponentInParent <IDraggable>();
                        if (draggableObject.IsDraggable)
                        {
                            currentDraggable = draggableObject;
                        }
                    }
                }
            }

            if (Input.GetMouseButton(0) && currentDraggable != null)
            {
                //drag draggable if the player is holding the left mouse button down and has a draggable
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 1000f, LayerMask.GetMask("GameBoard")))
                {
                    currentDraggable.Drag(hit.point);
                }
            }

            if (Input.GetMouseButtonUp(0) && currentDraggable != null)
            {
                //release and reset the draggable member if the mouse button is up and there was a draggable stored
                currentDraggable.Release();
                currentDraggable = null;
            }
        }
Пример #3
0
 public void Drag(CoreShape.Point oldPoint, CoreShape.Point currentPoint)
 {
     activeShape?.Drag(oldPoint, currentPoint);
 }
Пример #4
0
        /// <summary>
        /// マウスイベントの開始
        /// </summary>
        /// <param name="target">イベント発生元コントロール</param>
        /// <param name="button">ドラッグイベントに対応するマウスボタン</param>
        public void Start(Control target, MouseButtons button)
        {
            IDraggable active = this.DefaultItem;

            //ボタンが押されていない間のマウスムーブイベント
            this.Disposables.Add(
                target.MouseMoveAsObservable()
                .Where(e => e.Button == MouseButtons.None)
                .Subscribe(
                    e =>
            {
                //選択中のオブジェクトを先行してチェック
                active = SelectedItems.HitTest(e.Location);
                if (active != null)
                {
                    target.Cursor = active.Cursor;
                    return;
                }

                //カーソルの下にあるm_shapes内のオブジェクトをactiveに設定する。
                //オブジェクトのない場所にカーソルがある場合はDefaultItemがActiveとなる。
                active = DefaultItem;

                foreach (IDraggable item in Items.Reverse <IDraggable>())
                {
                    var result = item.HitTest(e.Location);
                    if (result != null)
                    {
                        active = result;
                        break;
                    }
                }
                ;
                target.Cursor = active.Cursor;
            }));

            //マウスダウンイベント
            this.Disposables.Add(
                target.MouseDownAsObservable()
                .Subscribe(
                    e =>
            {
                var act = active as ISelectable;
                if (act != null && !act.IsSelected)
                {
                    foreach (ISelectable item in this.Selectables)
                    {
                        item.IsSelected = item == act;
                    }
                    this.SelectedItems = new CompositeDraggable(Enumerable.Empty <IDraggable>());
                    target.Refresh();
                }
                ;
            }));

            //ドラッグイベント
            this.Disposables.Add(
                target.MouseDragAsObservable(button)
                .Subscribe(
                    e =>
            {
                active.Drag(e);
                target.Refresh();
            }));

            //マウスアップイベント
            this.Disposables.Add(
                target.MouseUpAsObservable()
                .Subscribe(
                    e =>
            {
                var item = active.Drop();
                if (item != null)
                {
                    this.AddItem(item);
                }
                target.Refresh();
            }));
        }