Exemple #1
0
    /// <summary>
    /// Converts a point in local space of this SLayout to the local space of another SLayout.
    /// If you pass a null SLayout, it will get the point in the space of the canvas.
    /// </summary>
    public Vector2 ConvertPositionToTarget(Vector2 localLayoutPos, SLayout targetLayout)
    {
        if (originTopLeft)
        {
            localLayoutPos.y = height - localLayoutPos.y;
        }

        var localPos        = localLayoutPos - GetPivotPos(rectTransform);
        var worldSpacePoint = rectTransform.TransformPoint(localPos);

        RectTransform targetRectTransform = targetLayout ? targetLayout.rectTransform : null;

        if (targetRectTransform == null)
        {
            targetRectTransform = canvas.transform as RectTransform;
        }

        var targetLocalPos  = (Vector2)targetRectTransform.InverseTransformPoint(worldSpacePoint);
        var targetLayoutPos = targetLocalPos + GetPivotPos(targetRectTransform);

        if (targetLayout != null && targetLayout.originTopLeft)
        {
            targetLayoutPos.y = targetLayout.height - targetLayoutPos.y;
        }

        return(targetLayoutPos);
    }
Exemple #2
0
 public void CancelAnimations(SLayout target)
 {
     _animations.RemoveAll(anim => {
         if (anim.owner == target)
         {
             anim.Cancel();
             return(true);
         }
         return(false);
     });
 }
Exemple #3
0
 public bool IsAnimating(SLayout target)
 {
     foreach (var a in _animations)
     {
         if (a.owner == target)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
    void CreateWords()
    {
        var words = paragraphText.Split(' ');

        _wordLayouts = words.Select(word => {
            SLayout wordLayout = Instantiate(wordPrefab);
            wordLayout.transform.SetParent(transform, worldPositionStays: false);
            wordLayout.text.text = word;
            wordLayout.width     = wordLayout.text.preferredWidth;
            return(wordLayout);
        }).ToArray();
    }
Exemple #5
0
    public void CompleteAnimations(SLayout target)
    {
        foreach (var anim in _animations)
        {
            if (anim.owner != target)
            {
                continue;
            }

            anim.CompleteImmediate();
        }
    }
Exemple #6
0
    /// <summary>
    /// Converts a rect in local space of this SLayout to the local space of another SLayout.
    /// If you pass a null SLayout, it will get the rect in the space of the canvas.
    /// </summary>
    public Rect ConvertRectToTarget(Rect localRect, SLayout targetLayout)
    {
        var convertedMin = ConvertPositionToTarget(localRect.min, targetLayout);
        var convertedMax = ConvertPositionToTarget(localRect.max, targetLayout);

        // Coordinate system may be flipped compared between SLayouts
        // (or if converting to canvas space)
        return(new Rect(
                   convertedMin.x,
                   Mathf.Min(convertedMin.y, convertedMax.y),
                   convertedMax.x - convertedMin.x,
                   Mathf.Abs(convertedMin.y - convertedMax.y)
                   ));
    }
    public SLayoutAnimation(float duration, float delay, Action animAction, Action completionAction, AnimationCurve customCurve, SLayout owner)
    {
        if (_animationsBeingDefined == null)
        {
            _animationsBeingDefined = new List <SLayoutAnimation>();
        }

        _animationsBeingDefined.Add(this);

        _time             = 0.0f;
        _duration         = _maxDuration = duration;
        _delay            = _maxDelay = delay;
        _completionAction = completionAction;
        _customCurve      = customCurve;
        _owner            = owner;

        // animAction == null when using the After method, for example
        if (animAction != null)
        {
            _properties = new List <SAnimatedProperty>();

            animAction();

            // Rewind animation back to beginning
            // But only if our duration > 0
            if (!isInstant)
            {
                foreach (var property in _properties)
                {
                    property.Start();
                }
            }
        }

        // Duration = zero? Done already
        if (isInstant)
        {
            Done();
        }

        _animationsBeingDefined.RemoveAt(_animationsBeingDefined.Count - 1);
    }
Exemple #8
0
    public void Animate(float duration, float delay, AnimationCurve customCurve, Action animAction, Action completeAction, SLayout owner)
    {
        // The constructor runs the animAction
        var newAnim = new SLayoutAnimation(duration, delay, animAction, completeAction, customCurve, owner);

        if (!newAnim.isComplete)
        {
            _animations.Add(newAnim);
        }
    }