private void CreateRow(IAtomAnimationTarget target) { var go = new GameObject("Row"); go.transform.SetParent(_layout.transform, false); var layout = go.AddComponent <LayoutElement>(); layout.preferredHeight = _style.RowHeight; DopeSheetKeyframes keyframes = null; GradientImage labelBackgroundImage = null; { var child = new GameObject(); child.transform.SetParent(go.transform, false); var rect = child.AddComponent <RectTransform>(); rect.StretchLeft(); rect.anchoredPosition = new Vector2(_style.LabelWidth / 2f, 0); rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _style.LabelWidth); labelBackgroundImage = child.AddComponent <GradientImage>(); labelBackgroundImage.top = _style.LabelBackgroundColorTop; labelBackgroundImage.bottom = _style.LabelBackgroundColorBottom; labelBackgroundImage.raycastTarget = true; var listener = child.AddComponent <Listener>(); listener.Bind( target.onSelectedChanged, () => UpdateSelected(target, keyframes, labelBackgroundImage) ); var click = child.AddComponent <Clickable>(); click.onClick.AddListener(_ => { target.selected = !target.selected; }); } { var child = new GameObject(); child.transform.SetParent(go.transform, false); var rect = child.AddComponent <RectTransform>(); var padding = 2f; rect.StretchLeft(); rect.anchoredPosition = new Vector2(_style.LabelWidth / 2f, 0); rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _style.LabelWidth - padding * 2); var text = child.AddComponent <Text>(); text.text = target.GetShortName(); text.font = _style.Font; text.fontSize = 20; text.color = _style.FontColor; text.alignment = TextAnchor.MiddleLeft; text.horizontalOverflow = HorizontalWrapMode.Wrap; text.resizeTextForBestFit = false; // Better but ugly if true text.raycastTarget = false; } { var child = new GameObject(); child.transform.SetParent(go.transform, false); var rect = child.AddComponent <RectTransform>(); rect.StretchParent(); rect.anchoredPosition = new Vector2(_style.LabelWidth / 2f, 0); rect.sizeDelta = new Vector2(-_style.LabelWidth, 0); keyframes = child.AddComponent <DopeSheetKeyframes>(); _keyframesRows.Add(keyframes); // TODO: We could optimize here by using the AnimationCurve directly, avoiding a copy. keyframes.SetKeyframes(target.GetAllKeyframesTime(), _clip.loop); keyframes.SetTime(_ms); keyframes.style = _style; keyframes.raycastTarget = true; var listener = go.AddComponent <Listener>(); listener.Bind( target.onAnimationKeyframesModified, () => { keyframes.SetKeyframes(target.GetAllKeyframesTime(), _clip.loop); keyframes.SetTime(_ms); } ); var targetWithCurves = target as IAnimationTargetWithCurves; if (targetWithCurves != null) { var click = go.AddComponent <Clickable>(); click.onClick.AddListener(eventData => OnClick(targetWithCurves, rect, eventData)); } } UpdateSelected(target, keyframes, labelBackgroundImage); }
private void CreateRow(IAtomAnimationTarget target) { var go = new GameObject("Row"); go.transform.SetParent(_content, false); var layout = go.AddComponent <LayoutElement>(); layout.preferredHeight = _style.RowHeight; DopeSheetKeyframes keyframes = null; GradientImage labelBackgroundImage = null; { var child = new GameObject(); child.transform.SetParent(go.transform, false); var rect = child.AddComponent <RectTransform>(); rect.StretchLeft(); rect.anchoredPosition = new Vector2(_style.LabelWidth / 2f, 0); rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _style.LabelWidth); labelBackgroundImage = child.AddComponent <GradientImage>(); labelBackgroundImage.top = _style.LabelBackgroundColorTop; labelBackgroundImage.bottom = _style.LabelBackgroundColorBottom; labelBackgroundImage.raycastTarget = true; var listener = child.AddComponent <Listener>(); // TODO: Change this for a dictionary and listen once instead of once per row! listener.Bind( _animationEditContext.onTargetsSelectionChanged, () => UpdateSelected(target, keyframes, labelBackgroundImage) ); var click = child.AddComponent <Clickable>(); click.onClick.AddListener(_ => { _animationEditContext.SetSelected(target, !_animationEditContext.IsSelected(target)); }); click.onRightClick.AddListener(_ => { target.SelectInVam(); }); } { var child = new GameObject(); child.transform.SetParent(go.transform, false); var rect = child.AddComponent <RectTransform>(); const float padding = 2f; rect.StretchLeft(); rect.anchoredPosition = new Vector2(_style.LabelWidth / 2f, 0); rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _style.LabelWidth - padding * 2); var text = child.AddComponent <Text>(); text.text = target.GetShortName(); text.font = _style.Font; text.fontSize = 20; text.color = _style.FontColor; text.alignment = TextAnchor.MiddleLeft; text.horizontalOverflow = HorizontalWrapMode.Wrap; text.resizeTextForBestFit = false; // Better but ugly if true text.raycastTarget = false; } { var child = new GameObject(); child.transform.SetParent(go.transform, false); var rect = child.AddComponent <RectTransform>(); rect.StretchParent(); rect.anchoredPosition = new Vector2(_style.LabelWidth / 2f, 0); rect.sizeDelta = new Vector2(-_style.LabelWidth, 0); keyframes = child.AddComponent <DopeSheetKeyframes>(); _keyframesRows.Add(keyframes); keyframes.SetKeyframes(target.GetAllKeyframesTime(), _clip.loop); keyframes.SetTime(_ms); keyframes.style = _style; keyframes.raycastTarget = true; var listener = go.AddComponent <Listener>(); listener.Bind( target.onAnimationKeyframesRebuilt, () => { keyframes.SetKeyframes(target.GetAllKeyframesTime(), _clip.loop); keyframes.SetTime(_ms); keyframes.SetVerticesDirty(); } ); var click = go.AddComponent <Clickable>(); click.onClick.AddListener(eventData => OnClick(target, rect, eventData)); } UpdateSelected(target, keyframes, labelBackgroundImage); }