本文整理汇总了C#中UnityEngine.RectTransform.GetComponentsInChildren方法的典型用法代码示例。如果您正苦于以下问题:C# RectTransform.GetComponentsInChildren方法的具体用法?C# RectTransform.GetComponentsInChildren怎么用?C# RectTransform.GetComponentsInChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.RectTransform
的用法示例。
在下文中一共展示了RectTransform.GetComponentsInChildren方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start () {
carouselToggler = gameObject.GetComponent<CarouselToggler> ();
ScrollRect scrollRect = gameObject.GetComponent<ScrollRect> ();
content = scrollRect.content;
Toggle[] toggles = content.GetComponentsInChildren<Toggle> ();
lastToggle = toggles [0];
StartCoroutine (WaitInactiveCycleAndReset());
}
示例2: PlayScaleAnimation
// Scale animation responsible for hiding and showing the element when required.
IEnumerator PlayScaleAnimation(RectTransform thisRectTransform, Axis axis, float finalScale, float duration)
{
tabManager.busyWithButtonAnimation = true;
float currentScale = 0.0f, stepDuration = 0.1f;
// Get Current Scale
if (axis == Axis.X)
{
currentScale = thisRectTransform.localScale.x;
} else
if (axis == Axis.Y)
{
currentScale = thisRectTransform.localScale.y;
}
// Show Child Elements Back, If Showing
if (finalScale > currentScale)
foreach (RectTransform thatRectTransform in thisRectTransform.GetComponentsInChildren<RectTransform>())
if (thatRectTransform!=thisRectTransform)
thatRectTransform.localScale = new Vector3(1,1,1);
// Ensure At Least 2 Animation Steps
if (stepDuration > duration/2) stepDuration = duration/2;
// Calculate Steps
// float scaleStep = (finalScale-currentScale)/(duration/stepDuration); // Remove Scale Step
// Execute Animation
for (float currentDuration=0; currentDuration<duration; currentDuration+=stepDuration)
{
float progress = currentDuration/duration;
float easeProgress = (Mathf.Sin((-90f + 180f*progress)*Mathf.Deg2Rad)+1f)*0.5f;
if (axis == Axis.X) thisRectTransform.localScale = new Vector3(currentScale + easeProgress * (finalScale - currentScale), thisRectTransform.localScale.y, thisRectTransform.localScale.z);
else if (axis == Axis.Y) thisRectTransform.localScale = new Vector3(thisRectTransform.localScale.x, currentScale + easeProgress * (finalScale - currentScale), thisRectTransform.localScale.z);
yield return new WaitForSeconds(stepDuration);
}
if (axis == Axis.X && thisRectTransform.localScale.x!=finalScale) thisRectTransform.localScale = new Vector3(finalScale, thisRectTransform.localScale.y, thisRectTransform.localScale.z);
else if (axis == Axis.Y && thisRectTransform.localScale.y!=finalScale) thisRectTransform.localScale = new Vector3(thisRectTransform.localScale.x, finalScale, thisRectTransform.localScale.z);
// Hide Child Elements, If Hiding
if (currentScale > finalScale)
foreach (RectTransform thatRectTransform in thisRectTransform.GetComponentsInChildren<RectTransform>())
if (thatRectTransform!=thisRectTransform)
thatRectTransform.localScale = new Vector3(0,0,0);
tabManager.busyWithButtonAnimation = false;
}
示例3: InitializeTransitionPage
public GameObject InitializeTransitionPage(GameObject transition)
{
//set the transition page
GameObject go = Instantiate(transition as GameObject);
transitionPage = go.GetComponent<RectTransform>();
//the transition page parent needs to be the canvas (or one of its children)
transitionPage.transform.SetParent(GameObject.FindGameObjectWithTag(parentTag).transform); //keep the canvas as the parent
transitionPage.transform.localScale = Vector3.one;
//fill the text and image arrays with components that need to be faded
transitionTxts = transitionPage.GetComponentsInChildren<Text>();
transitionImgs = transitionPage.GetComponentsInChildren<Image>();
//start the page off at transparent
foreach (Text t in transitionTxts)
t.color = new Vector4(t.color.r, t.color.g, t.color.b, 0);
foreach (Image i in transitionImgs)
i.color = new Vector4(i.color.r, i.color.g, i.color.b, 0);
transitionInitialized = true;
return transitionPage.gameObject;
}
示例4: 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);
}
示例5: 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 ;
}
}
示例6: markPlayerLayer
void markPlayerLayer(GameModel game, RectTransform gameCanvas) {
if (!game.ended) {
// get components
Image[] images = gameCanvas.GetComponentsInChildren<Image> ();
Image challengerLayer = images[1];
Image challengedLayer = images[2];
// activate
if (game.thisTurn == game.players.challenger.username) {
challengerLayer.enabled = true;
challengedLayer.enabled = false;
}
else {
challengedLayer.enabled = true;
challengerLayer.enabled = false;
}
}
}
示例7: setPlayersCategories
void setPlayersCategories(GameModel game, RectTransform gameCanvas) {
PlayerLeftCategoryProgressScript[] leftCategoriesProgress;
PlayerRightCategoryProgressScript[] rightCategoriesProgress;
// update categories progress
leftCategoriesProgress = gameCanvas.GetComponentsInChildren<PlayerLeftCategoryProgressScript>();
foreach (PlayerLeftCategoryProgressScript categoryProgress in leftCategoriesProgress) {
categoryProgress.updateCategory(game.players.challenger.categoriesProgress);
}
rightCategoriesProgress = gameCanvas.GetComponentsInChildren<PlayerRightCategoryProgressScript>();
foreach (PlayerRightCategoryProgressScript categoryProgress in rightCategoriesProgress) {
categoryProgress.updateCategory(game.players.challenged.categoriesProgress);
}
}
示例8: SetMassAlpha
void SetMassAlpha(RectTransform root, float alpha)
{
foreach(var graphic in root.GetComponentsInChildren<CanvasRenderer>()){
graphic.SetAlpha(alpha);
}
}
示例9: ScaleSizeGivenExpectedWidth
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);
}
}