protected virtual void Update()
        {
            if (thruster != null)
            {
                if (Application.isPlaying == true)
                {
                    flickerOffset += flickerSpeed * Time.deltaTime;
                }

                if (points == null)
                {
                    points = new float[128];

                    for (var i = points.Length - 1; i >= 0; i--)
                    {
                        points[i] = Random.value;
                    }
                }

                var noise  = Mathf.Repeat(flickerOffset, points.Length);
                var index  = (int)noise;
                var frac   = noise % 1.0f;
                var pointA = points[index];
                var pointB = points[(index + 1) % points.Length];
                var pointC = points[(index + 2) % points.Length];
                var pointD = points[(index + 3) % points.Length];
                var f      = 1.0f - SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * flicker;
                var factor = SgtHelper.DampenFactor(damping, Time.deltaTime);

                throttle = Mathf.Lerp(throttle, thruster.Throttle, factor);

                transform.localScale = baseScale + throttleScale * throttle * f;
            }
        }
Beispiel #2
0
        protected virtual void Update()
        {
            for (var i = 0; i < 9; i++)
            {
                if (Input.GetKeyDown(KeyCode.F1 + i) == true)
                {
                    GoToState(i);
                }
            }

            if (States != null && Target >= 0 && Target < States.Count)
            {
                var state  = States[Target];
                var tgtPos = state.Position;
                var tgtRot = Quaternion.Euler(state.Rotation);
                var factor = SgtHelper.DampenFactor(Dampening, Time.deltaTime);

                transform.position = Vector3.Lerp(transform.position, tgtPos, factor);
                transform.rotation = Quaternion.Slerp(transform.rotation, tgtRot, factor);

                if (Vector3.Distance(transform.position, tgtPos) <= ThresholdPosition && Quaternion.Angle(transform.rotation, tgtRot) < ThresholdRotation)
                {
                    Target = -1;
                }
            }
        }
        protected virtual void LateUpdate()
        {
            inputManager.Update();

            foreach (var finger in inputManager.Fingers)
            {
                if (finger.Down == true)
                {
                    Pick(finger.Position);
                }
            }

            var targetAlpha = 0.0f;

            if (FloatingCamera != null && WorldCamera != null)
            {
                if (CurrentTarget != null)
                {
                    var localPosition = FloatingCamera.CalculatePosition(ref CurrentTarget.CachedPoint.Position);
                    var screenPoint   = WorldCamera.WorldToScreenPoint(localPosition);

                    if (screenPoint.z >= 0.0f)
                    {
                        var anchoredPosition = default(Vector2);

                        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(Parent, screenPoint, null, out anchoredPosition) == true)
                        {
                            Rect.anchoredPosition = anchoredPosition;
                        }

                        targetAlpha = 1.0f;

                        if (HideIfTooClose == true)
                        {
                            if (SgtPosition.SqrDistance(ref SgtFloatingCamera.Instances.First.Value.Position, ref CurrentTarget.CachedPoint.Position) <= CurrentTarget.WarpDistance * CurrentTarget.WarpDistance)
                            {
                                targetAlpha = 0.0f;
                            }
                        }
                    }
                    else
                    {
                        Alpha = 0.0f;
                    }

                    Title.text = CurrentTarget.WarpName;
                }
            }

            var factor = SgtHelper.DampenFactor(10.0f, Time.deltaTime);

            Alpha = Mathf.Lerp(Alpha, targetAlpha, factor);

            Group.alpha          = Alpha;
            Group.blocksRaycasts = targetAlpha > 0.0f;
        }
Beispiel #4
0
        private void DampenDelta()
        {
            // Dampen remaining delta
            var factor   = SgtHelper.DampenFactor(Dampening, Time.deltaTime);
            var newDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);

            // Translate by difference
            transform.localPosition += remainingDelta - newDelta;

            // Update remaining
            remainingDelta = newDelta;
        }
Beispiel #5
0
        private void DampenDelta()
        {
            // Dampen remaining delta
            var factor   = SgtHelper.DampenFactor(damping, Time.deltaTime);
            var newDelta = Quaternion.Slerp(remainingDelta, Quaternion.identity, factor);

            // Rotate by difference
            transform.localRotation = transform.localRotation * Quaternion.Inverse(newDelta) * remainingDelta;

            // Update remaining
            remainingDelta = newDelta;
        }
