Ejemplo n.º 1
0
        void UpdateScreenPos()
        {
            Vector3 screenPos = Camera.main.WorldToScreenPoint(targetPos);

            screenPos.z         = 0;
            rectT.localPosition = screenPos * UI.GetScaleFactor();
        }
Ejemplo n.º 2
0
        // Update is called once per frame
        void Update()
        {
            if (!isOn)
            {
                return;
            }

            Vector3 screenPos = Camera.main.WorldToScreenPoint(currentTower.thisT.position);

            floatingButtons.transform.localPosition = screenPos / UI.GetScaleFactor();

            //force the frame to go left when the tower is off screen (specifically for dragNdrop button hover)
            if (currentTower.IsSampleTower())
            {
                if (screenPos.x < 0 || screenPos.x > Screen.width || screenPos.y < 0 || screenPos.y > Screen.height)
                {
                    screenPos.x = Screen.width;
                    currentX    = 0;
                }
            }

            if (currentX < Screen.width / 2 && screenPos.x > Screen.width / 2)
            {
                _SetScreenPos(screenPos);
            }
            else if (currentX > Screen.width / 2 && screenPos.x < Screen.width / 2)
            {
                _SetScreenPos(screenPos);
            }
        }
Ejemplo n.º 3
0
        IEnumerator _UnitOverlay(Unit unit)
        {
            if (overlayedUnitList.Contains(unit))
            {
                yield break;
            }

            overlayedUnitList.Add(unit);

            UnitOverlay overlay = GetUnusedOverlay();

            overlay.rootObj.SetActive(true);

            while (unit != null && !unit.dead && unit.thisObj.activeInHierarchy)
            {
                overlay.barHP.value = unit.HP / unit.fullHP;
                Vector3 screenPos = mainCam.WorldToScreenPoint(unit.thisT.position + new Vector3(0, 0, 0));
                overlay.rootT.localPosition = (screenPos + new Vector3(0, 20, 0)) / UI.GetScaleFactor();

                yield return(null);
            }

            overlay.rootObj.SetActive(false);
            overlayedUnitList.Remove(unit);
        }
Ejemplo n.º 4
0
        void OnTextOverlay(TextOverlay overlayInstance)
        {
            if (UI.DisableTextOverlay())
            {
                return;
            }

            Text txt = GetUnusedTextOverlay();

            txt.text = overlayInstance.msg;
            if (overlayInstance.useColor)
            {
                txt.color = overlayInstance.color;
            }
            else
            {
                txt.color = new Color(1f, 150 / 255f, 0, 1f);
            }

            Vector3 screenPos = mainCam.WorldToScreenPoint(overlayInstance.pos);

            txt.transform.localPosition = screenPos / UI.GetScaleFactor();

            txt.gameObject.SetActive(true);

            StartCoroutine(TextOverlayRoutine(txt));
        }
Ejemplo n.º 5
0
        void UpdateScreenPos()
        {
            Vector3 screenPos = Camera.main.WorldToScreenPoint(unit.GetPos() + new Vector3(0, .5f, 0));

            screenPos.z         = 0;
            rectT.localPosition = screenPos * UI.GetScaleFactor();
        }
Ejemplo n.º 6
0
        void Update()
        {
            if (TowerManager.InDragNDropPhase())
            {
                if (TowerManager.GetDragNDropTower() != null)
                {
                    Vector3 towerPos  = TowerManager.GetDragNDropTower().GetPos();
                    Vector3 screenPos = Camera.main.WorldToScreenPoint(towerPos) * UI.GetScaleFactor();
                    screenPos.z  = 0;
                    screenPos.y += 50;
                    dndLabelRectT.localPosition = screenPos;

                    if (TowerManager.DnDHasValidPos())
                    {
                        dndLabel.text = "";
                    }
                    else
                    {
                        dndLabel.gameObject.SetActive(true);
                        dndLabel.text = "Invalid Pos";
                    }
                }
                else
                {
                    dndLabel.text = "";
                }
            }
            else
            {
                if (dndLabel.gameObject.activeInHierarchy)
                {
                    dndLabel.gameObject.SetActive(false);
                }
            }
        }
