private void SetSelection(Ballistics.IProjectileConfiguration config) { List <CUBSPartDisplayWidget> widgets = new List <CUBSPartDisplayWidget>(GetComponentsInChildren <CUBSPartDisplayWidget>()); SetHeight(config.Parts.Count); bool isWidgetLayoutChanged = false; //add any extra widgets we may need while (config.Parts.Count > widgets.Count) { widgets.Add(ObjectPool.Spawn(partDisplayButtonPrefab)); } //set the parts for (int idx = 0; idx <= config.Parts.Count; ++idx) { CUBSPartDisplayWidget nextWidget = widgets[idx]; nextWidget.Part = config.Parts[idx]; } //clear unused widgets of thier current part for (int idx = config.Parts.Count; idx <= widgets.Count; ++idx) { widgets[idx].Part = null; } SetHeight(config.Parts.Count); if (isWidgetLayoutChanged) { UpdateLayout(widgets); } }
private void UpdateLayout(List <CUBSPartDisplayWidget> widgets) { for (int idx = 0; idx < widgets.Count; ++idx) { CUBSPartDisplayWidget nextWidget = widgets[idx]; RectTransform rt = nextWidget.transform as RectTransform; rt.SetParent(widgetContainerTranform); float inset = (idx * widgetHeight) + borderHeight; rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, inset, widgetHeight); nextWidget.RegisterPartChangeRequestListener(this.PartChangeRequestEventHandler); } }
private void PartChangeRequestEventHandler(object sender, CUBSPartDisplayWidget.PartChangeRequestEventArgs e) { configurationAltertionWidget.gameObject.SetActive(true); partToChange = e.partWidget; }