SetSizeWithCurrentAnchors() public méthode

public SetSizeWithCurrentAnchors ( Axis axis, float size ) : void
axis Axis
size float
Résultat void
Exemple #1
2
    public static void DrawLine(Vector3 pos0, Vector3 pos1, RectTransform rectTrans, float thickness)
    {
        // drawLine
        float dist = Vector3.Distance(pos0, pos1);

        rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, dist);
        rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, thickness);

        rectTrans.pivot = new Vector2(0, 0.5f); // update pivot

        Vector3 dir = pos1 - pos0;
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        rectTrans.eulerAngles = new Vector3(0,0, angle);

        rectTrans.anchoredPosition = pos0;
    }
Exemple #2
1
    private void ScaleSizeGivenExpectedWidth(RectTransform rect, int width)
    {
        float originalWidth = originalPanelSize.x;
        float originalHeight = originalPanelSize.y;
        float scaleBy = width / originalWidth;

        Text[] allText = rect.GetComponentsInChildren<Text>(true);
        foreach(Text text in allText)
        {
            //Debug.Log ("Original font size: " + text.fontSize + " Font size: " + (int)(originalFontSize * scaleBy));
            text.fontSize = (int)(originalFontSize * scaleBy);
        }

        //Debug.Log ("Original width: " + originalWidth + " width: " + width);
        //Debug.Log ("Original height: " + originalHeight + " height: " + (int)(originalHeight*scaleBy));
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (int)(originalHeight*scaleBy)+2);
    }
Exemple #3
0
 static public int SetSizeWithCurrentAnchors(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.RectTransform      self = (UnityEngine.RectTransform)checkSelf(l);
         UnityEngine.RectTransform.Axis a1;
         a1 = (UnityEngine.RectTransform.Axis)LuaDLL.luaL_checkinteger(l, 2);
         System.Single a2;
         checkType(l, 3, out a2);
         self.SetSizeWithCurrentAnchors(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemple #4
0
    private void StartBarInventory()
    {
        rect = GetComponent<RectTransform>();

        var rectHight = rows*(slotSize + slotPaddingTop)+(10*slotPaddingTop)+40;
        var rectWidth = (slots/rows)*(slotSize+slotPaddingLeft)+(10 * slotPaddingLeft);

        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectWidth);
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectHight);

        inventory = new List<GameObject>();

        int colums = slots / rows;
        for (int i = 0; i < rows; i++)
        {
            for(int k = 0; k < colums; k++)
            {
                GameObject newSlot = (GameObject)Instantiate(slotPrefab);

                RectTransform slotRect = newSlot.GetComponent<RectTransform>();

                newSlot.name = "Slot";

                newSlot.transform.SetParent(this.transform);

                float x =  (2*slotPaddingLeft) * (k + 1) + (slotSize * k)+ 2*slotPaddingLeft;
                float y = -slotPaddingTop * (i + 1) - (slotSize * i) - slotPaddingTop - 50;

                slotRect.localPosition =  new Vector3(x, y);

                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize);
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize);

                slotRect.localScale = new Vector3(1, 1);

                inventory.Add(newSlot);
            }
        }

        //text.text = "Bar Inventar";
        rect.localScale = new Vector3(2, 2);

        StartCoroutine(fader.FadeToBlack());
    }
 void AjustarPropsUI(RectTransform rectTransformProp, int i)
 {
     rectTransformProp.gameObject.SetActive(true);
     rectTransformProp.transform.parent = ListaDePropriedades.transform;
     //redimensionar
     rectTransformProp.SetSizeWithCurrentAnchors( RectTransform.Axis.Horizontal,rectTransform.rect.width*(90f/100f) );
     //posicionar
     float altura = rectTransformProp.rect.height;
     float offset = rectTransform.rect.height / 2 - altura / 2;
     rectTransformProp.localPosition = new Vector2(0, offset - altura * i);
     //rectTransformProp.anchoredPosition = new Vector2(0, offset - altura * i);
     UtilidadesUI.AjustarAnchors(rectTransformProp.gameObject);
    
 }
 static public int SetSizeWithCurrentAnchors(IntPtr l)
 {
     try {
         UnityEngine.RectTransform      self = (UnityEngine.RectTransform)checkSelf(l);
         UnityEngine.RectTransform.Axis a1;
         checkEnum(l, 2, out a1);
         System.Single a2;
         checkType(l, 3, out a2);
         self.SetSizeWithCurrentAnchors(a1, a2);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        /// <summary>
        /// Open animation.
        /// </summary>
        /// <returns>Animation.</returns>
        /// <param name="rect">Rect.</param>
        /// <param name="time">Time.</param>
        public static IEnumerator Open(RectTransform rect, float time=0.5f)
        {
            if (rect!=null)
            {
                var layout = rect.GetComponentInParent<EasyLayout.EasyLayout>();
                var max_height = rect.rect.height;

                var end_time = Time.time + time;

                while (Time.time <= end_time)
                {
                    var height = Mathf.Lerp(0, max_height, 1 - (end_time - Time.time) / time);
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
                    if (layout!=null)
                    {
                        layout.NeedUpdateLayout();
                    }
                    yield return null;
                }

                //return height back for future use
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, max_height);
            }
        }
 static int QPYX_SetSizeWithCurrentAnchors_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 3);
         UnityEngine.RectTransform      QPYX_obj_YXQP  = (UnityEngine.RectTransform)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.RectTransform));
         UnityEngine.RectTransform.Axis QPYX_arg0_YXQP = (UnityEngine.RectTransform.Axis)ToLua.CheckObject(L_YXQP, 2, typeof(UnityEngine.RectTransform.Axis));
         float QPYX_arg1_YXQP = (float)LuaDLL.luaL_checknumber(L_YXQP, 3);
         QPYX_obj_YXQP.SetSizeWithCurrentAnchors(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Exemple #9
0
 static int SetSizeWithCurrentAnchors(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.RectTransform      obj  = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
         UnityEngine.RectTransform.Axis arg0 = (UnityEngine.RectTransform.Axis)ToLua.CheckObject(L, 2, typeof(UnityEngine.RectTransform.Axis));
         float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
         obj.SetSizeWithCurrentAnchors(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
		/// <summary>
		/// Collapse animation.
		/// </summary>
		/// <returns>Animation.</returns>
		/// <param name="rect">Rect.</param>
		/// <param name="time">Time.</param>
		static public IEnumerator Collapse(RectTransform rect, float time=0.5f)
		{
			if (rect!=null)
			{
				var max_height = rect.rect.height;

				var end_time = Time.time + time;
				
				while (Time.time <= end_time)
				{
					var height = Mathf.Lerp(max_height, 0, 1 - (end_time - Time.time) / time);
					rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);

					yield return null;
				}
				
				//return height back for future use
				rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, max_height);
			}
		}
Exemple #11
0
    private void createLayout()
    {
        slots = new List<GameObject>();
        hoverOffset = slotSize * 0.01f;
        EmptySlots = slotNum;
        inventoryWidth = (slotNum / rowNum) * (slotSize + slotPadding) + slotPadding;
        inventoryHeight = rowNum * (slotSize + slotPadding) + slotPadding;
        inventoryTransform = GetComponent<RectTransform>();
        inventoryTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inventoryWidth);
        inventoryTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, inventoryHeight);

        int cols = slotNum / rowNum;

        for(int y = 0; y < rowNum; y++)
        {
            for(int x = 0; x < cols; x++)
            {
                GameObject newSlot = (GameObject) Instantiate(slotPrefab);
                RectTransform slotTransform = newSlot.GetComponent<RectTransform>();
                newSlot.name = "Slot";
                newSlot.transform.SetParent(this.transform.parent);

                float xPosition = slotPadding * (x + 1) + (slotSize * x);
                float yPostion = -slotPadding * (y + 1) - (slotSize * y);

                slotTransform.localPosition = inventoryTransform.localPosition + new Vector3(xPosition, yPostion);
                slotTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize);
                slotTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize);

                newSlot.transform.SetParent(this.transform);

                slots.Add(newSlot);
            }
        }
    }
