public float Arrange() { if (!EventViews.Any()) { var height = RectTransform.sizeDelta.y; return(height); } var eventPosX = 0.0f; // Start by counting our own height from our top to the event attachement point var cumulativeHeight = 9.0f; // Then increment by space between bottom of step and top of event. cumulativeHeight += TimelineViewBehaviour.SpaceBetweenStepAndEventBadge; foreach (var eventView in EventViews) { // This positions the /attachment point/ eventView.RectTransform.anchoredPosition = new Vector2(eventPosX, 0.0f); eventPosX += TimelineViewBehaviour.HorizontalEventSpacing; // Ensure hierarchy order is synced with EventViews collection order. eventView.RectTransform.SetAsFirstSibling(); // Add height of iterated event and its steps recursive cumulativeHeight += eventView.Arrange(cumulativeHeight); if (eventView != EventViews.Last()) { if (eventView.StepViewsEnumerable.Any()) { cumulativeHeight += TimelineViewBehaviour.SpaceBetweenStepAndEventBadge; } else { cumulativeHeight += TimelineViewBehaviour.SpaceBetweenEventAndEvent; } } } // Make sure workspace fits this step var xFromWorkspaceEdge = RectTransform.sizeDelta.x - TimelineViewBehaviour.GetStepViewPositionRelativeToWorkspace(this).x; TimelineViewBehaviour.BoostWorkspaceMax(new Vector2(xFromWorkspaceEdge + 40, cumulativeHeight + 40)); // Finish by counting the height from the attachment point to the bottom. return(cumulativeHeight + 9.0f); }
private void AddStepView(Step step) { var stepViewGo = Instantiate(StepViewPrefab); var stepView = stepViewGo.GetComponent <TimelineStepViewBehaviour>(); stepView.transform.SetParent(StepAttachmentPoint, false); stepView.Step = step; stepView.EventColor = TimelineColorManager.GetEventColor(Event); StepViews.Add(stepView); TimelineViewBehaviour.RegisterStepView(stepView); }
private void RemoveStepView(Step step) { var stepView = StepViews.FirstOrDefault(view => view.Step == step); if (stepView == null) { return; } StepViews.Remove(stepView); stepView.Shutdown(); Destroy(stepView.gameObject); TimelineViewBehaviour.UnregisterStepView(stepView); }