Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit = new RaycastHit();

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
        {
            if (hit.transform.gameObject.tag == "Zone")
            {
                currentTile = hit.transform.gameObject.GetComponent <Zone>();

                if (currentTile.player_id != prevPlayerID)
                {
                    if (prevPlayerID > 0)
                    {
                        GameObject.Find("Map").GetComponent <Map>().SelectTerritory(prevPlayerID, false);
                    }

                    GameObject.Find("Map").GetComponent <Map>().SelectTerritory(currentTile.player_id, true);
                    prevPlayerID = currentTile.player_id;
                }

                string owner_name = "";

                if (currentTile.player_id > 0)
                {
                    owner_name = GameObject.Find("Map").GetComponent <Map>().playerList[currentTile.player_id].name;

                    Color playerColor = GameObject.Find("Map").GetComponent <Map>().playerList[currentTile.player_id].color;;
                    tileInfoGUI.bgColor = new Color(playerColor.r, playerColor.g, playerColor.b, 0.8f);
                }
                else
                {
                    tileInfoGUI.DefaultColor();
                }

                tileInfoGUI.SetInformation(currentTile.terrain_type, currentTile.v_capacity, owner_name);
                tileInfoGUI.position = Camera.main.WorldToScreenPoint(currentTile.transform.position);

                tileInfoGUI.SetActive(true);

                roamingCursor.SetActive(true);
                roamingCursor.transform.position = currentTile.transform.position + new Vector3(0, 0.1f, 0);
//				roamingCursor.renderer.material.color = new Color32(0, 181, 248, 255);
            }
        }
        else
        {
            tileInfoGUI.SetActive(false);
            roamingCursor.SetActive(false);
            currentTile = null;
        }

        switch (InputExtended.GetMouseNumClick(0))
        {
        case 1:                 // Single Click
//				mouseDownPos = Input.mousePosition;
//				oldCameraPos = transform.position;
//				if (currentTile != null && currentTile.player_id > 0) {
//					mapCamera.Center(currentTile.player_id);
//					mapCamera.isLeaving = mapCamera.isZooming = true;
//				}
            break;

        case 2:                 // Double Click
            if (currentTile.player_id == GameState.player.GetID())
            {
                mapCamera.Move(currentTile.transform.position);
            }
            break;
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (PerformCameraEntrance())
        {
            return;
        }

        switch (InputExtended.GetMouseNumClick(0))
        {
        case 1:                 // Single Click
            mouseDownPos = Input.mousePosition;
            oldCameraPos = transform.position;
            break;

        case 2:                 // Double Click
            isZoomed = !isZoomed;

            if (isZoomed)
            {
                RaycastHit hit = new RaycastHit();
                if (Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit))
                {
                    float xPos = hit.point.x;
                    xPos = Mathf.Clamp(xPos, zLowerBound.x, zUpperBound.x);

                    float zPos = hit.point.z + cameraOffset;
                    zPos = Mathf.Clamp(zPos, zLowerBound.z, zUpperBound.z);

                    cameraNextPos = new Vector3(xPos, transform.position.y, zPos);
                }
            }

            isZooming = isPanning = true;
            break;
        }

        if (Input.GetMouseButton(0))
        {
            isDragging = Vector3.Distance(mouseDownPos, Input.mousePosition) > 0.1f;
        }
        else
        {
            isDragging = false;
        }

        if (isZoomed)
        {
            if (isDragging)
            {
                float xPos = oldCameraPos.x + (mouseDownPos.x - Input.mousePosition.x) * 0.2f;
                xPos = Mathf.Clamp(xPos, zLowerBound.x - 20, zUpperBound.x + 20);

                float zPos = oldCameraPos.z + (mouseDownPos.y - Input.mousePosition.y) * 0.2f;
                zPos = Mathf.Clamp(zPos, zLowerBound.z - 20, zUpperBound.z + 20);

                transform.position = new Vector3(xPos, transform.position.y, zPos);
                isPanning          = false;
            }

            if (isPanning && Vector3.Distance(transform.position, cameraNextPos) > 0.1f)
            {
                transform.position = Vector3.Lerp(transform.position, cameraNextPos, Time.deltaTime * cameraSmoothing);
            }
            else
            {
                isPanning = false;
            }

            if (isZooming && !Mathf.Approximately(camera.fieldOfView, cameraZoomed))
            {
                camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, cameraZoomed, Time.deltaTime * cameraSmoothing);
            }
            else
            {
                isZooming = false;
            }

            if (!isDragging)
            {
                transform.position = Vector3.Lerp(transform.position, new Vector3(Mathf.Clamp(transform.position.x, zLowerBound.x, zUpperBound.x), transform.position.y, Mathf.Clamp(transform.position.z, zLowerBound.z, zUpperBound.z)), Time.deltaTime * cameraSmoothing);
            }
        }
        else
        {
            if (isDragging)
            {
                float xPos = oldCameraPos.x + (mouseDownPos.x - Input.mousePosition.x) * 0.4f;
//				xPos = Mathf.Clamp(xPos, cameraStartPos.x - 30, cameraStartPos.x + 30);
                xPos = Mathf.Clamp(xPos, nLowerBound.x - 30, nUpperBound.x + 30);

                float zPos = oldCameraPos.z + (mouseDownPos.y - Input.mousePosition.y) * 0.4f;
//				zPos = Mathf.Clamp(zPos, cameraStartPos.z - 30, cameraStartPos.z + 30);
                zPos = Mathf.Clamp(zPos, nLowerBound.z - 30, nUpperBound.z + 30);

                transform.position = new Vector3(xPos, transform.position.y, zPos);
                isPanning          = false;
            }

            if (isPanning && Vector3.Distance(transform.position, cameraStartPos) > 0.1f)
            {
                transform.position = Vector3.Lerp(transform.position, cameraStartPos, Time.deltaTime * cameraSmoothing);
            }
            else
            {
                isPanning = false;
            }

            if (isZooming && !Mathf.Approximately(camera.fieldOfView, cameraNormal))
            {
                camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, cameraNormal, Time.deltaTime * cameraSmoothing);
            }
            else
            {
                isZooming = false;
            }

//			if (!isDragging && Vector3.Distance(transform.position, cameraStartPos) > 0.1f) {
//				transform.position = Vector3.Lerp(transform.position, new Vector3(cameraStartPos.x, transform.position.y, cameraStartPos.z), Time.deltaTime * cameraSmoothing);
//			}

            if (!isDragging)
            {
                transform.position = Vector3.Lerp(transform.position, new Vector3(Mathf.Clamp(transform.position.x, nLowerBound.x, nUpperBound.x), transform.position.y, Mathf.Clamp(transform.position.z, nLowerBound.z, nUpperBound.z)), Time.deltaTime * cameraSmoothing);
            }
        }
    }