Beispiel #6
0
        protected virtual void Update()
        {
            if (clonedMaterial != null)
            {
                var factor = SgtHelper.DampenFactor(Dampening, Time.deltaTime);
                var level  = clonedMaterial.GetFloat(SgtShader._WaterLevel);

                level = Mathf.Lerp(level, targetWaterLevel, factor);

                clonedMaterial.SetFloat(SgtShader._WaterLevel, level);
            }
        }
Beispiel #7
0
        private void AddToDelta()
        {
            // Get delta from binds
            var delta = default(Vector3);

            delta.x = bindHorizontal.GetValue(fingers);
            delta.y = bindVertical.GetValue(fingers);
            delta.z = bindDepth.GetValue(fingers);

            // Store old position
            var oldPosition = transform.position;

            // Translate
            transform.Translate(delta * GetSpeedMultiplier() * Time.deltaTime, Space.Self);

            // Add to remaining
            var acceleration = transform.position - oldPosition;

            remainingDelta += acceleration;

            // Revert position
            transform.position = oldPosition;

            // Rotate to acceleration?
            if (target != null && targetRotation != RotationType.None && delta != Vector3.zero)
            {
                var factor   = SgtHelper.DampenFactor(targetDamping, Time.deltaTime);
                var rotation = target.transform.rotation;

                switch (targetRotation)
                {
                case RotationType.Acceleration:
                {
                    rotation = Quaternion.LookRotation(acceleration, target.transform.up);
                }
                break;

                case RotationType.MainCamera:
                {
                    var camera = Camera.main;

                    if (camera != null)
                    {
                        rotation = camera.transform.rotation;
                    }
                }
                break;
                }

                target.transform.rotation = Quaternion.Slerp(target.transform.rotation, rotation, factor);
                target.angularVelocity    = Vector3.Lerp(target.angularVelocity, Vector3.zero, factor);
            }
        }
        public void UpdatePosition()
        {
            if (Target != null)
            {
                var targetPosition = Target.TransformPoint(LocalPosition);
                var factor         = SgtHelper.DampenFactor(Dampening, Time.deltaTime);

                transform.position = Vector3.Lerp(transform.position, targetPosition, factor);

                if (Rotate == true)
                {
                    var targetRotation = Target.rotation * Quaternion.Euler(LocalRotation);

                    transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, factor);
                }
            }
        }
        protected virtual void LateUpdate()
        {
            var targetAlpha = 0.0f;

            if (floatingCamera != null && worldCamera != null)
            {
                if (currentTarget != null)
                {
                    var localPosition = floatingCamera.CalculatePosition(currentTarget.CachedPoint.Position);
                    var screenPoint   = worldCamera.WorldToScreenPoint(localPosition);

                    if (screenPoint.z >= 0.0f)
                    {
                        var anchoredPosition = default(Vector2);

                        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPoint, null, out anchoredPosition) == true)
                        {
                            rect.anchoredPosition = anchoredPosition;
                        }

                        targetAlpha = 1.0f;

                        if (hideIfTooClose == true)
                        {
                            if (SgtPosition.SqrDistance(SgtFloatingCamera.Instances.First.Value.Position, currentTarget.CachedPoint.Position) <= currentTarget.WarpDistance * currentTarget.WarpDistance)
                            {
                                targetAlpha = 0.0f;
                            }
                        }
                    }
                    else
                    {
                        alpha = 0.0f;
                    }

                    title.text = currentTarget.WarpName;
                }
            }

            var factor = SgtHelper.DampenFactor(10.0f, Time.deltaTime);

            alpha = Mathf.Lerp(alpha, targetAlpha, factor);

            group.alpha          = alpha;
            group.blocksRaycasts = targetAlpha > 0.0f;
        }
Beispiel #10
0
        protected virtual void Update()
        {
            if (target != null)
            {
                var currentPosition = cachedPoint.Position;
                var targetPosition  = target.Position + localPosition;
                var factor          = SgtHelper.DampenFactor(Dampening, Time.deltaTime);

                cachedPoint.SetPosition(SgtPosition.Lerp(ref currentPosition, ref targetPosition, factor));

                if (Rotate == true)
                {
                    var targetRotation = target.transform.rotation * Quaternion.Euler(LocalRotation);

                    transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, factor);
                }
            }
        }
