Exemple #1
0
    private void OnMouseDown()
    {
        if (cameraController != null && !cameraController.IsPointerOverGUI())
        {
            if (!Selected)
            {
                PrevFlagPosition = this.transform.position;
            }

            Selected = true;
            OnFlagMoved?.Invoke(this);
        }
    }
Exemple #2
0
    private void Update()
    {
        if (Selected)
        {
            if (Input.GetMouseButtonUp(0) && Selected)
            {
                Selected = false;
                OnFlagReleased?.Invoke(this);
            }
            else if (Vector3.Distance(prevMousePos, Input.mousePosition) > GlobalConst.EPSILON)
            {
                Ray        raycast = camera.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                int        layerMask = LayerMask.GetMask(GlobalConst.FLOOR_LAYER);

                if (Physics.Raycast(raycast, out hit, 1000, layerMask))
                {
                    Vector3 newPos = hit.point;
                    newPos.y = 0;

                    if (stageEditor.SnapToGrid)
                    {
                        float gridCellSize = stageEditor.GridCellSize;
                        newPos.x = newPos.x / gridCellSize;
                        newPos.x = (float)(gridCellSize * (int)newPos.x);
                        newPos.z = newPos.z / gridCellSize;
                        newPos.z = (float)(gridCellSize * (int)newPos.z);
                    }

                    if (Vector3.Distance(newPos, this.transform.localPosition) > GlobalConst.EPSILON)
                    {
                        if (Vector3.Distance(Vector3.zero, newPos) < GlobalConst.STAGE_RADIUS)
                        {
                            this.transform.localPosition = newPos;
                            OnFlagMoved?.Invoke(this);
                        }
                    }
                }
            }

            prevMousePos = Input.mousePosition;
        }
    }