Ejemplo n.º 1
0
    //Handle mouse dragging here.
    void Update()
    {
        if (!DFConnection.Connected || GameMap.Instance == null || !GameMap.Instance.enabled)
        {
            return;
        }

        //mouseWorldPosition = GetMouseWorldPosition(Input.mousePosition);

        UpdateCameraPan();

        if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            Ray mouseRay = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);

            DFCoord currentTarget;
            Vector3 currentTargetCoords;
            if (DFConnection.Connected && GameMap.Instance.enabled && MapDataStore.FindCurrentTarget(mouseRay, out currentTarget, out currentTargetCoords))
            {
                GameMap.Instance.cursX = currentTarget.x;
                GameMap.Instance.cursY = currentTarget.y;
                GameMap.Instance.cursZ = currentTarget.z;
            }
            else
            {
                GameMap.Instance.cursX = -30000;
                GameMap.Instance.cursY = -30000;
                GameMap.Instance.cursZ = -30000;
            }
        }
    }
Ejemplo n.º 2
0
    Vector3 GetMouseWorldPosition(Vector3 mousePosition)
    {
        DFCoord dfTarget; //dummy coord to hold things for now.
        Vector3 WorldPos;
        Ray     mouseRay = GetComponent <Camera>().ScreenPointToRay(mousePosition);

        if (!MapDataStore.FindCurrentTarget(mouseRay, out dfTarget, out WorldPos))
        {
            Plane currentPlane = new Plane(Vector3.up, GameMap.DFtoUnityCoord(0, 0, GameMap.Instance.PosZ));
            float distance;
            if (currentPlane.Raycast(mouseRay, out distance))
            {
                WorldPos = mouseRay.GetPoint(distance);
            }
            else
            {
                WorldPos = Vector3.zero;
            }
        }
        return(WorldPos);
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (diggingTool.digMode != DiggingTool.DigMode.None)
        {
            //start the drag. This is the same for all shapes.
            if (Input.GetMouseButtonDown(0))
            {
                if (EventSystem.current.IsPointerOverGameObject()) //we just clicked on
                {
                    coordList.Clear();                             //flush out any list we currently have, so the rest doesn't get confused.
                    drawing = false;
                }
                else
                {
                    Ray     ray = mainCam.ScreenPointToRay(Input.mousePosition);
                    DFCoord mapTargetPos;
                    Vector3 unityTargetPos;
                    if (MapDataStore.FindCurrentTarget(ray, out mapTargetPos, out unityTargetPos))
                    {
                        //lastTargetPos = mapTargetPos;
                        unityTargetPos += (ray.direction * 0.001f);
                        lastTargetPosF  = GameMap.UnityToFloatingDFCoord(unityTargetPos);
                        drawing         = true;
                    }
                }
            }
            else if (Input.GetMouseButton(0) && drawing) //still dragging
            {
                Ray     ray = mainCam.ScreenPointToRay(Input.mousePosition);
                DFCoord mapTargetPos;
                Vector3 unityTargetPos;

                if (MapDataStore.FindCurrentTarget(ray, out mapTargetPos, out unityTargetPos))
                {
                    unityTargetPos += (ray.direction * 0.001f);
                    Vector3 mapFloatTargetPos = GameMap.UnityToFloatingDFCoord(unityTargetPos);
                    switch (brushShape)
                    {
                    case BrushShape.Freehand:
                    //if (dragging)
                    //{
                    //    diggingTool.Apply(coordList);
                    //    coordList.Clear();
                    //    RayTrace(coordList, lastTargetPosF, mapFloatTargetPos);
                    //}
                    //lastTargetPosF = mapFloatTargetPos;
                    //dragging = true;
                    //break;
                    case BrushShape.Box:
                        coordList.Clear();
                        Box(coordList, lastTargetPosF, mapFloatTargetPos);
                        break;

                    default:
                        break;
                    }
                }

                foreach (var item in coordList)
                {
                    DrawCursor(item, true);
                }
            }
            else if (Input.GetMouseButtonUp(0) && drawing) //released the mouse
            {
                diggingTool.Apply(coordList);
                coordList.Clear();
                drawing = false;
            }
            else if (!EventSystem.current.IsPointerOverGameObject()) // Just hovering over the map.
            {
                Ray     ray = mainCam.ScreenPointToRay(Input.mousePosition);
                DFCoord mapTargetPos;
                Vector3 unityTargetPos;
                if (MapDataStore.FindCurrentTarget(ray, out mapTargetPos, out unityTargetPos))
                {
                    unityTargetPos += ray.direction * 0.001f;
                    Vector3 pos = GameMap.UnityToFloatingDFCoord(unityTargetPos);
                    mapTargetPos = new DFCoord(Mathf.FloorToInt(pos.x), Mathf.FloorToInt(pos.y), Mathf.FloorToInt(pos.z));
                    DrawCursor(mapTargetPos, false);
                }
            }
        }
    }