Exemple #12
0
    /// <summary>
    /// �I�u�W�F�N�g��������я��������\�b�h
    /// </summary>
    public void InitControl()
    {
        var cbi = transform.Find("Button/ComboButton/Image");
        var cbt = transform.Find("Button/ComboButton/Text");
        var cba = transform.Find("Button/Arrow");
        if (cbi == null || cbt == null || cba == null)
        {
            foreach (Transform child in transform)
                Destroy(child);
            CreateControl();
        }

        comboButtonRectTransform.GetComponent<Button>().onClick.AddListener(() => { ToggleComboBox(false); });
        var dropdownHeight = comboButtonRectTransform.sizeDelta.y *  Mathf.Min(ItemsToDisplay, ClassList.Length - (HideFirstItem ? 1 : 0));

        // �{�^����}�X�N���邽�߂̃I�[�o�[���CComboBox�I�u�W�F�N�g�𐶐�
        overlayGO = new GameObject("Overlay");
        overlayGO.SetActive(false);

        // �I�[�o�[���CComboBox��Image�R���|��lj�
        var overlayImage = overlayGO.AddComponent<Image>();

        // �J���[��ݒ�
        overlayImage.color = new Color32(0, 0, 0, 0);

        // Canvas�R���|��Q�g�R���ł���܂Őe�I�u�W�F�N�g����[�v
        var canvasTransform = transform;
        while (canvasTransform.GetComponent<Canvas>() == null)
        {
            canvasTransform = canvasTransform.parent;
        }
        // �I�[�o�[���CComboBox�I�u�W�F�N�g��Canvas�R���|����ƒI�u�W�F�N�g�̎q�ɂ���
        overlayGO.transform.SetParent(canvasTransform, false);

        // �I�[�o�[���CComboBox��RectTransform�R���|��lj�
        var overlayRectTransform = overlayGO.GetComponent<RectTransform>();

        // �I�[�o�[���CComboBox��Rect�n�̐ݒ�
        overlayRectTransform.anchorMin = Vector2.zero;
        overlayRectTransform.anchorMax = Vector2.one;
        overlayRectTransform.offsetMin = Vector2.zero;
        overlayRectTransform.offsetMax = Vector2.zero;
        overlayGO.transform.SetParent(transform, false);

        // �I�[�o�[���CComboBox��Button�R���|��lj����ăA���t�@�l0�̓���Image��ݒ�
        var overlayButton = overlayGO.AddComponent<Button>();
        overlayButton.targetGraphic = overlayImage;

        // �Ȃ񂩂�lj����Ă���ۂ�
        overlayButton.onClick.AddListener(() => { ToggleComboBox(false); });

        // �I�[�o�[���CComboBox�I�u�W�F�N�g�Ɏ�������X�N���[���o�[�𐶐�
        var scrollPanelGO = new GameObject("ScrollPanel");

        // �X�N���[���o�[��Image�R���|��lj����摜����щ摜�^�C�v�iSliced�j��ݒ�
        var scrollPanelImage = scrollPanelGO.AddComponent<Image>();
        scrollPanelImage.sprite = Sprite_UISprite;
        scrollPanelImage.type = Image.Type.Sliced;

        // �X�N���[���o�[��I�[�o�[���CComboBox�I�u�W�F�N�g�̎q�ɐݒ�
        scrollPanelGO.transform.SetParent(overlayGO.transform, false);

        // �X�N���[���o�[��Rect�n�̐ݒ�
        scrollPanelRectTransfrom.pivot = new Vector2(0.5f, 1.0f);
        scrollPanelRectTransfrom.anchorMin = Vector2.zero;
        scrollPanelRectTransfrom.anchorMax = Vector2.one;

        scrollPanelGO.transform.SetParent(transform, false);
        scrollPanelRectTransfrom.anchoredPosition = new Vector2(0.0f, -comboButtonRectTransform.sizeDelta.y);
        scrollPanelGO.transform.SetParent(overlayGO.transform, false);

        scrollPanelRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, comboButtonRectTransform.sizeDelta.x);
        scrollPanelRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);

        var scrollPanelScrollRect = scrollPanelGO.AddComponent<ScrollRect>();
        scrollPanelScrollRect.horizontal = false;
        scrollPanelScrollRect.elasticity = 0.0f;
        scrollPanelScrollRect.movementType = ScrollRect.MovementType.Clamped;
        scrollPanelScrollRect.inertia = false;
        scrollPanelScrollRect.scrollSensitivity = comboButtonRectTransform.sizeDelta.y;
        scrollPanelGO.AddComponent<Mask>();

        // �X�N���[���o�[�̉��������H
        var scrollbarWidth = ClassList.Length - (HideFirstItem ? 1 : 0) > _itemsToDisplay ? _scrollbarWidth : 0.0f;

        // Items�I�u�W�F�N�g�i�S�ẴR���{�{�^���̐e�I�u�W�F�N�g�j�𐶐�
        var itemsGO = new GameObject("Items");
        itemsGO.transform.SetParent(scrollPanelGO.transform, false);
        itemsRectTransfrom = itemsGO.AddComponent<RectTransform>();
        itemsRectTransfrom.pivot = Vector2.up;
        itemsRectTransfrom.anchorMin = Vector2.up;
        itemsRectTransfrom.anchorMax = Vector2.one;
        itemsRectTransfrom.anchoredPosition = Vector2.right;
        itemsRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollPanelRectTransfrom.sizeDelta.x - scrollbarWidth);
        var itemsContentSizeFitter = itemsGO.AddComponent<ContentSizeFitter>();
        itemsContentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
        itemsContentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        var itemsGridLayoutGroup = itemsGO.AddComponent<GridLayoutGroup>();
        itemsGridLayoutGroup.cellSize = new Vector2(comboButtonRectTransform.sizeDelta.x - scrollbarWidth, comboButtonRectTransform.sizeDelta.y);
        itemsGridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
        itemsGridLayoutGroup.constraintCount = 1;
        scrollPanelScrollRect.content = itemsRectTransfrom;

        // Scrollbar�I�u�W�F�N�g�𐶐�
        var scrollbarGO = new GameObject("Scrollbar");
        scrollbarGO.transform.SetParent(scrollPanelGO.transform, false);
        var scrollbarImage = scrollbarGO.AddComponent<Image>();
        scrollbarImage.sprite = Sprite_Background;
        scrollbarImage.type = Image.Type.Sliced;
        var scrollbarScrollbar = scrollbarGO.AddComponent<Scrollbar>();
        var scrollbarColors = new ColorBlock();
        scrollbarColors.normalColor = new Color32(128, 128, 128, 128);
        scrollbarColors.highlightedColor = new Color32(128, 128, 128, 178);
        scrollbarColors.pressedColor = new Color32(88, 88, 88, 178);
        scrollbarColors.disabledColor = new Color32(64, 64, 64, 128);
        scrollbarColors.colorMultiplier = 2.0f;
        scrollbarColors.fadeDuration = 0.1f;
        scrollbarScrollbar.colors = scrollbarColors;
        scrollPanelScrollRect.verticalScrollbar = scrollbarScrollbar;
        scrollbarScrollbar.direction = Scrollbar.Direction.BottomToTop;
        scrollbarRectTransfrom.pivot = Vector2.one;
        scrollbarRectTransfrom.anchorMin = Vector2.one;
        scrollbarRectTransfrom.anchorMax = Vector2.one;
        scrollbarRectTransfrom.anchoredPosition = Vector2.zero;
        scrollbarRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
        scrollbarRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);

        var slidingAreaGO = new GameObject("SlidingArea");
        slidingAreaGO.transform.SetParent(scrollbarGO.transform, false);
        slidingAreaRectTransform = slidingAreaGO.AddComponent<RectTransform>();
        slidingAreaRectTransform.anchoredPosition = Vector2.zero;
        slidingAreaRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
        slidingAreaRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - scrollbarRectTransfrom.sizeDelta.x);

        var handleGO = new GameObject("Handle");
        handleGO.transform.SetParent(slidingAreaGO.transform, false);
        var handleImage = handleGO.AddComponent<Image>();
        handleImage.sprite = Sprite_UISprite;
        handleImage.type = Image.Type.Sliced;
        handleImage.color = new Color32(255, 255, 255, 150);
        scrollbarScrollbar.targetGraphic = handleImage;
        scrollbarScrollbar.handleRect = handleRectTransfrom;
        handleRectTransfrom.pivot = new Vector2(0.5f, 0.5f);
        handleRectTransfrom.anchorMin = new Vector2(0.5f, 0.5f);
        handleRectTransfrom.anchorMax = new Vector2(0.5f, 0.5f);
        handleRectTransfrom.anchoredPosition = Vector2.zero;
        handleRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
        handleRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollbarWidth);

        IsComboBoxEnable = IsComboBoxEnable;

        if (ClassList.Length < 1)
            return;
        Refresh();
    }
    public void SetSlots(int numberOfSlots)
    {
        if (numberOfSlots < 0)
            numberOfSlots = 0;

        int newSlots = numberOfSlots - slots;
        int oldSlots = slots;

        int rows = (int)Mathf.Ceil((float)numberOfSlots / columns);

        inventoryWidth = columns * (slotSize + slotPaddingLeft) + slotPaddingLeft;
        inventoryHeight = rows * (slotSize + slotPaddingTop) + slotPaddingTop;

        if (newSlots > 0) {
            for (int i = oldSlots; i < numberOfSlots; i++) {
                GameObject newSlot = Instantiate(PanelManager.Instance.slotPrefab) as GameObject;
                newSlot.transform.SetParent(m_slotContainer.transform, false);
                newSlot.name = "Slot[" + (i / 4) + "][" + (i % 4) + "]";

                RectTransform slotRect = newSlot.GetComponent<RectTransform>();
                slotRect.localPosition = new Vector3(slotPaddingLeft * ((i % 4) + 1) + (slotSize * (i % 4)), - slotPaddingTop * ((i / 4) + 1) - (slotSize * (i / 4)));
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize);
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize);

                allSlots.Add(newSlot);
                emptySlots++;
            }
        } else if (newSlots < 0) {
            RemoveSlots(-newSlots);
        }

        slots = numberOfSlots;
        inventoryRect = m_slotContainer.GetComponent<RectTransform>();
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inventoryWidth);
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, inventoryHeight);
        RepositionSlots();
    }
