Пример #1
0
        public Vector3 GetScreenPos(Vector3 worldPos)
        {
            Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPos) * UIMainControl.GetScaleFactor();

            screenPos.z = 0;
            return(screenPos);
        }
Пример #2
0
        // Update is called once per frame
        void LateUpdate()
        {
            if (unit == null)
            {
                if (thisObj.activeInHierarchy)
                {
                    thisObj.SetActive(false);
                }
                return;
            }


            if (unit.IsDestroyed() || (unit.HP >= unit.GetFullHP() && unit.shield >= unit.GetFullShield()))
            {
                UIUnitOverlayManager.RemoveUnit(unit);
                unit = null;
                thisObj.SetActive(false);
                return;
            }


            if (!thisObj.activeInHierarchy)
            {
                return;
            }

            Vector3 screenPos = Camera.main.WorldToScreenPoint(unit.thisT.position + new Vector3(0, 1, 0));

            screenPos.z         = 0;
            rectT.localPosition = screenPos * UIMainControl.GetScaleFactor();

            sliderHP.value     = (unit.HP / unit.GetFullHP());
            sliderShield.value = (unit.shield / unit.GetFullShield());
        }
Пример #3
0
        public List <Vector3> GetPieMenuPos(float num, Vector3 screenPos, float cutoff, int size)
        {
            List <Vector3> points = new List <Vector3>();

            if (num == 1)
            {
                points.Add(screenPos * UIMainControl.GetScaleFactor() + 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 * UIMainControl.GetScaleFactor() + new Vector3(50, 10, 0));
                points.Add(screenPos * UIMainControl.GetScaleFactor() + 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;
                piePosDummyT.parent = transform;
                piePosDummyT.name   = "PiePosDummy";
            }

            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;      //UIMainControl.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++)
            {
                points.Add(piePosDummyT.TransformPoint(new Vector3(0, -dist, 0)));
                piePosDummyT.Rotate(Vector3.forward * spacing);
            }

            return(points);
        }
Пример #4
0
        public IEnumerator BuildingBarRoutine(UnitTower tower)
        {
            Slider    bar  = buildingBarList[GetUnusedBuildingBarIndex()];
            Transform barT = bar.transform;

            bar.gameObject.SetActive(true);

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

                Vector3 screenPos = Camera.main.WorldToScreenPoint(tower.thisT.position + new Vector3(0, 0, 0));
                barT.localPosition = (screenPos + new Vector3(0, -20, 0)) * UIMainControl.GetScaleFactor();

                yield return(null);
            }

            bar.gameObject.SetActive(false);
        }
Пример #5
0
        void Update()
        {
            if (BuildManager.UseDragNDrop() || !UIMainControl.UsePieMenu())
            {
                return;
            }

            if (buildInfo == null)
            {
                return;
            }

            Vector3        screenPos = Camera.main.WorldToScreenPoint(buildInfo.position) * UIMainControl.GetScaleFactor();
            List <Vector3> pos       = GetPieMenuPos(activeButtonList.Count, screenPos, 120, 50);

            for (int i = 0; i < activeButtonList.Count; i++)
            {
                if (i < pos.Count)
                {
                    activeButtonList[i].rectT.localPosition = pos[i];
                }
                else
                {
                    activeButtonList[i].rectT.localPosition = new Vector3(0, 9999, 0);
                }
            }
        }