Ejemplo n.º 1
0
    //スコアを表示するUIテキストのサイズを画面に合わせて変更する
    void InitTextUISize()
    {
        if (mText != null)
        {
            int screenWidth  = Screen.width;
            int screenHeight = Screen.height;

            Canvas tmpCanvas = mText.GetComponentInParent <Canvas>() as Canvas;
            if (tmpCanvas != null)
            {
                RectTransform canvasRect = tmpCanvas.GetComponent <RectTransform>() as RectTransform;
                if (canvasRect != null)
                {
                    canvasRect.sizeDelta = new Vector2(screenWidth, screenHeight);
                }
            }

            screenHeight /= 5;                                          //mTextのクライアント領域の高さをスクリーンの1/5とする
            screenWidth  /= 2;                                          //mTextのクライアント領域の幅をスクリーンの1/2とする

            RectTransform rt = mText.rectTransform;                     //
            rt.sizeDelta = new Vector2(screenWidth, screenHeight);      //

            mText.resizeTextForBestFit = true;                          //フォントサイズをmTextのクライアント領域に自動フィットにする
        }
    }
Ejemplo n.º 2
0
    public void ShowTargetInfo(bool showInfo)
    {
        // Don't open the target info if upload menu is open.
        // if (CloudUploading.Instance.uploadMenu.activeSelf){
        //     return;
        // }

        Canvas canvas = cloudTargetInfo.GetComponentInParent <Canvas>();

        canvas.enabled = showInfo;
    }
Ejemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyUp(KeyCode.E))
     {
         editMode = !editMode;
         if (editMode)
         {
             modoActual.text = "Modo Editar";
         }
         else
         {
             modoActual.text = "Modo Mover";
         }
     }
     if (Input.GetKeyUp(KeyCode.H))
     {
         instrucciones.SetActive(!instrucciones.gameObject.active);
     }
     if (Input.GetKeyUp(KeyCode.R))
     {
         camara.ResetTarget();
         Informacion.text  = "NULL";
         Informacion.color = Color.white;
         Informacion.GetComponentInParent <UnityEngine.UI.Image>().color = Color.black;
         unidadActual     = null;
         diagnostico.text = "";
     }
     if (Input.GetKeyUp(KeyCode.Q))
     {
         reiniciaMapa();
     }
     if (Input.GetKey(KeyCode.Escape))
     {
         Application.Quit();
     }
 }
    public void ShowTargetInfo(bool showInfo)
    {
        Canvas canvas = cloudTargetInfo.GetComponentInParent <Canvas>();

        canvas.enabled = showInfo;
    }
Ejemplo n.º 5
0
        private static int GetBestFitSize(UnityEngine.UI.Text text, List <string> newStrings)
        {
            var smallestFontSize = 0;
            var currentText      = text.text;

            if (newStrings == null)
            {
                newStrings = new List <string> {
                    currentText
                };
            }
            if (!newStrings.Contains(currentText))
            {
                newStrings.Add(currentText);
            }
            var bestFitBehaviour = text.GetComponentInParent <BestFit>();

            foreach (var s in newStrings)
            {
                text.text = s;
                text.resizeTextForBestFit = true;
                text.resizeTextMinSize    = bestFitBehaviour ? bestFitBehaviour.MinFontSize : 1;
                text.resizeTextMaxSize    = (bestFitBehaviour ? bestFitBehaviour.MaxFontSize : 300) + 1;
                text.fontSize             = text.resizeTextMaxSize;
                text.cachedTextGenerator.Invalidate();
                text.cachedTextGenerator.Populate(text.text, text.GetGenerationSettings(text.rectTransform.rect.size));
                text.resizeTextForBestFit = false;
                var newSize        = text.cachedTextGenerator.fontSizeUsedForBestFit;
                var newSizeRescale = text.rectTransform.rect.size.x / text.cachedTextGenerator.rectExtents.size.x;
                if (text.rectTransform.rect.size.y / text.cachedTextGenerator.rectExtents.size.y < newSizeRescale)
                {
                    newSizeRescale = text.rectTransform.rect.size.y / text.cachedTextGenerator.rectExtents.size.y;
                }
                //log logic copied from https://bitbucket.org/Unity-Technologies/ui/src/a3f89d5f7d145e4b6fa11cf9f2de768fea2c500f/UnityEngine.UI/UI/Core/Layout/CanvasScaler.cs?at=2017.3&fileviewer=file-view-default
                //allows calculation to be accurate from the first frame
                var canvasScaler = text.GetComponentInParent <CanvasScaler>();
                while (canvasScaler != null && canvasScaler.transform.parent != null && canvasScaler.transform.parent.GetComponentInParent <CanvasScaler>())
                {
                    canvasScaler = canvasScaler.transform.parent.GetComponentInParent <CanvasScaler>();
                }
                var canvas = text.GetComponentInParent <Canvas>();
                while (canvas != null && canvas.transform.parent != null && canvas.transform.parent.GetComponentInParent <Canvas>())
                {
                    canvas = canvas.transform.parent.GetComponentInParent <Canvas>();
                }
                if (canvas && canvasScaler)
                {
                    var logWidth           = Mathf.Log(Screen.width / canvasScaler.referenceResolution.x, 2);
                    var logHeight          = Mathf.Log(Screen.height / canvasScaler.referenceResolution.y, 2);
                    var logWeightedAverage = Mathf.Lerp(logWidth, logHeight, canvasScaler.matchWidthOrHeight);
                    var logScaleFactor     = Mathf.Pow(2, logWeightedAverage);
                    if (canvas.renderMode == RenderMode.ScreenSpaceCamera && canvas.worldCamera)
                    {
                        logScaleFactor *= canvas.worldCamera.orthographicSize / (Screen.height * 0.5f);
                    }
                    if (canvas.renderMode == RenderMode.ScreenSpaceOverlay || (canvas.renderMode == RenderMode.ScreenSpaceCamera && !canvas.worldCamera) || (canvas.renderMode == RenderMode.ScreenSpaceCamera && canvas.worldCamera && canvas.worldCamera.orthographic))
                    {
                        newSizeRescale *= canvas.transform.localScale.x / logScaleFactor;
                    }
                }
                newSize = Mathf.FloorToInt(newSize * newSizeRescale);
                if (newSize < smallestFontSize || smallestFontSize == 0)
                {
                    smallestFontSize = newSize;
                }
            }
            text.text = currentText;
            return(Mathf.Min(smallestFontSize, bestFitBehaviour ? bestFitBehaviour.MaxFontSize : 300));
        }
Ejemplo n.º 6
0
 public void setCurrentUnit(GameObject unidad)
 {
     unidadActual      = unidad;
     Informacion.color = unidadActual.GetComponent <SpriteRenderer>().color;
     Informacion.GetComponentInParent <UnityEngine.UI.Image>().color = new Color(1.0f - Informacion.color.r, 1.0f - Informacion.color.g, 1.0f - Informacion.color.b);
 }