Exemple #14
0
 IEnumerator CoStretch(RectTransform aRect, float aTime, Vector2 aSize, AnimationCurve aCurve, System.Action aCallback = null)
 {
     float startTime = Time.time;
     Vector2 startSize = aRect.sizeDelta;
     float percentCompleted = 0;
     while (percentCompleted < 1)
     {
         percentCompleted = (Time.time - startTime) / aTime;
         if(aSize.x > -1f)
             aRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Lerp(startSize.x, aSize.x, aCurve.Evaluate(percentCompleted)));
         if (aSize.y > -1f)
             aRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Mathf.Lerp(startSize.y, aSize.y, aCurve.Evaluate(percentCompleted)));
         yield return new WaitForEndOfFrame();
         if (aRect == null)
         {
             DeregisterObject(aRect);
             yield break;
         }
     }
     DeregisterObject(aRect);
     mCallbacks.Add(aCallback);
     yield break;
 }
    private void SetPositionAndSizeOfRectTransform(RectTransform rect, float xpos, float ypos, float width, float height)
    {
        float currentHeight = Mathf.Abs( rect.rect.yMax - rect.rect.yMin );
        float ratio = height / currentHeight;

        rect.anchoredPosition = new Vector2(xpos, ypos);
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);

        Text[] allText = rect.GetComponentsInChildren<Text>(true);
        foreach(Text text in allText)
        {
            text.fontSize = (int)(text.fontSize * ratio)-1	;
        }
    }