Ejemplo n.º 7
0
        public void UpdateScreenPosition()
        {
            Vector3 screenPos = Camera.main.WorldToScreenPoint(tower.GetPos());          //+new Vector3(0, 0, 0));

            screenPos.z         = 0;
            rectT.localPosition = (screenPos + new Vector3(0, -20, 0)) * UI.GetScaleFactor();
        }
Ejemplo n.º 8
0
        public static List <Vector3> GetPieMenuPos(float num, Vector3 screenPos, float cutoff, int size)
        {
            List <Vector3> points = new List <Vector3>();

            if (num == 1)
            {
                points.Add(screenPos + new Vector3(0, 50, 0));
                return(points);
            }

            //if there's only two button to be displayed, then normal calculation doesnt apply
            if (num <= 2)
            {
                points.Add(screenPos + new Vector3(50, 10, 0));
                points.Add(screenPos + new Vector3(-50, 10, 0));
                return(points);
            }

            //create a dummy transform which we will use to do the calculation
            if (piePosDummyT == null)
            {
                piePosDummyT = new GameObject().transform;
            }

            int cutoffOffset = cutoff > 0 ? 1:0;

            //calculate the spacing of angle and distance of button from center
            float spacing = (float)((360f - cutoff) / (num - cutoffOffset));
            //float dist=Mathf.Max((num+1)*10, 50);
            float dist = 0.35f * num * size * UI.GetScaleFactor();

            piePosDummyT.rotation = Quaternion.Euler(0, 0, cutoff / 2);
            piePosDummyT.position = screenPos;          //Vector3.zero;

            //rotate the dummy transform using the spacing interval, then sample the end point
            //these end point will be our button position
            for (int i = 0; i < num; i++)
            {
                Vector3 pos = piePosDummyT.TransformPoint(new Vector3(0, -dist, 0));
                points.Add(pos / UI.GetScaleFactor());
                piePosDummyT.Rotate(Vector3.forward * spacing);
            }

            //clear the dummy object
            //Destroy(piePosDummyT.gameObject);

            return(points);
        }
Ejemplo n.º 9
0
        IEnumerator _Building(UnitTower tower)
        {
            Slider    bar  = GetUnusedBuildingBar();
            Transform barT = bar.transform;

            while (tower != null && tower.IsInConstruction())
            {
                bar.value = tower.GetBuildProgress();

                if (mainCam == null)
                {
                    mainCam = Camera.main;
                    continue;
                }

                Vector3 screenPos = mainCam.WorldToScreenPoint(tower.thisT.position + new Vector3(0, 0, 0));
                barT.localPosition = (screenPos + new Vector3(0, -20, 0)) / UI.GetScaleFactor();
                bar.gameObject.SetActive(true);

                yield return(null);
            }
            bar.gameObject.SetActive(false);
        }
Ejemplo n.º 10
0
        void Update()
        {
            if (UIControl.UseDragNDropMode() || !UIControl.UsePieMenuForBuild())
            {
                return;
            }

            if (buttonLayoutGroup.enabled == UIControl.UsePieMenuForBuild())
            {
                buttonLayoutGroup.enabled = !UIControl.UsePieMenuForBuild();
            }

            if (sInfo == null)
            {
                return;
            }

            Vector3        screenPos = Camera.main.WorldToScreenPoint(sInfo.GetPos()) * UI.GetScaleFactor();
            List <Vector3> posList   = GetPieMenuPos(sInfo.buildableList.Count, screenPos);

            for (int i = 0; i < posList.Count; i++)
            {
                buildButtons[i].rectT.localPosition = posList[i];
            }
        }