Exemplo n.º 1
0
        void Update()
        {
            _points = PointsController.GetPoints();
            if (_pointsObj != null)
            {
                _pointsObj.GetComponent <Text>().text = _points.ToString();
            }

            _lifes = LifesController.GetLifes();

            /*if (_lifesObj != null)
             * {
             *  _lifesObj.GetComponent<UILabel>().text = _lifes.ToString();
             * }*/

            for (int i = 0; i < _listOfLifes.Count(); i++)
            {
                //_listOfLifes[i].transform.localPosition = new Vector3(Screen.width * 2 - (_listOfLifes[i].GetComponent<UI2DSprite>().width * i) - _offSetX * i, (Screen.height * 2 - _listOfLifes[i].GetComponent<UI2DSprite>().height / 2f));
                if (LifesController.GetLifes() > 0)
                {
                    for (int k = LifesController.GetLifes(); k < LifesController.GetInitialLifes(); k++)
                    {
                        _listOfLifes[k].GetComponent <Image>().sprite = Resources.Load <Sprite>(PathConstants.GetGameScenePath() + "lifeIcon_empty");
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static PointsController Instance()
 {
     if (_instance == null)
     {
         lock (_lock)
         {
             if (_instance == null)
             {
                 _instance = new PointsController();
             }
         }
     }
     return(_instance);
 }
Exemplo n.º 3
0
        void Start()
        {
            _hudFont  = Resources.Load <Font>(PathConstants._fontPath + "Ed-Gothic");
            _fontSize = 80;
            Color hudColor  = new Color(13f / 255f, 140f / 255f, 7f / 255f, 255 / 255f);
            Color textColor = new Color(24f / 255f, 174f / 255f, 16f / 255f, 255 / 255f);

            _pointsController = PointsController.Instance();
            _points           = PointsController.GetPoints();
            _lifes            = LifesController.GetLifes();

            _canvas      = new GameObject();
            _canvas.name = "Canvas";
            Canvas           canvasComponent    = _canvas.AddComponent <Canvas>();
            CanvasScaler     scalerComponent    = _canvas.AddComponent <CanvasScaler>();
            GraphicRaycaster raycasterComponent = _canvas.AddComponent <GraphicRaycaster>();

            canvasComponent.renderMode          = RenderMode.ScreenSpaceOverlay;
            scalerComponent.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            scalerComponent.referenceResolution = new Vector2(2048, 1536);
            scalerComponent.matchWidthOrHeight  = .5f;

            _pointsHud = new GameObject();
            _pointsHud.transform.parent = _canvas.transform;
            _pointsHud.name             = "PointsHud";
            _pointsHud.AddComponent <CanvasRenderer>();
            Text textComponent = _pointsHud.AddComponent <Text>();

            textComponent.text     = "PONTOS";
            textComponent.font     = _hudFont;
            textComponent.fontSize = _fontSize;
            textComponent.color    = hudColor;
            textComponent.rectTransform.anchorMin = _anchorMin;
            textComponent.rectTransform.anchorMax = _anchorMax;
            _pointsHud.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, textComponent.preferredWidth);
            _pointsHud.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, textComponent.preferredHeight);
            _pointsHud.GetComponent <RectTransform>().anchoredPosition = new Vector2(540f, -60f);

            _pointsObj = new GameObject();
            _pointsObj.transform.parent = _canvas.transform;
            _pointsObj.AddComponent <CanvasRenderer>();
            Text pointsText = _pointsObj.AddComponent <Text>();

            pointsText.text     = _points.ToString();
            pointsText.font     = _hudFont;
            pointsText.fontSize = _fontSize;
            pointsText.color    = textColor;
            pointsText.rectTransform.anchorMin = _anchorMin;
            pointsText.rectTransform.anchorMax = _anchorMax;
            _pointsObj.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, pointsText.preferredWidth);
            _pointsObj.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, pointsText.preferredHeight);
            _pointsObj.GetComponent <RectTransform>().anchoredPosition = new Vector2(_pointsHud.GetComponent <RectTransform>().anchoredPosition.x + textComponent.preferredWidth, _pointsHud.GetComponent <RectTransform>().anchoredPosition.y);

            _lifeHUD = new GameObject();
            _lifeHUD.transform.parent = _canvas.transform;
            _lifeHUD.AddComponent <CanvasRenderer>();
            Text lifeTextHUD = _lifeHUD.AddComponent <Text>();

            lifeTextHUD.text     = "VIDAS";
            lifeTextHUD.font     = _hudFont;
            lifeTextHUD.fontSize = _fontSize;
            lifeTextHUD.color    = hudColor;
            lifeTextHUD.rectTransform.anchorMin = _anchorMin;
            lifeTextHUD.rectTransform.anchorMax = _anchorMax;
            _lifeHUD.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, lifeTextHUD.preferredWidth);
            _lifeHUD.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, lifeTextHUD.preferredHeight);
            _lifeHUD.GetComponent <RectTransform>().anchoredPosition = new Vector2(1300f, _pointsHud.GetComponent <RectTransform>().anchoredPosition.y);
            //_lifeHUD.GetComponent<RectTransform>().anchoredPosition = new Vector2(_lifeHUD.GetComponent<RectTransform>().anchoredPosition.x + lifeTextHUD.preferredWidth, _lifeHUD.GetComponent<RectTransform>().anchoredPosition.y

            CreateLifeHud();
        }