當前位置: 首頁>>代碼示例>>C#>>正文


C# RectTransform.SetSizeWithCurrentAnchors方法代碼示例

本文整理匯總了C#中UnityEngine.RectTransform.SetSizeWithCurrentAnchors方法的典型用法代碼示例。如果您正苦於以下問題:C# RectTransform.SetSizeWithCurrentAnchors方法的具體用法?C# RectTransform.SetSizeWithCurrentAnchors怎麽用?C# RectTransform.SetSizeWithCurrentAnchors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.RectTransform的用法示例。


在下文中一共展示了RectTransform.SetSizeWithCurrentAnchors方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DrawLine

    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;
    }
開發者ID:inoook,項目名稱:uGUICanvasTools,代碼行數:16,代碼來源:CanvasLine.cs

示例2: ScaleSizeGivenExpectedWidth

    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);
    }
開發者ID:tng2903,項目名稱:game1,代碼行數:18,代碼來源:RenderScore.cs

示例3: StartBarInventory

    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());
    }
開發者ID:LadyRhapsody,項目名稱:MyWorld,代碼行數:44,代碼來源:Inventory.cs

示例4: AjustarPropsUI

 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);
    
 }
開發者ID:wenderRondonia,項目名稱:Node-Editor-Unity,代碼行數:14,代碼來源:PropriedadesUI.cs

示例5: Open

        /// <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);
            }
        }
開發者ID:AresLee,項目名稱:FarmerSimulator,代碼行數:30,代碼來源:Animations.cs

示例6: Collapse

		/// <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);
			}
		}
開發者ID:jaronimoe,項目名稱:cellVIEW_animated,代碼行數:26,代碼來源:Animations.cs

示例7: CreateLayout

    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);
            }
        }
    }
開發者ID:houseofkohina,項目名稱:Project-Weeaboo,代碼行數:47,代碼來源:SAOInventory.cs

示例8: while

 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;
     }
 }
開發者ID:adrianit0,項目名稱:lolRunner-2,代碼行數:10,代碼來源:GameManager.cs

示例9: ResetContentSize

 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));
     }
 }
開發者ID:yoyo2004cn,項目名稱:VWCarFactory,代碼行數:6,代碼來源:UIManager.cs

示例10: createLayout

    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);
            }
        }
    }
開發者ID:B00058026,項目名稱:Project,代碼行數:35,代碼來源:Inventory.cs

示例11: CreateLayoutDonburi

    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;
    }
開發者ID:tsato1,項目名稱:Ramen-Master,代碼行數:18,代碼來源:Controller.cs

示例12: CreateLayout

    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); }     
                );
			}
		}
	}
開發者ID:Fahrettin52,項目名稱:Game-Lab-1.1,代碼行數:47,代碼來源:Inventory.cs

示例13: CoStretch

 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;
 }
開發者ID:James9074,項目名稱:Unity-Juice-UI,代碼行數:23,代碼來源:Juice.cs

示例14: InitControl

    /// <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;
//.........這裏部分代碼省略.........
開發者ID:yagamiiori,項目名稱:Eda,代碼行數:101,代碼來源:bak_ComboBoxClass.cs

示例15: SetPositionAndSizeOfRectTransform

    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	;
        }
    }
開發者ID:tng2903,項目名稱:game1,代碼行數:15,代碼來源:UiPauseMenuController.cs


注:本文中的UnityEngine.RectTransform.SetSizeWithCurrentAnchors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。