Beispiel #11
0
        private void DampenDelta()
        {
            // Dampen remaining delta
            var factor   = SgtHelper.DampenFactor(Dampening, Time.deltaTime);
            var newDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);

            // Translate by difference
            if (Target != null)
            {
                Target.velocity += remainingDelta - newDelta;
            }
            else
            {
                transform.position += remainingDelta - newDelta;
            }

            // Update remaining
            remainingDelta = newDelta;
        }
        protected virtual void Update()
        {
            if (Target == null)
            {
                ClearDebris(); return;
            }

            var followerDensity = GetFollowerDensity();

            if (followerDensity > 0.0f)
            {
                var debrisCount = Debris != null ? Debris.Count : 0;

                if (debrisCount < SpawnLimit)
                {
                    spawnCooldown -= Time.deltaTime;

                    while (spawnCooldown <= 0.0f)
                    {
                        spawnCooldown += Random.Range(SpawnRateMin, SpawnRateMax);

                        SpawnDebris(false);

                        debrisCount += 1;

                        if (debrisCount >= SpawnLimit)
                        {
                            break;
                        }
                    }
                }
            }

            followerPosition = Target.position;

            if (Debris != null)
            {
                var distanceRange = HideDistance - ShowDistance;

                for (var i = Debris.Count - 1; i >= 0; i--)
                {
                    var debris = Debris[i];

                    if (debris != null)
                    {
                        var targetScale = default(float);
                        var distance    = Vector3.Distance(followerPosition, debris.transform.position);

                        // Fade its size in
                        var factor = SgtHelper.DampenFactor(ShowSpeed, Time.deltaTime, 0.1f);

                        debris.Show = Mathf.Lerp(debris.Show, 1.0f, factor);

                        if (distance < ShowDistance)
                        {
                            targetScale = 1.0f;
                        }
                        else if (distance > HideDistance)
                        {
                            targetScale = 0.0f;
                        }
                        else
                        {
                            targetScale = 1.0f - SgtHelper.Divide(distance - ShowDistance, distanceRange);
                        }

                        debris.transform.localScale = debris.Scale * debris.Show * Mathf.Max(minScale, targetScale);

                        if (targetScale <= 0.0f)
                        {
                            Despawn(debris, i);
                        }
                    }
                    else
                    {
                        Debris.RemoveAt(i);
                    }
                }
            }
        }
Beispiel #13
0
        private void AddToDelta()
        {
            // Get delta from fingers
            var fingers = SgtInputManager.GetFingers(true);
            var deltaXY = SgtInputManager.GetScaledDelta(fingers) * PanSensitivity;
            var deltaZ  = (SgtInputManager.GetPinchScale(fingers, WheelSensitivity) - 1.0f) * PinchSensitivity;

            if (fingers.Count < 2)
            {
                deltaXY = Vector2.zero;
            }

            // Add delta from keyboard
            deltaXY.x += Input.GetAxisRaw("Horizontal") * KeySensitivity * Time.deltaTime;
            deltaZ    += Input.GetAxisRaw("Vertical") * KeySensitivity * Time.deltaTime;

            if (SlowOnProximity == true)
            {
                var distance = float.PositiveInfinity;

                if (SgtHelper.OnCalculateDistance != null)
                {
                    SgtHelper.OnCalculateDistance(transform.position, ref distance);
                }

                if (distance < SlowDistanceMax)
                {
                    var distance01 = Mathf.InverseLerp(SlowDistanceMin, SlowDistanceMax, distance);
                    var multiplier = Mathf.Lerp(SlowMultiplier, 1.0f, distance01);

                    deltaXY *= multiplier;
                    deltaZ  *= multiplier;
                }
            }

            // Store old position
            var oldPosition = transform.position;

            // Translate
            transform.Translate(deltaXY.x, deltaXY.y, deltaZ, Space.Self);

            // Add to remaining
            var acceleration = transform.position - oldPosition;

            remainingDelta += acceleration;

            // Revert position
            transform.position = oldPosition;

            // Rotate to acceleration?
            if (Target != null && TargetRotation != RotationType.None && acceleration != Vector3.zero)
            {
                var factor   = SgtHelper.DampenFactor(TargetDampening, Time.deltaTime);
                var rotation = Target.transform.rotation;

                switch (TargetRotation)
                {
                case RotationType.Acceleration:
                {
                    rotation = Quaternion.FromToRotation(Target.transform.forward, acceleration);
                }
                break;

                case RotationType.MainCamera:
                {
                    var camera = Camera.main;

                    if (camera != null)
                    {
                        rotation = camera.transform.rotation;
                    }
                }
                break;
                }

                Target.transform.rotation = Quaternion.Slerp(Target.transform.rotation, rotation, factor);
                Target.angularVelocity    = Vector3.Lerp(Target.angularVelocity, Vector3.zero, factor);
            }
        }