Пример #1
0
        public void Remove(IAtomAnimationTarget target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.clip = null;

            var freeControllerAnimationTarget = target as FreeControllerAnimationTarget;

            if (freeControllerAnimationTarget != null)
            {
                Remove(freeControllerAnimationTarget);
                return;
            }

            var floatParamAnimationTarget = target as FloatParamAnimationTarget;

            if (floatParamAnimationTarget != null)
            {
                Remove(floatParamAnimationTarget);
                return;
            }

            var animationTarget = target as TriggersAnimationTarget;

            if (animationTarget != null)
            {
                Remove(animationTarget);
                return;
            }

            throw new NotSupportedException($"Cannot remove unknown target type {target}");
        }
Пример #2
0
        public bool TargetsSameAs(IAtomAnimationTarget target)
        {
            var t = target as FreeControllerAnimationTarget;

            if (t == null)
            {
                return(false);
            }
            return(t.controller == controller);
        }
Пример #3
0
        public bool TargetsSameAs(IAtomAnimationTarget target)
        {
            var t = target as FloatParamAnimationTarget;

            if (t == null)
            {
                return(false);
            }
            return(Targets(t.storableId, t.floatParamName));
        }
Пример #4
0
 public void SetSelected(IAtomAnimationTarget target, bool selected)
 {
     if (selected && !selectedTargets.Contains(target))
     {
         selectedTargets.Add(target);
     }
     else if (!selected && selectedTargets.Contains(target))
     {
         selectedTargets.Remove(target);
     }
     onTargetsSelectionChanged.Invoke();
 }
Пример #5
0
 private void UpdateSelected(IAtomAnimationTarget target, DopeSheetKeyframes keyframes, GradientImage image)
 {
     if (target.selected)
     {
         keyframes.selected = true;
         image.top          = _style.LabelBackgroundColorTopSelected;
         image.bottom       = _style.LabelBackgroundColorBottomSelected;
     }
     else
     {
         keyframes.selected = false;
         image.top          = _style.LabelBackgroundColorTop;
         image.bottom       = _style.LabelBackgroundColorBottom;
     }
 }
Пример #6
0
 public IAtomAnimationTarget Add(IAtomAnimationTarget target)
 {
     if (target is FreeControllerAnimationTarget)
     {
         return(Add((FreeControllerAnimationTarget)target));
     }
     if (target is FloatParamAnimationTarget)
     {
         return(Add((FloatParamAnimationTarget)target));
     }
     if (target is TriggersAnimationTarget)
     {
         return(Add((TriggersAnimationTarget)target));
     }
     throw new NotSupportedException($"Cannot add unknown target type {target}");
 }
Пример #7
0
 public void Remove(IAtomAnimationTarget target)
 {
     if (target is FreeControllerAnimationTarget)
     {
         Remove((FreeControllerAnimationTarget)target);
         return;
     }
     if (target is FloatParamAnimationTarget)
     {
         Remove((FloatParamAnimationTarget)target);
         return;
     }
     if (target is TriggersAnimationTarget)
     {
         Remove((TriggersAnimationTarget)target);
         return;
     }
     throw new NotSupportedException($"Cannot remove unknown target type {target}");
 }
Пример #8
0
 public void RemoveAll(IAtomAnimationTarget target, bool includeEdges = false)
 {
     target.StartBulkUpdates();
     try
     {
         foreach (var time in target.GetAllKeyframesTime())
         {
             if (!includeEdges && (time == 0f || time == _clip.animationLength))
             {
                 continue;
             }
             target.DeleteFrame(time);
         }
     }
     finally
     {
         target.EndBulkUpdates();
     }
 }
Пример #9
0
        private void OnClick(IAtomAnimationTarget target, RectTransform rect, PointerEventData eventData)
        {
            if (!_animationEditContext.CanEdit())
            {
                return;
            }

            Vector2 localPosition;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, eventData.position, eventData.pressEventCamera, out localPosition))
            {
                return;
            }
            var width            = rect.rect.width - _style.KeyframesRowPadding * 2f;
            var ratio            = Mathf.Clamp01((localPosition.x + width / 2f) / width);
            var clickedTime      = ratio * _clip.animationLength;
            var previousClipTime = _animationEditContext.clipTime;

            _animationEditContext.clipTime = target.GetTimeClosestTo(clickedTime);
            if (!_animationEditContext.IsSelected(target))
            {
                _animationEditContext.SetSelected(target, true);
                if (!Input.GetKey(KeyCode.LeftControl))
                {
                    foreach (var t in _animationEditContext.selectedTargets.Where(x => x != target).ToList())
                    {
                        _animationEditContext.SetSelected(t, false);
                    }
                }
            }
            else if (previousClipTime == _animationEditContext.clipTime)
            {
                _animationEditContext.SetSelected(target, false);
                if (!Input.GetKey(KeyCode.LeftControl))
                {
                    foreach (var t in _animationEditContext.selectedTargets.Where(x => x != target).ToList())
                    {
                        _animationEditContext.SetSelected(t, false);
                    }
                }
            }
        }
Пример #10
0
        private void OnClick(IAtomAnimationTarget target, RectTransform rect, PointerEventData eventData)
        {
            if (SuperController.singleton.gameMode != SuperController.GameMode.Edit)
            {
                return;
            }

            Vector2 localPosition;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, eventData.position, eventData.pressEventCamera, out localPosition))
            {
                return;
            }
            var width            = rect.rect.width - _style.KeyframesRowPadding * 2f;
            var ratio            = Mathf.Clamp01((localPosition.x + width / 2f) / width);
            var clickedTime      = ratio * _clip.animationLength;
            var previousClipTime = _animation.clipTime;

            _animation.clipTime = target.GetTimeClosestTo(clickedTime);
            if (!target.selected)
            {
                target.selected = true;
                if (!Input.GetKey(KeyCode.LeftControl))
                {
                    foreach (var t in _clip.GetAllTargets().Where(x => x.selected && x != target))
                    {
                        t.selected = false;
                    }
                }
            }
            else if (previousClipTime == _animation.clipTime)
            {
                target.selected = false;
                if (!Input.GetKey(KeyCode.LeftControl))
                {
                    foreach (var t in _clip.GetAllTargets().Where(x => x.selected && x != target))
                    {
                        t.selected = false;
                    }
                }
            }
        }
Пример #11
0
        private void UpdateSelected(IAtomAnimationTarget target, DopeSheetKeyframes keyframes, GradientImage image)
        {
            var selected = _animationEditContext.IsSelected(target);

            if (keyframes.selected == selected)
            {
                return;
            }

            if (selected)
            {
                keyframes.selected = true;
                image.top          = _style.LabelBackgroundColorTopSelected;
                image.bottom       = _style.LabelBackgroundColorBottomSelected;
            }
            else
            {
                keyframes.selected = false;
                image.top          = _style.LabelBackgroundColorTop;
                image.bottom       = _style.LabelBackgroundColorBottom;
            }
        }
 public bool TargetsSameAs(IAtomAnimationTarget target)
 {
     return(target.name == name);
 }
Пример #13
0
 public bool IsSelected(IAtomAnimationTarget t)
 {
     return(selectedTargets.Contains(t));
 }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }