Example #1
0
    void OnMouseDrag()
    {
        if (Cell.clickTimer.ElapsedMilliseconds < 300)
        {
            return;
        }
        //Cell.clickTimer.Stop();

        UnityEngine.Debug.Log("OnMouseDrag fired.");
        foreach (Cell cell in Cell.selection.SelectedCells)
        {
            Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y,
                                                 cell.screenPoint.z);
            Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + cell.offset;

            // Bind mouse cursor to within the map bounds.
            if (curPosition.x > Cell.map.BoundOffsetX)
            {
                curPosition.x = Cell.map.BoundOffsetX;
            }
            else if (curPosition.x < -Cell.map.BoundOffsetX)
            {
                curPosition.x = -Cell.map.BoundOffsetX;
            }
            if (curPosition.y > Cell.map.BoundOffsetY)
            {
                curPosition.y = Cell.map.BoundOffsetY;
            }
            else if (curPosition.y < -Cell.map.BoundOffsetY)
            {
                curPosition.y = -Cell.map.BoundOffsetY;
            }
            cell.transform.position = curPosition;

            cell.Site.X = curPosition.x * map.Width + map.BoundOffsetX * map.Width;
            cell.Site.Y = curPosition.y * map.Height + map.BoundOffsetY * map.Height;
        }

        map.RefreshSections();
        map.ClearScreen();
        map.Render();
    }