Exemple #16
0
 private static void SetRectTransformSize(RectTransform rect, float width, float height)
 {
     rect.offsetMin = Vector2.zero;
     rect.offsetMax = Vector2.zero;
     rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
     rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
 }
    private void CreateLayout()
    {
        if (allSlots != null)
        {
            foreach (GameObject go in allSlots)
            {
                Destroy(go);
            }
        }

        allSlots = new List<GameObject>();

        hoverYOffset = slotSize * 0.01f;

        emptySlots = slots;

        inventoryWidth = (slots / rows) * (slotSize + slotPaddingLeft) + slotPaddingLeft;
        inventoryHeight = rows * (slotSize + slotPaddingTop) + slotPaddingTop;

        inventoryRect = GetComponent<RectTransform>();
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inventoryWidth);
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, inventoryHeight);

        int columns = slots / rows;

        for (int y = 0; y < rows; y++)
        {
            for (int x = 0; x < columns; x++)
            {
                GameObject newSlot = (GameObject)Instantiate(slotPrefab);

                RectTransform slotRect = newSlot.GetComponent<RectTransform>();

                newSlot.name = "Slot";

                newSlot.transform.SetParent(this.transform.parent);

                slotRect.localPosition = inventoryRect.localPosition + new Vector3(slotPaddingLeft * (x + 1) + (slotSize * x), -slotPaddingTop * (y + 1) - (slotSize * y));

                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize * canvas.scaleFactor);
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize * canvas.scaleFactor);
                newSlot.transform.SetParent(this.transform);

                allSlots.Add(newSlot);
            }
        }
    }
