Example #1
0
 private void HandlePatternChange(object sender, EventArgs e)
 {
     _bounds = _lineCircle.GetMaxPossibleBounds();
     SetFromBounds(_bounds, true);
 }
        public void Update()
        {
            _currentBounds = _lineCircle.GetBounds();
            _maxBounds     = _lineCircle.GetMaxPossibleBounds();
            _bounds        = UseCurrentBounds ? _currentBounds : _maxBounds;

            var longestSide = Mathf.Max(_bounds.size.x, Mathf.Max(_bounds.size.y, _bounds.size.z));

            if (longestSide > 0f)
            {
                TargetScale = (0.8f * 0.78539816f * TargetFillSize / longestSide);
            }
            else
            {
                TargetScale = 0f;
            }
            if (float.IsNaN(TargetScale))
            {
                TargetScale = 0f;
            }

            var centerPoint = _bounds.center;

            centerPoint.Scale(Vector3.one * TargetScale);
            TargetPosition  = -centerPoint;
            TargetPosition += CenterPosition;
            if (float.IsNaN(TargetPosition.x) || float.IsNaN(TargetPosition.y) || float.IsNaN(TargetPosition.z))
            {
                TargetPosition = Vector3.zero;
            }

            var currentScale = Scale;

            _scaleVelocity += (TargetScale - currentScale) * ScaleAcceleration * Time.deltaTime;
            if (Mathf.Abs(_scaleVelocity) > ScaleMaxVelocity)
            {
                _scaleVelocity = Mathf.Sign(_scaleVelocity) * ScaleMaxVelocity;
            }

            if (Mathf.Abs(_scaleVelocity) > 0f)
            {
                var scaleArriveTime = (TargetScale - currentScale) / _scaleVelocity;
                _scaleVelocity *= Mathf.Clamp01(scaleArriveTime / ScaleSlowdownTime);

                Scale += _scaleVelocity * Time.deltaTime;
                transform.localScale = Vector3.one * Mathf.Lerp(1f, Scale, ActiveLevel);
            }

            var currentPosition = Position;

            _positionVelocity += (TargetPosition - currentPosition) * PositionAcceleration * Time.deltaTime;
            if (_positionVelocity.sqrMagnitude > PositionMaxVelocity * PositionMaxVelocity)
            {
                _positionVelocity = _positionVelocity.normalized * PositionMaxVelocity;
            }

            if (_positionVelocity.sqrMagnitude > 0f)
            {
                var positionArriveTime = (TargetPosition - currentPosition).magnitude / _positionVelocity.magnitude;
                _positionVelocity *= Mathf.Clamp01(positionArriveTime / PositionSlowdownTime);

                Position += _positionVelocity * Time.deltaTime;
                transform.localPosition = Vector3.Lerp(CenterPosition, Position, ActiveLevel);
            }

            if (VisualizeBounds)
            {
                DrawDebugBounds();
            }
        }