public void UpdateLives(float lives) { int livesInt = Mathf.FloorToInt(lives); List <RectTransform> lifeIcons = new List <RectTransform> (); livesContainer.GetComponentsInChildren <RectTransform>(lifeIcons); if (livesContainer.GetComponent <RectTransform> () != null) { lifeIcons.Remove(livesContainer.GetComponent <RectTransform>()); } int lifeIconsCount = lifeIcons.Count; while (lifeIconsCount > livesInt) { Destroy(lifeIcons[lifeIconsCount - 1].gameObject); lifeIconsCount--; } while (lifeIconsCount < livesInt) { GameObject newHeart = Instantiate(lifeHeartPrefab) as GameObject; newHeart.transform.SetParent(livesContainer.transform, false); lifeIconsCount++; } }
void Awake() { _scrollRect = gameObject.GetComponentInChildren <ScrollRect>(); _scrollRectTransform = _scrollRect.gameObject.GetComponent <RectTransform>(); foreach (LayoutGroup layoutGroup in _scrollRect.content.GetComponents <LayoutGroup>()) { layoutGroup.enabled = false; } if (m_ViewType == ViewType.Vertical) { _contentLayoutGroup = _scrollRect.content.GetComponent <VerticalLayoutGroup>(); _contentLayoutGroupParams = m_VerticalLayoutParams; } else if (m_ViewType == ViewType.Horizontal) { _contentLayoutGroup = _scrollRect.content.GetComponent <HorizontalLayoutGroup>(); _contentLayoutGroupParams = m_HorizontalLayoutParams; } else { _contentLayoutGroup = _scrollRect.content.GetComponent <GridLayoutGroup>(); _contentLayoutGroupParams = m_GridLayoutParams; } _contentLayoutGroup.enabled = true; _contentTransform = _contentLayoutGroup.GetComponent <RectTransform>(); }
private void adjustContentViewSize() { int nrOfMessages = MessagesList.transform.childCount; float heightOfPreFab = MessagePrefab.GetComponent<RectTransform>().sizeDelta.y; RectTransform contentContainer = MessagesList.GetComponent<RectTransform>(); Vector2 currentMin = contentContainer.offsetMin; contentContainer.offsetMin = new Vector2(contentContainer.offsetMin.x, nrOfMessages * heightOfPreFab * -1); }
private void OnValidate() { if (layoutGroup == null) { layoutGroup = GetComponent<LayoutGroup>(); } if (layoutGroup != null) { rectTransform = layoutGroup.GetComponent<RectTransform>(); } }
public virtual void Show(Vector2 pos) { if (OpenMenu != this && OpenMenu != null) { OpenMenu.Hide(); } gameObject.SetActive(true); pos.x += ButtonContainer.GetComponent <RectTransform>().sizeDelta.x; transform.position = pos; }
public void Init() { //Initialize build panel foreach (BuildingType bt in Enum.GetValues(typeof(BuildingType))) { BuildingDefinition bd = BuildingLibrary.I.GetDefinition(bt); GameObject buildPanelElement = Instantiate(buildPanelElementPrefab); buildPanelElement.transform.SetParent(layoutBuildPanel.transform); buildPanelElement.transform.localScale = Vector3.one; buildPanelElement.GetComponent <Toggle>().group = layoutBuildPanel.GetComponent <ToggleGroup>(); buildPanelElement.GetComponent <BuildElement>().Init(bd, this); } waveInfoPanel.Init(this); }
//记录初始的Layout数据 private void InitLayoutData() { //挂载循环列表后,padding值会被修改` WrapContent wrapContent = _contentLayout.GetComponent <WrapContent>(); if (wrapContent && wrapContent.InitPadding != null) { if (horizontal) { _paddingSize.Set(wrapContent.InitPadding.left, wrapContent.InitPadding.right); } else if (vertical) { _paddingSize.Set(wrapContent.InitPadding.top, wrapContent.InitPadding.bottom); } _space = wrapContent.Space; return; } if (_contentLayout is HorizontalLayoutGroup || _contentLayout is VerticalLayoutGroup) { HorizontalOrVerticalLayoutGroup hvLayout = (HorizontalOrVerticalLayoutGroup)_contentLayout; _space = hvLayout.spacing; if (horizontal) { _paddingSize.Set(hvLayout.padding.left, hvLayout.padding.right); } else if (vertical) { _paddingSize.Set(hvLayout.padding.top, hvLayout.padding.bottom); } } else if (_contentLayout is GridLayoutGroup) { GridLayoutGroup grid = (GridLayoutGroup)_contentLayout; if (horizontal) { _space = grid.spacing.x; _paddingSize.Set(grid.padding.left, grid.padding.right); } else if (vertical) { _space = grid.spacing.y; _paddingSize.Set(grid.padding.top, grid.padding.bottom); } } }
override protected void ProcessCustomData(IUIScreenData customData) { if (_closingRoutine != null) { StopCoroutine(_closingRoutine); _closingRoutine = null; } base.ProcessCustomData(customData); bool dataExists = customData != null; CleanUpButtons(); _header.gameObject.SetActive(dataExists); _message.gameObject.SetActive(dataExists); foreach (UIGenericPopupButton button in _originalButtons) { button.gameObject.SetActive(dataExists); } if (dataExists) { UIGenericPopupData data = (UIGenericPopupData)customData; SetText(_header, data.Header); SetText(_message, data.Message); SetupButtons(data.Buttons); if (data.Width > 0f) { RectTransform rt = _layoutGroup.GetComponent <RectTransform>(); if (rt != null) { rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, data.Width); } } if (data.Timeout > 0f) { CloseWithDelay(data.Timeout); } } }
private void SortScores() { playersSorted.Clear(); foreach (RectTransform tr in playerList.transform) { playersSorted.Add(tr.GetComponent <ScoreRow>()); } playersSorted.Sort(KillsComparer); for (var i = 0; i < playersSorted.Count; i++) { playersSorted[i].transform.SetSiblingIndex(i); } LayoutRebuilder.MarkLayoutForRebuild(playerList.GetComponent <RectTransform>()); dirty = false; }
void HandleIncomingMessage(string payload) { IncomingMessage message = JsonUtility.FromJson <IncomingMessage>(payload); switch (Enum.Parse(typeof(IncomingMessageAction), message.action)) { case IncomingMessageAction.Initialize: Configuration configuration = JsonUtility.FromJson <Configuration>(message.payload); Debug.Log("Initialize with: " + configuration.name + " - " + configuration.player); configurationsController.Initialize(configuration); DestroyImmediate(this.webViewObject.gameObject); LayoutGroup canvas = GameObject.Find("Canvas").GetComponent <LayoutGroup>(); LayoutRebuilder.ForceRebuildLayoutImmediate(canvas.GetComponent <RectTransform>()); //foreach (var layoutGroup in canvas.GetComponentsInChildren<LayoutGroup>()) //{ // LayoutRebuilder.ForceRebuildLayoutImmediate(layoutGroup.GetComponent<RectTransform>()); //} break; default: break; } }
protected virtual void SetupTarget() { if (targetTF != null && targetTF.gameObject.layer == LayerMask.NameToLayer("UI")) // Only do for UI { _targetParentTF = targetTF.parent; RectTransform targetRT = targetTF.GetComponent <RectTransform>(); _targetSiblingIndex = targetRT.GetSiblingIndex(); if (cloneTarget && _targetCloneGO == null) // Position the target clone to target's position { _targetCloneGO = targetTF.parent.gameObject.AddChild(targetTF.gameObject); RectTransform targetCloneRT = _targetCloneGO.GetComponent <RectTransform>(); if (targetCloneRT != null) { targetCloneRT.SetSiblingIndex(_targetSiblingIndex); targetCloneRT.sizeDelta = targetRT.sizeDelta; } } // Move target to tutorial panel if (targetRT != null) { Transform transformToMoveInTutorialPanel = targetTF; if (putCloneToTutorialPanelInstead) { transformToMoveInTutorialPanel = _targetCloneGO.transform; // Add canvas sorting Canvas canvas = transformToMoveInTutorialPanel.GetComponent <Canvas>(); if (canvas != null) { canvas.sortingOrder += 1000; } // Remove TweenOnEnable TweenOnEnable tweenOnEnable = transformToMoveInTutorialPanel.GetComponent <TweenOnEnable>(); if (tweenOnEnable != null) { tweenOnEnable.ForceCancelTween(); Destroy(tweenOnEnable); } } transformToMoveInTutorialPanel.SetParent(tutorialPanel.transform, true); RectTransform rectTransformToMoveInTutorialPanel = transformToMoveInTutorialPanel.GetComponent <RectTransform>(); rectTransformToMoveInTutorialPanel.SetSiblingIndex(1); // Just after background mask // Set if target should catch raycasts and store original state Graphic graphicToMoveInTutorialPanel = rectTransformToMoveInTutorialPanel.GetComponent <Graphic>(); if (graphicToMoveInTutorialPanel != null) { _cachedRaycastTarget = graphicToMoveInTutorialPanel.raycastTarget; graphicToMoveInTutorialPanel.raycastTarget = targetCanCatchRaycast; } // Make sure it sets it to the right width. if (cloneTarget && _targetCloneGO != null) // Position the target clone to target's position { RectTransform subTf = (putCloneToTutorialPanelInstead) ? _targetCloneGO.GetComponent <RectTransform>() : targetTF.GetComponent <RectTransform>(); RectTransform coreTf = (putCloneToTutorialPanelInstead) ? targetTF.GetComponent <RectTransform>() : _targetCloneGO.GetComponent <RectTransform>(); LayoutGroup parentGroup = coreTf.GetComponentInParent <LayoutGroup>(); if (parentGroup != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(parentGroup.GetComponent <RectTransform>()); } subTf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, coreTf.rect.width); subTf.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, coreTf.rect.height); } // Try copy the data from target to clone _targetCloneGO?.SendMessage("CopyFrom", targetTF.gameObject, SendMessageOptions.DontRequireReceiver); } } foreach (Button b in _disableButtons) { if (b != null) { b.interactable = false; } } }
// Use this for initialization void Start() { view = GetComponent <RectTransform>(); contentRectTrsfm = contentLayout.GetComponent <RectTransform>(); StartCoroutine(UpdateScrollBarSize()); }
private void Awake() { Content = ContentLayout.GetComponent <RectTransform>(); listContent = ContentLayout.gameObject.AddComponent <CustomReorderableContent>(); listContent.InitializeReorderableContent(this); }