本文整理汇总了C#中UnityEngine.RectTransform.SetParent方法的典型用法代码示例。如果您正苦于以下问题:C# RectTransform.SetParent方法的具体用法?C# RectTransform.SetParent怎么用?C# RectTransform.SetParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.RectTransform
的用法示例。
在下文中一共展示了RectTransform.SetParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddInlineGraphicsChild
public void AddInlineGraphicsChild()
{
if (m_inlineGraphic != null)
{
//Debug.LogWarning("A child Inline Graphics object already exists.");
return;
}
GameObject inlineGraphicObj = new GameObject("Inline Graphic");
m_inlineGraphic = inlineGraphicObj.AddComponent<InlineGraphic>();
m_inlineGraphicRectTransform = inlineGraphicObj.GetComponent<RectTransform>();
m_inlineGraphicCanvasRenderer = inlineGraphicObj.GetComponent<CanvasRenderer>();
m_inlineGraphicRectTransform.SetParent(transform, false);
m_inlineGraphicRectTransform.localPosition = Vector3.zero;
m_inlineGraphicRectTransform.anchoredPosition3D = Vector3.zero;
m_inlineGraphicRectTransform.sizeDelta = Vector2.zero;
m_inlineGraphicRectTransform.anchorMin = Vector2.zero;
m_inlineGraphicRectTransform.anchorMax = Vector2.one;
m_TextMeshPro = gameObject.GetComponent<TextMeshPro>();
m_TextMeshProUI = gameObject.GetComponent<TextMeshProUGUI>();
}
示例2: Start
// Use this for initialization
void Start()
{
//general setup
menu = GetComponentInParent<Menu>();
options = new List<MenuViewOptionBasic>();
GetComponentsInChildren<MenuViewOptionBasic>(options);
toDraw = true;
if(options == null) options = new List<MenuViewOptionBasic>();
//Setup view
viewObject = new GameObject("MenuViewBasic");
viewObject.transform.SetParent(transform);
canvas = viewObject.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.worldCamera = drawCamera;
canvas.planeDistance = 1f;
viewObject.AddComponent<CanvasScaler>();
viewObject.AddComponent<GraphicRaycaster>();
//Setup textbox
textbox = new GameObject("TextBox");
textPosition = textbox.AddComponent<RectTransform>();
textPosition.SetParent(viewObject.transform);
textPosition.localPosition = new Vector3(position.x,position.y, 0);
textbox.AddComponent<CanvasRenderer>();
text = textbox.AddComponent<Text>();
text.font = textFont;
text.alignment = TextAnchor.MiddleCenter;
text.color = new Color(color.r, color.g, color.b);
if(options.Count > 0) text.text = options[menu.CurOption].optionText;
}
示例3: AddItem
public void AddItem(RectTransform item)
{
item.SetParent(contentsNode, false);
if (this.gameObject.activeInHierarchy)
{
StartCoroutine(SetPosition(item));
}
}
示例4: addChild
public void addChild(RectTransform rt ,RectTransform parent = null)
{
if(parent == null)
{
parent = UIRoot;
}
rt.SetParent(parent);
rt.localPosition = Vector3.zero;
rt.localScale = Vector3.one;
}
示例5: OnBeginDrag
public void OnBeginDrag(PointerEventData eventData)
{
GameObject go = new GameObject();
placeholder = go.AddComponent<RectTransform>();
placeholder.SetParent(parentToReturn);
placeholder.transform.SetSiblingIndex(myTransform.GetSiblingIndex());
placeholder.transform.localScale = new Vector3(10, 10, 0);
myTransform.SetParent(parentDragging);
tooltip.DestroyTooltip();
tooltip.enabled = false;
}
示例6: PlaceUI
public void PlaceUI(RectTransform prefabZone, RectTransform prefabLetter)
{
Assert.Check (prefabZone, "Zone UI prefab is null");
Assert.Check (prefabLetter, "Letter prefab is null");
GameObject gCanvas = GameObject.Find ("CanvasZone");
Assert.Check (gCanvas, "CanvasZone gameObject is not found");
GameObject zoneG = GameObject.Instantiate (prefabZone.gameObject) as GameObject;
Assert.Check (zoneG, "Couldn't instantiate zone UI");
ZoneUI = zoneG.transform as RectTransform;
Assert.Check (ZoneUI, "Zone has no RectTransform");
RectTransform imgT = zoneG.transform.FindChild("Picto") as RectTransform;
Assert.Check (imgT, "Zone has no Picto RectTransform");
this.Picto = imgT.GetComponent<Image>();
Assert.Check(this.Picto, "Picto has no image");
this.Picto.sprite = this.Effect.Picto;
Canvas canvas = gCanvas.GetComponent<Canvas> ();
Assert.Check (canvas, "CanvasZone's 'Canvas' component is not found");
ZoneUI.SetParent(canvas.transform, false);
Vector2 local;
Vector2 screen = RectTransformUtility.WorldToScreenPoint (Camera.main, this.transform.position);
RectTransformUtility.ScreenPointToLocalPointInRectangle (canvas.transform as RectTransform, screen, Camera.main, out local);
ZoneUI.anchoredPosition = local;
for (int i = 0; i < Combinaison.Count; i++)
{
GameObject letterG = GameObject.Instantiate (prefabLetter.gameObject) as GameObject;
Assert.Check (zoneG, "Couldn't instantiate letter");
RectTransform letter = letterG.transform as RectTransform;
Assert.Check (ZoneUI, "Letter has no RectTransform");
letter.SetParent (ZoneUI, false);
Letters.Add (letter);
RectTransform txtT = letter.FindChild ("Text") as RectTransform;
Assert.Check (txtT, "Letter Text child not found or has no RectTransform");
Text txt = txtT.GetComponent<Text> ();
Assert.Check (txtT, "Letter Text child's 'Text' component not found");
txt.text = Combinaison [i].ToString();
}
}
示例7: Start
void Start()
{
healthBarCanvas = GameObject.Find("Health Bar Canvas").transform;
hpSource = this.GetComponent<IHealth>();
_healthBarInstance = GameObject.Instantiate(healthBarPrefab);
_healthBarInstance.SetParent(healthBarCanvas, false);
healthBarSlider = _healthBarInstance.GetComponentInChildren<Slider>();
healthBarPos = this.transform.position;
healthBarPos.y += healthBarHeight;
_healthBarInstance.anchoredPosition = Camera.main.WorldToScreenPoint(healthBarPos);
}
示例8: Init
// Use this for initialization
void Init()
{
// Debug.Log("apply");
us=gameObject.GetComponent<RectTransform>();
//from=us.parent as RectTransform;
us.SetParent(us.RootCanvasTransform());
us.SetInternalAnchors (new Vector4 (0, 0, 1, 1));
//start=us.rect;
//reference=from.rect;
Rect rr = to.RootCanvasRect ();
// Debug.Log(rr);
tovec = (us.parent as RectTransform).getAnchorsFromCanvasRect (rr);
// Debug.Log(tovec);
stvec = new Vector4 (us.anchorMin.x,us.anchorMin.y,us.anchorMax.x,us.anchorMax.y);
}
示例9: RichEditLine
public RichEditLine(Transform parent, float width)
{
gameObject = new GameObject("RichEditLine");
transform = gameObject.AddComponent<RectTransform>();
transform.SetParent(parent, false);
transform.SetAsLastSibling();
layoutElement = gameObject.AddComponent<LayoutElement>();
layoutElement.preferredWidth = width;
layoutElement.preferredHeight = 0;
layoutGroup = gameObject.AddComponent<HorizontalLayoutGroup>();
layoutGroup.childForceExpandWidth = false;
layoutGroup.childForceExpandHeight = false;
layoutGroup.childAlignment = TextAnchor.LowerLeft;
}
示例10: RichEditBlock
public RichEditBlock(Transform parent, float width, float lineSpacing)
{
gameObject = new GameObject("RichEditBlock");
transform = gameObject.AddComponent<RectTransform>();
transform.SetParent(parent, false);
transform.SetAsLastSibling();
layoutElement = gameObject.AddComponent<LayoutElement>();
layoutElement.preferredWidth = width;
layoutElement.preferredHeight = 0;
layoutGroup = gameObject.AddComponent<VerticalLayoutGroup>();
layoutGroup.childForceExpandWidth = false;
layoutGroup.childForceExpandHeight = false;
layoutGroup.childAlignment = TextAnchor.LowerLeft;
layoutGroup.spacing = lineSpacing;
currentLine = AddNewLine();
}
示例11: Awake
void Awake()
{
m_TextMeshPro = gameObject.GetComponent<TextMeshProUGUI>();
m_Canvas = gameObject.GetComponentInParent<Canvas>();
// Get a reference to the camera if Canvas Render Mode is not ScreenSpace Overlay.
if (m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay)
m_Camera = null;
else
m_Camera = m_Canvas.worldCamera;
// Create pop-up text object which is used to show the link information.
m_TextPopup_RectTransform = Instantiate(TextPopup_Prefab_01) as RectTransform;
m_TextPopup_RectTransform.SetParent(m_Canvas.transform, false);
m_TextPopup_TMPComponent = m_TextPopup_RectTransform.GetComponentInChildren<TextMeshProUGUI>();
m_TextPopup_RectTransform.gameObject.SetActive(false);
}
示例12: Init
public virtual void Init()
{
// set attributes of scrollrect
scrollRect = GetComponent<ScrollRect> ();
scrollRect.onValueChanged.AddListener (OnValueChanged);
// set the scroll direction
switch (layout)
{
case Layout.Horizontal:
scrollRect.horizontal = true;
scrollRect.vertical = false;
break;
case Layout.Vertical:
scrollRect.horizontal = false;
scrollRect.vertical = true;
break;
}
// add a scrollrect content
GameObject go = new GameObject ();
go.name = "content";
content = go.AddComponent (typeof(RectTransform)) as RectTransform;
content.SetParent (transform);
content.pivot = new Vector2 (0, 1);
content.anchorMin = content.anchorMax = content.pivot;
content.anchoredPosition = Vector2.zero;
content.localScale = Vector3.one;
scrollRect.content = content;
// record some sizes
RectTransform scrollRectTransform = scrollRect.transform as RectTransform;
scrollRectSize = scrollRectTransform.rect.size;
// add mask
if (needMask)
{
Image image = gameObject.AddComponent(typeof(Image)) as Image;
image.color = new Color32(0, 0, 0, 5);
gameObject.AddComponent(typeof(Mask));
}
}
示例13: AddOption
/// <summary>
/// Add an option to the dialogue box
/// </summary>
/// <param name="option_text">Text to display for the option</param>
/// <param name="option_action">Function to run when this option is selected</param>
public void AddOption(string option_text, UnityAction option_action)
{
if (options.Count % 3 == 0)
{
current_option_panel = Instantiate(OptionPanelPrefab).GetComponent<RectTransform>();
current_option_panel.SetParent(transform, false);
current_option_panel.gameObject.SetActive(true);
panels.Add(current_option_panel);
}
Button new_button = Instantiate(OptionButtonPrefab).GetComponent<Button>();
new_button.transform.SetParent(current_option_panel.transform, false);
new_button.GetComponentInChildren<Text>().text = option_text;
new_button.onClick.AddListener(option_action);
new_button.gameObject.SetActive(true);
options.Add(new_button);
}
示例14: ApplyTo
public virtual void ApplyTo(GameObject ApplyingTo, Image UIicon, RectTransform UIdurationPanel, Transform parent)
{
affecting = ApplyingTo;
UIIcon = UIicon;
UIDurationPanel = UIdurationPanel;
BuffIndex = affecting.GetComponent<IBuffable>().GetNumberOfBuffs();
affecting.GetComponent<IBuffable>().AddNumberOfBuffs(1);
UIIcon.transform.SetParent(parent, false);
UIIcon.rectTransform.anchorMin = new Vector2(0.04f * BuffIndex, 0);
UIIcon.rectTransform.anchorMax = new Vector2(0.04f * (BuffIndex + 1), 1);
UIDurationPanel.SetParent(UIIcon.rectTransform, false);
UIDurationPanel.anchorMin = new Vector2(0, 0);
UIDurationPanel.anchorMax = new Vector2(1, 1);
UIIcon.sprite = Icon;
}
示例15: Awake
void Awake()
{
if (!enabled)
return;
Application.targetFrameRate = -1;
GameObject frameCounter = new GameObject("Frame Counter");
m_frameCounter_transform = frameCounter.AddComponent<RectTransform>();
m_frameCounter_transform.SetParent(this.transform, false);
m_TextMeshPro = frameCounter.AddComponent<TextMeshProUGUI>();
m_TextMeshPro.font = Resources.Load("Fonts & Materials/ARIAL SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/ARIAL SDF Overlay", typeof(Material)) as Material;
m_TextMeshPro.enableWordWrapping = false;
m_TextMeshPro.fontSize = 36;
m_TextMeshPro.isOverlay = true;
Set_FrameCounter_Position(AnchorPosition);
last_AnchorPosition = AnchorPosition;
}