Exemplo n.º 1
0
    private void SpawnStatChangeText(ShipStats ship, int value, Sprite icon)
    {
        GameObject statChangeText = ship.GetComponent <ShipStatsUI>().statChangeText;
        GameObject instance       = GameObject.Instantiate(statChangeText);

        RectTransform rect = instance.GetComponent <RectTransform>();

        rect.anchoredPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

        instance.transform.parent = ship.GetComponent <ShipStatsUI>().canvas;

        MoveAndFadeBehaviour moveAndFadeBehaviour = instance.GetComponent <MoveAndFadeBehaviour>();

        moveAndFadeBehaviour.offset = new Vector2(0, +75);
        moveAndFadeBehaviour.SetValue(value, icon);
    }
Exemplo n.º 2
0
    public void SpawnStatChangeText(int value, Sprite icon = null)
    {
        ShipStatsUI shipStatsUI  = shipStats.GetComponent <ShipStatsUI>();
        GameObject  statChangeUI = Instantiate(shipStatsUI.statChangeText);

        RectTransform rect = statChangeUI.GetComponent <RectTransform>();

        Vector3 spawnPos = cam.WorldToScreenPoint(transform.GetChild(0).position);

        rect.anchoredPosition = new Vector2(spawnPos.x, spawnPos.y);

        statChangeUI.transform.parent = shipStats.GetComponent <ShipStatsUI>().canvas; // you have to set the parent after you change the anchored position or the position gets messed up.  Don't set it in the instantiation.  I don't know why someone decided to change that.

        MoveAndFadeBehaviour moveAndFadeBehaviour = statChangeUI.GetComponent <MoveAndFadeBehaviour>();

        moveAndFadeBehaviour.offset = new Vector2(0, 25 + transform.GetChild(0).localPosition.y * 100);
        moveAndFadeBehaviour.SetValue(value, icon);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Spawns a pop-up of a number below the stat bar and where the object was clicked. Shows exactly how much a stat changes
    /// </summary>
    /// <param name="statText"> The text that it spawns the next text under</param>
    /// <param name="value"> How much the stat was changed</param>
    /// <param name="icon">The icon it should use when spawning</param>
    /// <param name="canvasNum">The canvas that stat ui should spawn at</param>
    /// <param name="oppositeValueOnRoom">Default false. If true the resouce value will be opposite in -/+ compared to the ship stat bar</param>
    private void SpawnStatChangeText(TMP_Text statText, int value, Sprite icon, int canvasNum, bool oppositeValueOnRoom = false)
    {
        if (value != 0)
        {
            //ERROR: something gets destroyed that it is trying to access
            GameObject instance = Instantiate(statChangeText, statText.gameObject.transform.parent);

            RectTransform rect     = instance.GetComponent <RectTransform>();
            RectTransform statRect = statText.gameObject.GetComponent <RectTransform>();

            rect.anchorMax        = statRect.anchorMax;
            rect.anchorMin        = statRect.anchorMin;
            rect.offsetMax        = statRect.offsetMax;
            rect.offsetMin        = statRect.offsetMin;
            rect.pivot            = statRect.pivot;
            rect.sizeDelta        = statRect.sizeDelta;
            rect.anchoredPosition = statRect.anchoredPosition;

            TMP_Text text = instance.GetComponent <TMP_Text>();

            text.fontSize  = statText.fontSize;
            text.alignment = statText.alignment;

            MoveAndFadeBehaviour moveAndFadeBehaviour = instance.GetComponent <MoveAndFadeBehaviour>();
            moveAndFadeBehaviour.offset = new Vector2(0, -75);
            moveAndFadeBehaviour.SetValue(value);

            if (roomBeingPlaced != null)
            {
                Vector2 pos           = roomBeingPlaced.transform.position;    // get the game object position
                Vector2 viewportPoint = Camera.main.WorldToViewportPoint(pos); //convert game object position to VievportPoint

                GameObject instanceRoom = Instantiate(statChangeTextRoom, roomBeingPlaced.GetComponent <RoomStats>().statCanvas[canvasNum]);

                RectTransform rectRoom     = instanceRoom.GetComponent <RectTransform>();
                RectTransform statRectRoom = statText.gameObject.GetComponent <RectTransform>();

                //rectRoom.anchorMax = viewportPoint;
                //rectRoom.anchorMin = viewportPoint;
                //rectRoom.offsetMax = statRectRoom.offsetMax;
                //rectRoom.offsetMin = statRectRoom.offsetMin;
                //rectRoom.pivot = statRectRoom.pivot;
                //rectRoom.sizeDelta = statRectRoom.sizeDelta;
                //rectRoom.anchoredPosition = roomBeingPlaced.transform.position;

                TMP_Text textRoom = instanceRoom.GetComponent <TMP_Text>();

                //textRoom.fontSize = statText.fontSize;
                //textRoom.alignment = statText.alignment;

                MoveAndFadeBehaviour moveAndFadeBehaviourRoom = instanceRoom.GetComponent <MoveAndFadeBehaviour>();
                moveAndFadeBehaviourRoom.offset = new Vector2(0, -.5f);
                if (oppositeValueOnRoom) // add option to reverse value for stat change UI so that rooms can show removing crew and stat bar can show gaining crew
                {
                    moveAndFadeBehaviourRoom.SetValue(-value, icon);
                }
                else
                {
                    moveAndFadeBehaviourRoom.SetValue(value, icon);
                }
            }
        }
    }