Exemple #18
0
 IEnumerator ModificarTamaño(RectTransform panel, float initialHeight, float finalHeight, float velocidad)
 {
     panel.SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, initialHeight);
     float step = 0;
     while (step < 1) {
         panel.SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, Mathf.Lerp (initialHeight, finalHeight, step));
         step += Time.deltaTime * velocidad;
         yield return null;
     }
 }
    void Awake()
    {
        if (m_awake)
            return;
        m_awake	= true;

        var screenSize		= FSNEngine.Instance.ScreenDimension;

        m_canvas			= gameObject.GetComponent<Canvas>() ?? gameObject.AddComponent<Canvas>();	// Canvas 생성, 세팅
        m_canvas.renderMode	= RenderMode.WorldSpace;							// World space에 둔다.

        m_rectTrans			= gameObject.GetComponent<RectTransform>();			// Size, 좌표계 세팅. 가운데를 중점으로 한다.
        m_rectTrans.pivot	= new Vector2(0.5f, 0.5f);
        m_rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, screenSize.x);
        m_rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, screenSize.y);

        if (m_camera)															// 카메라가 지정된 경우만 카메라 세팅
        {

            if ((m_camera.cullingMask | 1 << gameObject.layer) == 0)			// 컬링 마스크 체크 - 이 레이어가 카메라에 표시되지 않는다면 경고
            {
                Debug.LogWarning("[FSNNewUICanvas] This UI canvas cannot shown by the camera - the camera's layer mask doesn't include this object's layer.");
            }

            if (m_camera.orthographic)											// Orthogonal일 시 카메라에 맞춘 스케일 세팅
            {
                m_rectTrans.localScale	= Vector3.one * (m_camera.orthographicSize / (FSNEngine.Instance.ScreenYSize / 2f));
            }
            else
            {																	// Perspective일 시 카메라에 맞춘 스케일 세팅

                var screensize	= FSNEngine.Instance.ScreenDimension;

                // 0. canvas의 점을 camera의 좌표계로 변환
                var toCamera	= m_rectTrans.localToWorldMatrix * m_camera.transform.worldToLocalMatrix;
                var canvasP0	= toCamera.MultiplyPoint(Vector3.zero);
                var canvasP1	= toCamera.MultiplyPoint(Vector3.up * screensize.y);
                var canvasP2	= toCamera.MultiplyPoint(Vector3.right * screensize.x);

                // 1. canvas가 만들어내는 평면과 카메라의 방향 벡터가 만나는 점을 구한다.
                var canvPlane	= new Plane(canvasP0, canvasP1, canvasP2);
                float enter;
                canvPlane.Raycast(new Ray(Vector3.zero, Vector3.forward), out enter);
                var intersectP	= Vector3.forward * enter;

                m_cameraToCanvas	= intersectP.magnitude;			// 카메라 -> 캔버스까지 거리 저장해두기

                // 2. 그 만나는 점을 포함하고 카메라의 방향 벡터와는 수직한 평면(= 카메라와 마주보는)을 가정하고,
                var paralPlane	= new Plane(Vector3.back, intersectP);

                // 3. 이 평면에서의 좌표계가 카메라에 투영될 때의 좌표가 (엔진에서의) 화면 좌표계와 일치하도록 canvas의 스케일을 조절한다.
                var screenRay		= m_camera.ScreenPointToRay(new Vector3(m_camera.pixelWidth / 2, m_camera.pixelHeight));
                screenRay.origin	= m_camera.transform.InverseTransformPoint(screenRay.origin);		// ray를 카메라 로컬 스페이스로 옮겨오기 (world 기준으로 ray가 생성되었으므로)
                screenRay.direction	= m_camera.transform.InverseTransformDirection(screenRay.direction);// 방향도...

                float raydist;
                paralPlane.Raycast(screenRay, out raydist);												// 모든 것이 카메라 로컬 스페이스에 있으므로 안심하고 레이캐스팅

                float distFromScreenSqr	= (screenRay.GetPoint(raydist)).sqrMagnitude;

                float planeHalfHeight	= Mathf.Sqrt(distFromScreenSqr - Mathf.Pow(paralPlane.distance, 2));	// 가상 plane의 높이/2 를 구한다
                float scale				= planeHalfHeight / (screensize.y / 2f);
                m_rectTrans.localScale	= Vector3.one * scale;
            }
        }
    }
