Ejemplo n.º 1
0
        private IEnumerator AnimateSettingsChange(CurvedUISettings target, float time)
        {
            var t        = 0f;
            var original = currentCurveSettings.Clone() as CurvedUISettings;

            // Creating a new copy so that the current settings (if they happen to be a scriptable object) aren't overwritten.
            SetCurveSettingsInstant(original.Clone() as CurvedUISettings);

            var cachedCurve  = Vector3.zero;
            var cachedPull   = Vector3.zero;
            var cachedScale  = Vector3.zero;
            var cachedOffset = Vector3.zero;

            while (t < 1)
            {
                var animatedT = curveTransition.Evaluate(t);

                LerpVectorsIntoResult(ref cachedCurve, original.Curve, target.Curve, animatedT);
                LerpVectorsIntoResult(ref cachedPull, original.Pull, target.Pull, animatedT);
                LerpVectorsIntoResult(ref cachedScale, original.Scale, target.Scale, animatedT);
                LerpVectorsIntoResult(ref cachedOffset, original.Offset, target.Offset, animatedT);

                currentCurveSettings.Set(cachedCurve, cachedPull, cachedScale, cachedOffset);

                t += Time.deltaTime / time;
                yield return(new WaitForEndOfFrame());
            }

            SetCurveSettingsInstant(target.Clone() as CurvedUISettings);
        }
Ejemplo n.º 2
0
        private void OnEnable()
        {
            currentCurveSettings = CurrentCurveSettings;

            currentCurveSettings.SettingsChanged += CurrentCurveSettings_PropertyChanged;
            CurveSettingsChangedEvent?.Invoke();
        }
Ejemplo n.º 3
0
 public void SetCurveSettingsInstant(CurvedUISettings newSettings)
 {
     currentCurveSettings.SettingsChanged -= CurrentCurveSettings_PropertyChanged;
     currentCurveSettings = newSettings;
     currentCurveSettings.SettingsChanged += CurrentCurveSettings_PropertyChanged;
     CurveSettingsChangedEvent?.Invoke();
 }
        private void OnEnable()
        {
            currentCurveSettings = CurrentCurveSettings;
            currentCurveSettings.RefreshBooleans();

            currentCurveSettings.PropertyChanged += CurrentCurveSettings_PropertyChanged;
            CurveSettingsChangedEvent?.Invoke();
        }
Ejemplo n.º 5
0
        public void SetCurveSettings(CurvedUISettings newSettings, float transitionTime = 1f)
        {
            StopAllCoroutines();

            if (transitionTime <= 0)
            {
                SetCurveSettingsInstant(newSettings);
                return;
            }

            StartCoroutine(AnimateSettingsChange(newSettings, transitionTime));
        }
Ejemplo n.º 6
0
 private void OnValidate()
 {
     if (currentCurveSettings != CurrentCurveSettings)
     {
         if (currentCurveSettings != null)
         {
             currentCurveSettings.SettingsChanged -= CurrentCurveSettings_PropertyChanged;
         }
         currentCurveSettings = CurrentCurveSettings;
         currentCurveSettings.SettingsChanged += CurrentCurveSettings_PropertyChanged;
     }
     CurveSettingsChangedEvent?.Invoke();
 }
Ejemplo n.º 7
0
        public void ModifyCurvedPosition(ref Vector3 screenSpace, CurvedUISettings settings)
        {
            var xDist = DistanceFromCenter(screenSpace.y, cachedCanvasSize.y / 2);
            var yDist = DistanceFromCenter(screenSpace.x, cachedCanvasSize.x / 2);

            // Curve
            screenSpace.x -= screenSpace.x * xDist * settings.Curve.x;
            screenSpace.y -= screenSpace.y * yDist * settings.Curve.y;

            // Pull
            screenSpace.x += xDist * settings.Pull.x;
            screenSpace.y += yDist * settings.Pull.y;

            // Scale
            screenSpace.x *= settings.Scale.x;
            screenSpace.y *= settings.Scale.y;

            // Offset
            screenSpace.x += settings.Offset.x * cachedCanvasSize.x;
            screenSpace.y += settings.Offset.y * cachedCanvasSize.y;
        }
        public void ModifyCurvedPosition(ref Vector3 screenSpace, CurvedUISettings settings)
        {
            var xDist = DistanceFromCenter(screenSpace.y, cachedCanvasSize.y / 2);
            var yDist = DistanceFromCenter(screenSpace.x, cachedCanvasSize.x / 2);

            if (settings.UsingCurve)
            {
                var curve = settings.Curve;
                screenSpace.Set(
                    screenSpace.x + (0 - screenSpace.x) * xDist * curve.x,
                    screenSpace.y + (0 - screenSpace.y) * yDist * curve.y,
                    screenSpace.z
                    );
            }

            if (settings.UsingPull)
            {
                var pull = settings.Pull;
                screenSpace.Set(
                    screenSpace.x + (xDist * pull.x),
                    screenSpace.y + (yDist * pull.y),
                    screenSpace.z
                    );
            }

            if (settings.UsingScale)
            {
                MultiplyVectorValues(ref screenSpace, settings.Scale);
            }

            if (settings.UsingOffset)
            {
                MultiplyVectorValuesIntoResult(ref screenSizeOffset, settings.Offset, cachedCanvasSize);
                AddVectorValues(ref screenSpace, screenSizeOffset);
            }
        }
        // We're saving a bunch of implicit Vector2 conversions by having everything as a Vector3
        public Vector3 GetCurvedPosition(Vector3 position, Matrix4x4 localToCanvas, Matrix4x4 canvasToLocal, CurvedUISettings settings)
        {
            var screenSpace = localToCanvas.MultiplyPoint(position);

            ModifyCurvedPosition(ref screenSpace, settings);

            return(canvasToLocal.MultiplyPoint(screenSpace));
        }