Пример #1
0
    private void Awake()
    {
        GameDBCSV db   = GlobalSettings.instance.db;
        Text      text = GetComponent <Text>();

        if (GlobalSettings.instance.win)
        {
            text.text = db.GetTranslation("Good Report");
        }
        else
        {
            text.text = db.GetTranslation("Bad Report");
        }
    }
Пример #2
0
    private void Update()
    {
        Vector2 screenSize = new Vector2(mainCamera.pixelWidth, mainCamera.pixelHeight);

        Ray ray = mainCamera.ScreenPointToRay(GetMousePosition(screenSize));

        RaycastHit hitItem;
        RaycastHit hitWall;

        bool itemCollided = Physics.Raycast(ray, out hitItem, Mathf.Infinity, 1 << LayerMask.NameToLayer("Item"));
        bool wallCollided = Physics.Raycast(ray, out hitWall, Mathf.Infinity, 1 << LayerMask.NameToLayer("Default"));

        Item item = null;

        if (itemCollided)
        {
            item = hitItem.transform.GetComponent <Item>();
        }

        if (itemCollided && (!wallCollided || hitItem.distance < hitWall.distance) && item != null)
        {
            // Highlight
            if (highlightedItem != null)
            {
                highlightedItem.Hide();
            }

            if (item != highlightedItem && !showInfoSound.isPlaying)
            {
                showInfoSound.Play();
            }

            highlightedItem = item;
            highlightedItem.Show();

            // Select
            if (!onSuspect && Input.GetMouseButtonDown(0))
            {
                if (selectedItem != null)
                {
                    selectedItem.Unselect();
                    selectedItem.Hide();

                    if (!selectedSound.isPlaying)
                    {
                        selectedSound.Play();
                    }
                }

                if (selectedItem != highlightedItem)
                {
                    selectedItem = highlightedItem;
                    selectedItem.Select();
                    suspectButton.SetActive(true);

                    if (!selectedSound.isPlaying)
                    {
                        selectedSound.Play();
                    }
                }
                else
                {
                    selectedItem = null;
                    suspectButton.SetActive(false);
                    onSuspect = false;
                }
            }

            // Update panel
            labelText.text       = "<b>" + highlightedItem.label + "</b>";
            priceText.text       = "<b>" + db.GetTranslation("Price") + ":</b> " + highlightedItem.price + " ₽";
            descriptionText.text = "<b>" + db.GetTranslation("Descritption") + ":</b>\n" + highlightedItem.description;
            panel.gameObject.SetActive(true);

            // Place a panel not on the edge and with offset.
            Vector3 itemPosition = mainCamera.WorldToScreenPoint(hitItem.transform.position);

            float   dirOffset     = (itemPosition.x > screenSize.x / 2) ? +offset : -offset;
            Vector3 panelPosition = VectorExt.WithZ(itemPosition, 0.0f) + Vector3.left * dirOffset;

            if (panelPosition.x > screenSize.x - offsetWidth)
            {
                panelPosition = VectorExt.WithX(panelPosition, screenSize.x - offsetWidth);
            }
            if (panelPosition.x < offsetWidth)
            {
                panelPosition = VectorExt.WithX(panelPosition, offsetWidth);
            }

            if (panelPosition.y > screenSize.y - offsetHeight)
            {
                panelPosition = VectorExt.WithY(panelPosition, screenSize.y - offsetHeight);
            }
            if (panelPosition.y < offsetHeight)
            {
                panelPosition = VectorExt.WithY(panelPosition, offsetHeight);
            }

            panel.position = panelPosition;
        }
        else
        {
            panel.gameObject.SetActive(false);
            if (highlightedItem != null)
            {
                highlightedItem.Hide();
                highlightedItem = null;
            }
        }
    }