public void OnBeginDrag(PointerEventData data) { Debug.Log("On Begin Drag"); canvas = GameObject.Find("Screen Overlay Canvas"); if (onHand) { placeHolder = new GameObject(); placeHolder.name = "PlaceHolder"; placeHolder.transform.SetParent(this.transform.parent); LayoutElement le = placeHolder.AddComponent <LayoutElement>(); RectTransform rt = le.GetComponent <RectTransform>(); rt.sizeDelta = new Vector2(80, 160); placeHolder.transform.SetSiblingIndex(this.transform.GetSiblingIndex()); this.transform.SetParent(canvas.transform); } else if (!onHand) { this.transform.SetParent(canvas.transform); Debug.Log("Move from table to hand!"); this.transform.localPosition = Vector3.one; this.transform.localScale = new Vector3(1.5f, 1.5f, 1); data.pointerDrag.transform.localRotation = Quaternion.identity; } GetComponent <CanvasGroup>().blocksRaycasts = false; }
public void SetValue(float value, bool special) { LayoutElement bar = _gridBars[0]; // Set new value bar.GetComponent <Image>().color = special ? Color.red : Color.green; bar.minHeight = value * _gridHeight; // Push to end of transform bar.transform.SetAsLastSibling(); // Move to end of list _gridBars.RemoveAt(0); _gridBars.Add(bar); }
private void Update() { if ((Object)tooltipSetting != (Object)null) { tooltipSetting.UpdateWhileHovered(); } if (!((Object)multiTooltipContainer == (Object)null) && !((Object)anchorRoot == (Object)null)) { if ((Object)dirtyHoverTooltip != (Object)null) { ToolTip tt = dirtyHoverTooltip; MakeDirtyTooltipClean(tt); ClearToolTip(tt); } if (tooltipIncubating) { tooltipIncubating = false; Image componentInChildren = anchorRoot.GetComponentInChildren <Image>(); if ((Object)componentInChildren != (Object)null) { anchorRoot.GetComponentInChildren <Image>(true).enabled = false; } multiTooltipContainer.transform.localScale = Vector3.zero; toolTipIsBlank = true; for (int i = 0; i < multiTooltipContainer.transform.childCount; i++) { if (multiTooltipContainer.transform.GetChild(i).transform.localScale != Vector3.one) { multiTooltipContainer.transform.GetChild(i).transform.localScale = Vector3.one; } LayoutElement component = multiTooltipContainer.transform.GetChild(i).GetComponent <LayoutElement>(); TextMeshProUGUI component2 = component.GetComponent <TextMeshProUGUI>(); toolTipIsBlank = (component2.text == string.Empty && toolTipIsBlank); if (component.minHeight != component2.preferredHeight) { component.minHeight = component2.preferredHeight; } } } else if (multiTooltipContainer.transform.localScale != Vector3.one && !toolTipIsBlank) { Image componentInChildren2 = anchorRoot.GetComponentInChildren <Image>(); if ((Object)componentInChildren2 != (Object)null) { anchorRoot.GetComponentInChildren <Image>(true).enabled = true; } multiTooltipContainer.transform.localScale = Vector3.one; } } }
void HandleContent() { content = gameObject.AddImageChild().AddOrGetComponent<LayoutElement>(); #if UNITY_EDITOR Undo.RegisterCreatedObjectUndo(content.gameObject, "content"); #endif content.minHeight = LayoutPanel.topHeight; content.minWidth = 26; content.flexibleWidth = 0.001f; content.GetComponent<Image>().enabled = false; content.name = "CONTENT"; Fold(content); }
// ----------------------------------------------------------------------------------- IEnumerator Resize() { // make the grid as tiny as possible as to make sure it fits inside the UI // but give it a really large flexible size, so it tries to fit as much // as the UI as it can heightController.minHeight = IconSize; heightController.preferredHeight = IconSize; heightController.flexibleHeight = 500000; widthController.minWidth = IconSize; widthController.preferredWidth = IconSize; widthController.flexibleWidth = 500000; // needed here, otherwise ForceRebuildLayoutImmediate doesn't work // for some goddamn reason yield return(null); // force the rect to resize. This will give us the // actual amount of available space for the grid RectTransform rt = widthController.GetComponent <RectTransform>(); LayoutRebuilder.ForceRebuildLayoutImmediate(rt); // amazingly, this is needed here too! yield return(null); // okay, so now we have the maximum amount of available // space for the grid float w = rt.sizeDelta.x; float h = rt.sizeDelta.y; // make sure we make it nice and snug to fit an integer amount of icons iconsPerPageX = Mathf.FloorToInt(w / IconSize); iconsPerPageY = Mathf.FloorToInt(h / IconSize); w = (iconsPerPageX * IconSize) + 4; // 2px padding on each side h = (iconsPerPageY * IconSize) + 4; // now resize it again heightController.minHeight = h; heightController.preferredHeight = h; heightController.flexibleHeight = 0; widthController.minWidth = w; widthController.preferredWidth = w; widthController.flexibleWidth = 0; Paginate(); }
public void AddBordersAndSampleContent() { if (name.Contains(LayoutPanel.spacerName)) { name = "Item " + zExt.RandomString(4); } AddBordersOnly(); var fold = gameObject.AddOrGetComponent <LayoutFoldController>(); if (fold.foldButton == null) { foldButton = CreateFoldButton(); fold.foldButton = foldButton; } else { foldButton = fold.foldButton; } Fold(fold); VerticalLayoutGroup group = gameObject.AddOrGetComponent <VerticalLayoutGroup>(); group.SetChildControl(2); Fold(group); content = gameObject.AddImageChild().AddOrGetComponent <LayoutElement>(); content.minHeight = LayoutTopControl.topHeight; content.minWidth = 26; content.flexibleWidth = 0.001f; content.GetComponent <Image>().enabled = false; content.name = "CONTENT"; Fold(content); layoutBorderHide = gameObject.AddOrGetComponent <LayoutBorderHide>(); #if UNITY_EDITOR Selection.activeObject = content; #endif Fold(GetComponent <RectTransform>()); TryToGetReferences(); var panel = gameObject.AddOrGetComponent <LayoutPanel>(); if (panel.resizableElement == null) { panel.resizableElement = content; } }
public void OnPointerDown(PointerEventData eventData) { if (inside) { dragging = true; Cursor.SetCursor(cursorTexture, hotSpot, cursorMode); startMouseY = Input.mousePosition.y; previousStartHeight = previousElement.preferredHeight; if (previousStartHeight == -1) { previousStartHeight = previousElement.GetComponent <RectTransform>().rect.height; } nextStartHeight = nextElement.preferredHeight; if (nextStartHeight == -1) { nextStartHeight = nextElement.GetComponent <RectTransform>().rect.height; } } }
protected override void OnLateUpdate() { base.OnLateUpdate(); if (Application.isPlaying == true) { // キャレットが表示されなくなるバグ対策 if (_inputField != null && m_LE == null) { m_LE = _inputField.GetComponentInChildren <LayoutElement>(); if (m_LE != null) { CanvasRenderer tCR0 = m_LE.GetComponent <CanvasRenderer>(); CanvasRenderer tCR1 = _inputField.GetComponent <CanvasRenderer>(); if (tCR0 != null && tCR1 != null) { tCR0.SetMaterial(tCR1.GetMaterial(), 0); } } } } }
public void SetLayoutVertical() { SetSizes(); _layoutElementTopLeft.GetComponent <RectTransform>().SetPosition( 0, RectTransform.rect.height - _layoutElementTopLeft.preferredHeight); _layoutElementTopRight.GetComponent <RectTransform>().SetPosition( RectTransform.rect.width - _layoutElementTopRight.preferredWidth, RectTransform.rect.height - _layoutElementTopRight.preferredHeight); _layoutElementMiddle.GetComponent <RectTransform>().SetPosition( RectTransform.rect.width / 2 - _layoutElementMiddle.preferredWidth / 2, RectTransform.rect.height / 2 - _layoutElementMiddle.preferredHeight / 2); _layoutElementBottomLeft.GetComponent <RectTransform>().SetPosition( 0, 0); _layoutElementBottomRight.GetComponent <RectTransform>().SetPosition( RectTransform.rect.width - _layoutElementBottomRight.preferredWidth, 0); }
public void Initialize(ComplexFabricator target) { if ((Object)target == (Object)null) { Debug.LogError("ComplexFabricator provided was null."); } else { targetFab = target; base.gameObject.SetActive(true); recipeMap = new Dictionary <GameObject, ComplexRecipe>(); recipeToggles.ForEach(delegate(GameObject rbi) { Object.Destroy(rbi.gameObject); }); recipeToggles.Clear(); GridLayoutGroup component = recipeGrid.GetComponent <GridLayoutGroup>(); switch (targetFab.sideScreenStyle) { case StyleSetting.ListResult: case StyleSetting.ListInput: case StyleSetting.ListInputOutput: { component.constraintCount = 1; GridLayoutGroup gridLayoutGroup2 = component; Vector2 cellSize2 = component.cellSize; gridLayoutGroup2.cellSize = new Vector2(262f, cellSize2.y); break; } case StyleSetting.ClassicFabricator: component.constraintCount = 128; component.cellSize = new Vector2(78f, 96f); buttonScrollContainer.minHeight = 100f; break; case StyleSetting.ListQueueHybrid: component.constraintCount = 1; component.cellSize = new Vector2(264f, 64f); buttonScrollContainer.minHeight = 66f; break; default: { component.constraintCount = 3; GridLayoutGroup gridLayoutGroup = component; Vector2 cellSize = component.cellSize; gridLayoutGroup.cellSize = new Vector2(116f, cellSize.y); break; } } int num = 0; ComplexRecipe[] recipes = targetFab.GetRecipes(); ComplexRecipe[] array = recipes; foreach (ComplexRecipe recipe in array) { bool flag = false; if (DebugHandler.InstantBuildMode) { flag = true; } else if (recipe.RequiresTechUnlock() && recipe.IsRequiredTechUnlocked()) { flag = true; } else if (target.GetRecipeQueueCount(recipe) != 0) { flag = true; } else if (AnyRecipeRequirementsDiscovered(recipe)) { flag = true; } else if (HasAnyRecipeRequirements(recipe)) { flag = true; } if (flag) { num++; Tuple <Sprite, Color> uISprite = Def.GetUISprite(recipe.ingredients[0].material, "ui", false); Tuple <Sprite, Color> uISprite2 = Def.GetUISprite(recipe.results[0].material, "ui", false); KToggle newToggle = null; GameObject entryGO; switch (target.sideScreenStyle) { case StyleSetting.ListInputOutput: case StyleSetting.GridInputOutput: { newToggle = Util.KInstantiateUI <KToggle>(recipeButtonMultiple, recipeGrid, false); entryGO = newToggle.gameObject; HierarchyReferences component2 = newToggle.GetComponent <HierarchyReferences>(); ComplexRecipe.RecipeElement[] ingredients = recipe.ingredients; foreach (ComplexRecipe.RecipeElement recipeElement in ingredients) { GameObject gameObject = Util.KInstantiateUI(component2.GetReference("FromIconPrefab").gameObject, component2.GetReference("FromIcons").gameObject, true); gameObject.GetComponent <Image>().sprite = Def.GetUISprite(recipeElement.material, "ui", false).first; gameObject.GetComponent <Image>().color = Def.GetUISprite(recipeElement.material, "ui", false).second; gameObject.gameObject.name = recipeElement.material.Name; } ComplexRecipe.RecipeElement[] results = recipe.results; foreach (ComplexRecipe.RecipeElement recipeElement2 in results) { GameObject gameObject2 = Util.KInstantiateUI(component2.GetReference("ToIconPrefab").gameObject, component2.GetReference("ToIcons").gameObject, true); gameObject2.GetComponent <Image>().sprite = Def.GetUISprite(recipeElement2.material, "ui", false).first; gameObject2.GetComponent <Image>().color = Def.GetUISprite(recipeElement2.material, "ui", false).second; gameObject2.gameObject.name = recipeElement2.material.Name; } break; } case StyleSetting.ListQueueHybrid: { newToggle = Util.KInstantiateUI <KToggle>(recipeButtonQueueHybrid, recipeGrid, false); entryGO = newToggle.gameObject; recipeMap.Add(entryGO, recipe); Image image = entryGO.GetComponentsInChildrenOnly <Image>()[2]; if (recipe.nameDisplay == ComplexRecipe.RecipeNameDisplay.Ingredient) { image.sprite = uISprite.first; image.color = uISprite.second; } else { image.sprite = uISprite2.first; image.color = uISprite2.second; } entryGO.GetComponentInChildren <LocText>().text = recipe.GetUIName(); bool flag2 = HasAllRecipeRequirements(recipe); image.material = ((!flag2) ? Assets.UIPrefabs.TableScreenWidgets.DesaturatedUIMaterial : Assets.UIPrefabs.TableScreenWidgets.DefaultUIMaterial); RefreshQueueCountDisplay(entryGO, targetFab); entryGO.GetComponent <HierarchyReferences>().GetReference <MultiToggle>("DecrementButton").onClick = delegate { target.DecrementRecipeQueueCount(recipe, false); RefreshQueueCountDisplay(entryGO, target); }; entryGO.GetComponent <HierarchyReferences>().GetReference <MultiToggle>("IncrementButton").onClick = delegate { target.IncrementRecipeQueueCount(recipe); RefreshQueueCountDisplay(entryGO, target); }; entryGO.gameObject.SetActive(true); break; } default: { newToggle = Util.KInstantiateUI <KToggle>(recipeButton, recipeGrid, false); entryGO = newToggle.gameObject; Image componentInChildrenOnly = newToggle.gameObject.GetComponentInChildrenOnly <Image>(); if (target.sideScreenStyle == StyleSetting.GridInput || target.sideScreenStyle == StyleSetting.ListInput) { componentInChildrenOnly.sprite = uISprite.first; componentInChildrenOnly.color = uISprite.second; } else { componentInChildrenOnly.sprite = uISprite2.first; componentInChildrenOnly.color = uISprite2.second; } break; } } if (targetFab.sideScreenStyle == StyleSetting.ClassicFabricator) { newToggle.GetComponentInChildren <LocText>().text = recipe.results[0].material.ProperName(); } else if (targetFab.sideScreenStyle != StyleSetting.ListQueueHybrid) { newToggle.GetComponentInChildren <LocText>().text = string.Format(UI.UISIDESCREENS.REFINERYSIDESCREEN.RECIPE_FROM_TO_WITH_NEWLINES, recipe.ingredients[0].material.ProperName(), recipe.results[0].material.ProperName()); } ToolTip component3 = entryGO.GetComponent <ToolTip>(); component3.toolTipPosition = ToolTip.TooltipPosition.Custom; component3.parentPositionAnchor = new Vector2(0f, 0.5f); component3.tooltipPivot = new Vector2(1f, 1f); component3.tooltipPositionOffset = new Vector2(-24f, 20f); component3.ClearMultiStringTooltip(); component3.AddMultiStringTooltip(recipe.GetUIName(), styleTooltipHeader); component3.AddMultiStringTooltip(recipe.description, styleTooltipBody); newToggle.onClick += delegate { ToggleClicked(newToggle); }; entryGO.SetActive(true); recipeToggles.Add(entryGO); } } if (recipeToggles.Count > 0) { LayoutElement component4 = buttonScrollContainer.GetComponent <LayoutElement>(); float num2 = (float)num; Vector2 sizeDelta = recipeButtonQueueHybrid.rectTransform().sizeDelta; component4.minHeight = Mathf.Min(451f, 2f + num2 * sizeDelta.y); subtitleLabel.SetText(UI.UISIDESCREENS.FABRICATORSIDESCREEN.SUBTITLE); noRecipesDiscoveredLabel.gameObject.SetActive(false); } else { subtitleLabel.SetText(UI.UISIDESCREENS.FABRICATORSIDESCREEN.NORECIPEDISCOVERED); noRecipesDiscoveredLabel.SetText(UI.UISIDESCREENS.FABRICATORSIDESCREEN.NORECIPEDISCOVERED_BODY); noRecipesDiscoveredLabel.gameObject.SetActive(true); LayoutElement component5 = buttonScrollContainer.GetComponent <LayoutElement>(); Vector2 sizeDelta2 = noRecipesDiscoveredLabel.rectTransform.sizeDelta; component5.minHeight = sizeDelta2.y + 10f; } RefreshIngredientAvailabilityVis(); } }
private void SetElementSize(LayoutElement element) { element.GetComponent <RectTransform>().sizeDelta = new Vector2(element.preferredWidth, element.preferredHeight); }
// Update is called once per frame private void Update() { row.preferredHeight = text.GetComponent <Text>().preferredHeight + 4; }