/// <summary> /// Sets all layout parameters of an object at once. /// </summary> /// <param name="item">The item to configure.</param> /// <param name="rawParams">The raw parameters to use.</param> internal void SetRaw(GameObject item, RelativeLayoutParams rawParams) { if (item != null && rawParams != null) { locConstraints[item] = rawParams; } }
/// <summary> /// Retrieves the parameters for a child game object. Creates an entry if none exists /// for this component. /// </summary> /// <param name="item">The item to look up.</param> /// <returns>The parameters for that object.</returns> private RelativeLayoutParams AddOrGet(GameObject item) { if (!locConstraints.TryGetValue(item, out RelativeLayoutParams param)) { locConstraints[item] = param = new RelativeLayoutParams(); } return(param); }
public override GameObject Build() { var panel = PUIElements.CreateUI(null, Name); var mapping = DictionaryPool <IUIComponent, GameObject, PRelativePanel> .Allocate(); SetImage(panel); // Realize each component and add them to the panel foreach (var pair in constraints) { var component = pair.Key; var realized = component.Build(); realized.SetParent(panel); // We were already guaranteed that there were no duplicate keys mapping[component] = realized; } // Add layout component var layout = panel.AddComponent <RelativeLayoutGroup>(); layout.Margin = Margin; foreach (var pair in constraints) { var realized = mapping[pair.Key]; var rawParams = pair.Value; var newParams = new RelativeLayoutParams(); // Copy all of the settings Resolve(newParams.TopEdge, rawParams.TopEdge, mapping); Resolve(newParams.BottomEdge, rawParams.BottomEdge, mapping); Resolve(newParams.LeftEdge, rawParams.LeftEdge, mapping); Resolve(newParams.RightEdge, rawParams.RightEdge, mapping); newParams.OverrideSize = rawParams.OverrideSize; newParams.Insets = rawParams.Insets; layout.SetRaw(realized, newParams); } if (!DynamicSize) { layout.LockLayout(); } mapping.Recycle(); // Set flex size layout.flexibleWidth = FlexSize.x; layout.flexibleHeight = FlexSize.y; InvokeRealize(panel); return(panel); }
internal RelativeLayoutResults(RectTransform transform, RelativeLayoutParams other) { Transform = transform ?? throw new ArgumentNullException(nameof(transform)); if (other != null) { BottomEdge.CopyFrom(other.BottomEdge); TopEdge.CopyFrom(other.TopEdge); RightEdge.CopyFrom(other.RightEdge); LeftEdge.CopyFrom(other.LeftEdge); Insets = other.Insets ?? ZERO; OverrideSize = other.OverrideSize; } else { Insets = ZERO; } BottomParams = LeftParams = TopParams = RightParams = null; PreferredWidth = PreferredHeight = 0.0f; UseSizeDeltaX = UseSizeDeltaY = false; }