Exemple #20
0
    public virtual void CreateLayout(){ // creates inventory layout

		if (allSlots != null) {
			foreach (GameObject go in allSlots) {
				Destroy(go);
			}
		}
		allSlots = new List<GameObject> (); // instantiates the allslot list

		hoverYOffset = slotSize * 0.1f; // icon met 1 % omlaag gaat

		emptySlots = slots; // stores the number of empty slots
         
		inventoryWidth = (slots / rows) * (slotSize + slotPaddingLeft) + slotPaddingLeft; // calculates the width of the inventory

		inventoryHeight = rows * (slotSize + slotPaddingTop) + slotPaddingTop; // calculates the height of the inventory

		inventoryRect = GetComponent<RectTransform> (); // creates a reference to the inventorys recttransform

		inventoryRect.SetSizeWithCurrentAnchors (RectTransform.Axis.Horizontal, inventoryWidth); // sets the width of the inventory
		inventoryRect.SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, inventoryHeight); // sets the height of the inventory

		int columns = slots / rows; // calculates the amount of columns
			 
		for (int y = 0; y < rows; y++) { // runs through the rows
			for (int x = 0; x < columns; x++) { // runs through the colums
				GameObject newSlot = (GameObject)Instantiate(InventoryManager.Instance.slotPrefab); // instantiate a slot and creates a reference to it
					
				RectTransform slotRect = newSlot.GetComponent<RectTransform>(); // makes a reference to the rect transform

				newSlot.name = "Slot "+"x"+x+"y"+y; // set the slot name

				newSlot.transform.SetParent(this.transform); // set the canvas as parent of the slot so that it is visible on the screen

				slotRect.localPosition = new Vector3(slotPaddingLeft * (x+1) + (slotSize * x), -slotPaddingTop * (y+1) - (slotSize * y)); // set the slot position

				slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize * InventoryManager.Instance.canvas.scaleFactor); // set the size of the slot
				slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize * InventoryManager.Instance.canvas.scaleFactor); // set the size of the slot

				allSlots.Add(newSlot); // add the new slot to the slot lost

                newSlot.GetComponent<Button>().onClick.AddListener(
                    delegate { MoveItem(newSlot); }     
                );
			}
		}
	}
Exemple #21
0
    void CreateLayoutDonburi()
    {
        donburi = Instantiate(Resources.Load("Prefabs/Donburi")) as GameObject;
        donburi.transform.SetParent(GameObject.Find("Canvas").transform);
        donburi.transform.localScale = new Vector3(3, 3, 1);
        RectTransform donburiRect = donburi.GetComponent<RectTransform>();
        donburiRect.localPosition = fieldRect.localPosition + new Vector3(0.0f, -150.0f);
        donburiRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, donburiRect.sizeDelta.x);
        donburiRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, donburiRect.sizeDelta.y);

        blackCircle = Instantiate(Resources.Load("Prefabs/BlackCircle")) as GameObject;
        blackCircle.transform.SetParent(GameObject.Find("Canvas").transform);
        blackCircleRect = blackCircle.GetComponent<RectTransform>();
        blackCircleRect.localScale = new Vector3(1, 1, 1);
        blackCircleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, blackCircleRect.sizeDelta.x);
        blackCircleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, blackCircleRect.sizeDelta.y);
        blackCircleRect.transform.position = donburiRect.transform.position;
    }
