当前位置: 首页>>代码示例>>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;未经允许,请勿转载。