//Handle mouse dragging here. void Update() { if (!DFConnection.Connected || GameMap.Instance == null || !GameMap.Instance.enabled) { return; } //mouseWorldPosition = GetMouseWorldPosition(Input.mousePosition); if (DFConnection.Instance.WorldMode != dfproto.GetWorldInfoOut.Mode.MODE_ADVENTURE) { UpdateCameraPan(); } if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject()) { Ray mouseRay = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition); DFCoord currentTarget; RaycastHit currentTargetCoords; if (DFConnection.Connected && GameMap.Instance.enabled && MapDataStore.Raycast(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; } } }
Vector3 GetMouseWorldPosition(Vector3 mousePosition) { DFCoord dfTarget; //dummy coord to hold things for now. RaycastHit WorldPos; Ray mouseRay = GetComponent <Camera>().ScreenPointToRay(mousePosition); if (!MapDataStore.Raycast(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.point = mouseRay.GetPoint(distance); } else { WorldPos.point = Vector3.zero; } } return(WorldPos.point); }
// 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; RaycastHit hit; if (MapDataStore.Raycast(ray, out mapTargetPos, out hit)) { //lastTargetPos = mapTargetPos; hit.point += (ray.direction * 0.001f); lastTargetPosF = GameMap.UnityToFloatingDFCoord(hit.point); drawing = true; } } } else if (Input.GetMouseButton(0) && drawing) //still dragging { Ray ray = mainCam.ScreenPointToRay(Input.mousePosition); DFCoord mapTargetPos; RaycastHit hit; if (MapDataStore.Raycast(ray, out mapTargetPos, out hit)) { hit.point += (ray.direction * 0.001f); Vector3 mapFloatTargetPos = GameMap.UnityToFloatingDFCoord(hit.point); 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; RaycastHit hit; if (MapDataStore.Raycast(ray, out mapTargetPos, out hit)) { hit.point += ray.direction * 0.001f; Vector3 pos = GameMap.UnityToFloatingDFCoord(hit.point); mapTargetPos = new DFCoord(Mathf.FloorToInt(pos.x), Mathf.FloorToInt(pos.y), Mathf.FloorToInt(pos.z)); DrawCursor(mapTargetPos, false); } } } }