private void FloatingCameraSnap(SgtFloatingCamera floatingCamera, Vector3 delta)
        {
            var position = transform.position + delta;
            var extent   = Size * SgtHelper.UniformScale(transform.lossyScale);

            position.x = position.x % extent.x;
            position.y = position.y % extent.y;
            position.z = position.z % extent.z;

            transform.position = position;
        }
        protected override void UpdatePositionNow(SgtFloatingCamera floatingCamera)
        {
            if (cachedRigidbody == null)
            {
                cachedRigidbody = GetComponent <Rigidbody>();
            }

            expectedPosition = floatingCamera.CalculatePosition(position);

            cachedRigidbody.position = expectedPosition;

            transform.position = expectedPosition;

            expectedPositionSet = true;
        }
        private void FloatingCameraSnap(SgtFloatingCamera floatingCamera, Vector3 delta)
        {
            // Make sure the right camera snapped
            if (floatingCamera.IsRendering(gameObject.layer) == true)
            {
                var position = transform.position + delta;
                var extent   = Size * SgtHelper.UniformScale(transform.lossyScale);

                position.x = position.x % extent.x;
                position.y = position.y % extent.y;
                position.z = position.z % extent.z;

                transform.position = position;
            }
        }
Exemple #4
0
        public void DerivePosition()
        {
            var floatingCamera = default(SgtFloatingCamera);

            expectedPosition = transform.position;

            if (SgtFloatingCamera.TryGetInstance(ref floatingCamera) == true && floatingCamera.SnappedPointSet == true)
            {
                SetPosition(floatingCamera.SnappedPoint + expectedPosition);
            }
            else
            {
                SetPosition(new SgtPosition(expectedPosition));
            }

            positionSet = true;
        }
        protected virtual void LateUpdate()
        {
            var floatingCamera = default(SgtFloatingCamera);
            var targetAlpha    = 0.0f;

            if (SgtFloatingCamera.TryGetCamera(1, ref floatingCamera) == true)
            {
                if (CurrentTarget != null)
                {
                    var localPosition = floatingCamera.CalculatePosition(ref CurrentTarget.CachedPoint.Position);
                    var screenPoint   = floatingCamera.CachedCamera.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 SgtFloatingOrigin.CurrentPoint.Position, ref CurrentTarget.CachedPoint.Position) <= CurrentTarget.WarpDistance * CurrentTarget.WarpDistance)
                            {
                                targetAlpha = 0.0f;
                            }
                        }
                    }
                    else
                    {
                        Alpha = 0.0f;
                    }

                    Title.text = CurrentTarget.WarpName;
                }
            }

            Alpha = SgtHelper.Dampen(Alpha, targetAlpha, 10.0f, Time.deltaTime);

            Group.alpha          = Alpha;
            Group.blocksRaycasts = targetAlpha > 0.0f;
        }
        public void Pick(Vector2 pickScreenPoint)
        {
            var floatingCamera = default(SgtFloatingCamera);

            if (SgtFloatingCamera.TryGetCamera(1, ref floatingCamera) == true)
            {
                var warpTarget   = SgtFloatingTarget.FirstInstance;
                var bestTarget   = default(SgtFloatingTarget);
                var bestDistance = float.PositiveInfinity;

                for (var i = 0; i < SgtFloatingTarget.InstanceCount; i++)
                {
                    var localPosition = floatingCamera.CalculatePosition(ref warpTarget.CachedPoint.Position);
                    var screenPoint   = floatingCamera.CachedCamera.WorldToScreenPoint(localPosition);

                    if (screenPoint.z >= 0.0f)
                    {
                        var distance = ((Vector2)screenPoint - pickScreenPoint).sqrMagnitude;

                        if (distance <= bestDistance)
                        {
                            bestDistance = distance;
                            bestTarget   = warpTarget;
                        }
                    }

                    warpTarget = warpTarget.NextInstance;
                }

                if (bestTarget != null)
                {
                    var pickThreshold = Mathf.Min(Screen.width, Screen.height) * PickDistance;

                    if (bestDistance <= pickThreshold * pickThreshold)
                    {
                        CurrentTarget = bestTarget;
                    }
                }
                else
                {
                    CurrentTarget = null;
                }
            }
        }