Exemple #22
0
        private void InitControl()
        {
            var cbi = transform.Find("Button/ComboButton/Image");
            var cbt = transform.Find("Button/ComboButton/Text");
            var cba = transform.Find("Button/Arrow");
            if (cbi == null || cbt == null || cba == null)
            {
                foreach (Transform child in transform)
                    Destroy(child);
                CreateControl();
            }

            comboButtonRectTransform.GetComponent<Button>().onClick.AddListener(() => {
                ToggleComboBox(false); });
            var dropdownHeight = comboButtonRectTransform.sizeDelta.y * Mathf.Min(ItemsToDisplay, Items.Length - (HideFirstItem ? 1 : 0));

            overlayGO = new GameObject("CBOverlay");
            overlayGO.SetActive(false);
            var overlayImage = overlayGO.AddComponent<Image>();
            overlayImage.color = new Color32(0, 0, 0, 0);
            overlayGO.transform.SetParent(canvasTransform, false);
            var overlayRectTransform = overlayGO.GetComponent<RectTransform>();
            overlayRectTransform.anchorMin = Vector2.zero;
            overlayRectTransform.anchorMax = Vector2.one;
            overlayRectTransform.offsetMin = Vector2.zero;
            overlayRectTransform.offsetMax = Vector2.zero;
            var overlayButton = overlayGO.AddComponent<Button>();
            overlayButton.targetGraphic = overlayImage;
            overlayButton.onClick.AddListener(() => {
                ToggleComboBox(false); });

            scrollPanelGO = new GameObject("ScrollPanel");
            var scrollPanelImage = scrollPanelGO.AddComponent<Image>();
            scrollPanelImage.sprite = Sprite_UISprite;
            scrollPanelImage.type = Image.Type.Sliced;
            scrollPanelGO.transform.SetParent(overlayGO.transform, false);
            scrollPanelRectTransfrom.pivot = Vector2.zero;
            scrollPanelRectTransfrom.anchorMin = Vector2.zero;
            scrollPanelRectTransfrom.anchorMax = Vector2.one;
            scrollPanelGO.transform.SetParent(transform, false);
            scrollPanelRectTransfrom.anchoredPosition = new Vector2(0.0f, -rectTransform.sizeDelta.y * _itemsToDisplay);

            scrollPanelRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, comboButtonRectTransform.sizeDelta.x);
            scrollPanelRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
            var scrollPanelScrollRect = scrollPanelGO.AddComponent<ScrollRect>();
            scrollPanelScrollRect.horizontal = false;
            scrollPanelScrollRect.elasticity = 0.0f;
            scrollPanelScrollRect.movementType = ScrollRect.MovementType.Clamped;
            scrollPanelScrollRect.inertia = false;
            scrollPanelScrollRect.scrollSensitivity = comboButtonRectTransform.sizeDelta.y;
            scrollPanelGO.AddComponent<Mask>();

            var scrollbarWidth = Items.Length - (HideFirstItem ? 1 : 0) > _itemsToDisplay ? _scrollbarWidth : 0.0f;

            var itemsGO = new GameObject("Items");
            itemsGO.transform.SetParent(scrollPanelGO.transform, false);
            itemsRectTransfrom = itemsGO.AddComponent<RectTransform>();
            itemsRectTransfrom.pivot = Vector2.up;
            itemsRectTransfrom.anchorMin = Vector2.up;
            itemsRectTransfrom.anchorMax = Vector2.one;
            itemsRectTransfrom.anchoredPosition = Vector2.right;
            itemsRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollPanelRectTransfrom.sizeDelta.x - scrollbarWidth);
            var itemsContentSizeFitter = itemsGO.AddComponent<ContentSizeFitter>();
            itemsContentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            itemsContentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            var itemsGridLayoutGroup = itemsGO.AddComponent<GridLayoutGroup>();
            itemsGridLayoutGroup.cellSize = new Vector2(comboButtonRectTransform.sizeDelta.x - scrollbarWidth, comboButtonRectTransform.sizeDelta.y);
            itemsGridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
            itemsGridLayoutGroup.constraintCount = 1;
            scrollPanelScrollRect.content = itemsRectTransfrom;

            var scrollbarGO = new GameObject("Scrollbar");
            scrollbarGO.transform.SetParent(scrollPanelGO.transform, false);
            var scrollbarImage = scrollbarGO.AddComponent<Image>();
            scrollbarImage.sprite = Sprite_Background;
            scrollbarImage.type = Image.Type.Sliced;
            var scrollbarScrollbar = scrollbarGO.AddComponent<Scrollbar>();
            var scrollbarColors = new ColorBlock();
            scrollbarColors.normalColor = new Color32(128, 128, 128, 128);
            scrollbarColors.highlightedColor = new Color32(128, 128, 128, 178);
            scrollbarColors.pressedColor = new Color32(88, 88, 88, 178);
            scrollbarColors.disabledColor = new Color32(64, 64, 64, 128);
            scrollbarColors.colorMultiplier = 2.0f;
            scrollbarColors.fadeDuration = 0.1f;
            scrollbarScrollbar.colors = scrollbarColors;
            scrollPanelScrollRect.verticalScrollbar = scrollbarScrollbar;
            scrollbarScrollbar.direction = Scrollbar.Direction.BottomToTop;
            scrollbarRectTransfrom.pivot = Vector2.one;
            scrollbarRectTransfrom.anchorMin = Vector2.one;
            scrollbarRectTransfrom.anchorMax = Vector2.one;
            scrollbarRectTransfrom.anchoredPosition = Vector2.zero;
            scrollbarRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
            scrollbarRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);

            var slidingAreaGO = new GameObject("SlidingArea");
            slidingAreaGO.transform.SetParent(scrollbarGO.transform, false);
            slidingAreaRectTransform = slidingAreaGO.AddComponent<RectTransform>();
            slidingAreaRectTransform.anchoredPosition = Vector2.zero;
            slidingAreaRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
            slidingAreaRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - scrollbarRectTransfrom.sizeDelta.x);

            var handleGO = new GameObject("Handle");
            handleGO.transform.SetParent(slidingAreaGO.transform, false);
            var handleImage = handleGO.AddComponent<Image>();
            handleImage.sprite = Sprite_UISprite;
            handleImage.type = Image.Type.Sliced;
            handleImage.color = new Color32(255, 255, 255, 150);
            scrollbarScrollbar.targetGraphic = handleImage;
            scrollbarScrollbar.handleRect = handleRectTransfrom;
            handleRectTransfrom.pivot = new Vector2(0.5f, 0.5f);
            handleRectTransfrom.anchorMin = new Vector2(0.5f, 0.5f);
            handleRectTransfrom.anchorMax = new Vector2(0.5f, 0.5f);
            handleRectTransfrom.anchoredPosition = Vector2.zero;
            handleRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
            handleRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollbarWidth);

            Interactable = Interactable;

            if (Items.Length < 1)
                return;
            Refresh();
        }
Exemple #23
0
    void CreateLayoutTopping()
    {
        allSlots = new List<GameObject>();

        fieldWidth = (numSlots / numRows) * (slotSize + slotPaddingLeft) + slotPaddingLeft;
        fieldHeight = numRows * (slotSize + slotPaddingTop) + slotPaddingTop;

        fieldRect = GetComponent<RectTransform>();
        fieldRect.localScale = new Vector3(1, 1, 1);
        fieldRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, fieldWidth);
        fieldRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, fieldHeight);
        //fieldRect.transform.position = new Vector2(Screen.width / 2, Screen.height / 2);

        int numColumns = numSlots / numRows;

        RectTransform fieldBackgroundRect = fieldBackground.GetComponent<RectTransform>();
        fieldBackgroundRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 498.5f);
        fieldBackgroundRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 286.0f);

        for (int y = 0; y < numRows; y++)
        {
            for (int x = 0; x < numColumns; x++)
            {
                GameObject newSlot = Instantiate(slotPrefab) as GameObject;
                newSlot.name = "Slot";
                newSlot.transform.SetParent(canvas.transform);
                newSlot.transform.localScale = new Vector3(1, 1, 1);
                newSlot.transform.SetParent(slots.transform);

                RectTransform slotRect = newSlot.GetComponent<RectTransform>();
                slotRect.localPosition = fieldRect.localPosition + new Vector3(-fieldWidth / 2, 200.0f) + new Vector3(slotPaddingLeft * (x + 1) + (slotSize * x), -slotPaddingTop * (y + 1) - (slotSize * y));
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize);
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize);

                allSlots.Add(newSlot);
            }
        }
    }
Exemple #24
0
    /// <summary>
    /// Creates the inventory's layout
    /// </summary>
    private void CreateLayout()
    {
        //Instantiates the allSlot's list
        allSlots = new List<GameObject>();

        //Calculates the hoverYOffset by taking 1% of the slot size
        hoverYOffset = slotSize * 0.01f;

        //Stores the number of empty slots
        emptySlots = slots;

        //Calculates the width of the inventory
        inventoryWidth = (slots / rows) * (slotSize + slotPaddingLeft) + slotPaddingLeft;

        //Calculates the highs of the inventory
        inventoryHight = rows * (slotSize + slotPaddingTop) + slotPaddingTop;

        //Creates a reference to the inventory's RectTransform
        inventoryRect = GetComponent<RectTransform>();

        //Sets the with and height of the inventory.
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inventoryWidth);
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, inventoryHight);

        //Calculates the amount of columns
        int columns = slots / rows;

        for (int y = 0; y < rows; y++) //Runs through the rows
        {
            for (int x = 0; x < columns; x++) //Runs through the columns
            {
                //Instantiates the slot and creates a reference to it
                GameObject newSlot = (GameObject)Instantiate(slotPrefab);

                //Makes a reference to the rect transform
                RectTransform slotRect = newSlot.GetComponent<RectTransform>();

                //Sets the slots name
                newSlot.name = "Slot";

                //Sets the canvas as the parent of the slots, so that it will be visible on the screen
                newSlot.transform.SetParent(this.transform.parent);

                //Sets the slots position
                slotRect.localPosition = inventoryRect.localPosition + new Vector3(slotPaddingLeft * (x + 1) + (slotSize * x), -slotPaddingTop * (y + 1) - (slotSize * y));

                //Sets the size of the slot
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize);
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize);

                //Adds the new slots to the slot list
                allSlots.Add(newSlot);

            }
        }
    }
Exemple #25
0
    //Creates the inventory's layout
    public virtual void CreateLayout()
    {
        if (allSlots != null) {

            foreach (GameObject go in allSlots) {

                Destroy(go);
            }
        }

        //Instantiates the allSlot's list
        allSlots = new List<GameObject>();

        //Calculates the hoverYOffset by taking 1% of the slot size
        hoverYOffset = slotSize * 0.1f;

        //Stores the number of empty slots
        emptySlots = slots;

        //Calculates the width of the inventory
        inventoryWidth = (slots / rows) * (slotSize + slotPaddingLeft);

        //Calculates the highs of the inventory
        inventoryHight = rows * (slotSize + slotPaddingTop);

        //Creates a reference to the inventory's RectTransform
        inventoryRect = GetComponent<RectTransform>();

        //Sets the with and height of the inventory.
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inventoryWidth + slotPaddingLeft);
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, inventoryHight + slotPaddingTop);

        //Calculates the amount of columns
        int columns = slots / rows;

        for (int y = 0; y < rows; y++) { //Runs through the rows

            for (int x = 0; x < columns; x++) { //Runs through the columns

                //Instantiates the slot and creates a reference to it
                GameObject newSlot = (GameObject)Instantiate(InventoryManager.Instance.slotPrefab);

                //Makes a reference to the rect transform
                RectTransform slotRect = newSlot.GetComponent<RectTransform>();

                //Sets the slots name
                newSlot.name = "Slot";

                //Sets the canvas as the parent of the slots, so that it will be visible on the screen
                newSlot.transform.SetParent(this.transform.parent);

                //Sets the slots position
                slotRect.localPosition = inventoryRect.localPosition + new Vector3(slotPaddingLeft * (x + 1) + (slotSize * x), -slotPaddingTop * (y + 1) - (slotSize * y));

                //Sets the size of the slot
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotSize * InventoryManager.Instance.canvas.scaleFactor);
                slotRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize * InventoryManager.Instance.canvas.scaleFactor);
                newSlot.transform.SetParent(this.transform);

                //Adds the new slots to the slot list
                allSlots.Add(newSlot);

                newSlot.GetComponent<Button>().onClick.AddListener
                    (
                        delegate{MoveItem(newSlot);  }

                    );
            }
        }
    }
Exemple #26
0
 public void ResetContentSize(RectTransform content,int count,float eleSize)
 {
     for (int i = 0; i < count; i++) {
         content.SetSizeWithCurrentAnchors (RectTransform.Axis.Horizontal,i * eleSize - eleSize / 100 * (i*i*2));
     }
 }
Exemple #27
-1
    private void ScaleSizeGivenExpectedWidth(RectTransform rect, int width)
    {
        float currentWidth = Mathf.Abs( rect.rect.xMax - rect.rect.xMin );
        float currentHeight = Mathf.Abs( rect.rect.yMax - rect.rect.yMin );
        float scaleBy = width / currentWidth;

        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (int)(currentHeight*scaleBy));

        Text[] allText = rect.GetComponentsInChildren<Text>(true);
        foreach(Text text in allText)
        {
            text.fontSize = (int)(text.fontSize * scaleBy);
        }
    }