Exemple #7
0
        private void CameraSnap(SgtFloatingCamera floatingCamera, Vector3 delta)
        {
            // Make sure the right camera snapped
            if (floatingCamera.IsRendering(gameObject.layer) == true)
            {
                // Use universal positioning?
                if (point != null)
                {
                    CheckForPositionChanges();
                    UpdatePositionNow(floatingCamera);
                }
                // Use basic shifting?
                else
                {
                    transform.position += delta;
                }

                if (OnSnap != null)
                {
                    OnSnap.Invoke();
                }
            }
        }
Exemple #8
0
        private void HandleCameraDraw(Camera camera)
        {
            if (SgtHelper.CanDraw(gameObject, camera) == false)
            {
                return;
            }

            if (orbit != null)
            {
                var floatingCamera = default(SgtFloatingCamera);

                if (SgtFloatingCamera.TryGetInstance(ref floatingCamera) == true)
                {
                    if (visualMesh == null)
                    {
                        visualMesh = SgtHelper.CreateTempMesh("Orbit Visual");
                    }

                    meshPositions.Clear();
                    meshCoords.Clear();
                    meshColors.Clear();
                    meshIndices.Clear();

                    var position = floatingCamera.CalculatePosition(orbit.ParentPoint.Position);
                    var rotation = orbit.ParentPoint.transform.rotation * Quaternion.Euler(orbit.Tilt);
                    var r1       = orbit.Radius;
                    var r2       = orbit.Radius * (1.0f - orbit.Oblateness);
                    var i1       = r1 - thickness * 0.5;
                    var i2       = r2 - thickness * 0.5;
                    var o1       = i1 + thickness;
                    var o2       = i2 + thickness;
                    var step     = 360.0 / points;
                    var stepI    = 1.0f / (points - 1);

                    for (var i = 0; i < points; i++)
                    {
                        var angle = (orbit.Angle - i * step) * Mathf.Deg2Rad;
                        var sin   = System.Math.Sin(angle);
                        var cos   = System.Math.Cos(angle);

                        // Inner
                        {
                            var point   = position;
                            var offsetX = orbit.Offset.x + sin * i1;
                            var offsetY = orbit.Offset.y + 0.0;
                            var offsetZ = orbit.Offset.z + cos * i2;

                            SgtFloatingOrbit.Rotate(rotation, ref offsetX, ref offsetY, ref offsetZ);

                            point.x += (float)offsetX;
                            point.y += (float)offsetY;
                            point.z += (float)offsetZ;

                            point = transform.InverseTransformPoint(point);

                            meshPositions.Add(point);
                        }

                        // Outer
                        {
                            var point   = position;
                            var offsetX = orbit.Offset.x + sin * o1;
                            var offsetY = orbit.Offset.y + 0.0;
                            var offsetZ = orbit.Offset.z + cos * o2;

                            SgtFloatingOrbit.Rotate(rotation, ref offsetX, ref offsetY, ref offsetZ);

                            point.x += (float)offsetX;
                            point.y += (float)offsetY;
                            point.z += (float)offsetZ;

                            point = transform.InverseTransformPoint(point);

                            meshPositions.Add(point);
                        }

                        var u     = stepI * i;
                        var color = colors.Evaluate(u);

                        meshCoords.Add(new Vector2(u, 0.0f));
                        meshCoords.Add(new Vector2(u, 1.0f));

                        meshColors.Add(color);
                        meshColors.Add(color);
                    }

                    for (var i = 0; i < points; i++)
                    {
                        var indexA = i * 2 + 0;
                        var indexB = i * 2 + 1;
                        var indexC = i * 2 + 2; indexC %= points * 2;
                        var indexD = i * 2 + 3; indexD %= points * 2;

                        meshIndices.Add(indexA);
                        meshIndices.Add(indexB);
                        meshIndices.Add(indexC);
                        meshIndices.Add(indexD);
                        meshIndices.Add(indexC);
                        meshIndices.Add(indexB);
                    }

                    visualMesh.SetVertices(meshPositions);
                    visualMesh.SetTriangles(meshIndices, 0);
                    visualMesh.SetUVs(0, meshCoords);
                    visualMesh.SetColors(meshColors);
                    visualMesh.RecalculateBounds();
                }

                if (visualMesh != null)
                {
                    Graphics.DrawMesh(visualMesh, transform.localToWorldMatrix, material, gameObject.layer, camera);
                }
            }
        }
Exemple #9
0
        private void UpdatePositionNow(SgtFloatingCamera camera)
        {
            transform.position = expectedPosition = camera.CalculatePosition(ref point.Position);

            expectedPositionSet = true;
        }
Exemple #10
0
        private void FloatingCameraPositionChanged(SgtFloatingCamera floatingCamera)
        {
            var direction = SgtPosition.Direction(ref cachedObject.Point.Position, ref SgtFloatingOrigin.CurrentPoint.Position);

            transform.forward = direction;
        }
Exemple #11
0
 private void FloatingCameraPositionChanged(SgtFloatingCamera floatingCamera)
 {
     LateUpdate();
 }
 private void CameraSnapped(SgtFloatingCamera floatingCamera, Vector3 delta)
 {
     PositionChanged();
 }
Exemple #13
0
        public void Draw(SgtFloatingOrbit orbit)
        {
            if (cachedMeshFilterSet == false)
            {
                cachedMeshFilter    = GetComponent <MeshFilter>();
                cachedMeshFilterSet = true;
            }

            if (visualMesh == null)
            {
                visualMesh = cachedMeshFilter.sharedMesh = SgtHelper.CreateTempMesh("Orbit Visual");
            }

            positions.Clear();
            coords.Clear();
            colors.Clear();
            indices.Clear();

            var camera = default(SgtFloatingCamera);

            if (SgtFloatingCamera.TryGetCamera(gameObject.layer, ref camera) == true)
            {
                var position = camera.CalculatePosition(ref orbit.ParentPoint.Position);
                var rotation = orbit.ParentPoint.transform.rotation * Quaternion.Euler(orbit.Tilt);
                var r1       = orbit.Radius;
                var r2       = orbit.Radius * (1.0f - orbit.Oblateness);
                var i1       = r1 - Thickness * 0.5;
                var i2       = r2 - Thickness * 0.5;
                var o1       = i1 + Thickness;
                var o2       = i2 + Thickness;
                var step     = 360.0 / Points;
                var stepI    = 1.0f / (Points - 1);

                for (var i = 0; i < Points; i++)
                {
                    var angle = (orbit.Angle - i * step) * Mathf.Deg2Rad;
                    var sin   = System.Math.Sin(angle);
                    var cos   = System.Math.Cos(angle);

                    // Inner
                    {
                        var point   = position;
                        var offsetX = sin * i1;
                        var offsetY = 0.0;
                        var offsetZ = cos * i2;

                        SgtFloatingOrbit.Rotate(rotation, ref offsetX, ref offsetY, ref offsetZ);

                        point.x += (float)offsetX;
                        point.y += (float)offsetY;
                        point.z += (float)offsetZ;

                        point = transform.InverseTransformPoint(point);

                        positions.Add(point);
                    }

                    // Outer
                    {
                        var point   = position;
                        var offsetX = sin * o1;
                        var offsetY = 0.0;
                        var offsetZ = cos * o2;

                        SgtFloatingOrbit.Rotate(rotation, ref offsetX, ref offsetY, ref offsetZ);

                        point.x += (float)offsetX;
                        point.y += (float)offsetY;
                        point.z += (float)offsetZ;

                        point = transform.InverseTransformPoint(point);

                        positions.Add(point);
                    }

                    var u     = stepI * i;
                    var color = Colors.Evaluate(u);

                    coords.Add(new Vector2(u, 0.0f));
                    coords.Add(new Vector2(u, 1.0f));

                    colors.Add(color);
                    colors.Add(color);
                }

                for (var i = 0; i < Points; i++)
                {
                    var indexA = i * 2 + 0;
                    var indexB = i * 2 + 1;
                    var indexC = i * 2 + 2; indexC %= Points * 2;
                    var indexD = i * 2 + 3; indexD %= Points * 2;

                    indices.Add(indexA);
                    indices.Add(indexB);
                    indices.Add(indexC);
                    indices.Add(indexD);
                    indices.Add(indexC);
                    indices.Add(indexB);
                }

                visualMesh.SetVertices(positions);
                visualMesh.SetTriangles(indices, 0);
                visualMesh.SetUVs(0, coords);
                visualMesh.SetColors(colors);
                visualMesh.RecalculateBounds();
            }
        }
Exemple #14
0
 private void HandleSnap(SgtFloatingCamera floatingCamera, Vector3 delta)
 {
     CheckForPositionChanges();
     UpdatePositionNow(floatingCamera);
 }
Exemple #15
0
        protected virtual void UpdatePositionNow(SgtFloatingCamera floatingCamera)
        {
            transform.position = expectedPosition = floatingCamera.CalculatePosition(position);

            expectedPositionSet = true;
        }
 public void UpdatePosition(SgtFloatingCamera camera)
 {
     transform.position = expectedPosition = camera.CalculatePosition(ref Point.Position);
 }