コード例 #1
0
        public static SgtPosition Lerp(ref SgtPosition a, ref SgtPosition b, double t)
        {
            var o = default(SgtPosition);

            if (t > 0.5)
            {
                t = 1.0 - t;

                o.GlobalX = b.GlobalX;
                o.GlobalY = b.GlobalY;
                o.GlobalZ = b.GlobalZ;
                o.LocalX  = b.LocalX - ((b.GlobalX - a.GlobalX) * CELL_SIZE + b.LocalX - a.LocalX) * t;
                o.LocalY  = b.LocalY - ((b.GlobalY - a.GlobalY) * CELL_SIZE + b.LocalY - a.LocalY) * t;
                o.LocalZ  = b.LocalZ - ((b.GlobalZ - a.GlobalZ) * CELL_SIZE + b.LocalZ - a.LocalZ) * t;
            }
            else
            {
                o.GlobalX = a.GlobalX;
                o.GlobalY = a.GlobalY;
                o.GlobalZ = a.GlobalZ;
                o.LocalX  = a.LocalX + ((b.GlobalX - a.GlobalX) * CELL_SIZE + b.LocalX - a.LocalX) * t;
                o.LocalY  = a.LocalY + ((b.GlobalY - a.GlobalY) * CELL_SIZE + b.LocalY - a.LocalY) * t;
                o.LocalZ  = a.LocalZ + ((b.GlobalZ - a.GlobalZ) * CELL_SIZE + b.LocalZ - a.LocalZ) * t;
            }

            o.SnapLocal();

            return(o);
        }
コード例 #2
0
        protected SgtFloatingObject SpawnAt(SgtPosition position)
        {
            var index       = Random.Range(0, prefabs.Count);
            var prefab      = prefabs[index];
            var prefabPoint = prefab.Point;
            var oldSeed     = prefab.Seed;
            var oldPosition = prefabPoint.Position;

            prefab.Seed          = Random.Range(int.MinValue, int.MaxValue);
            prefabPoint.Position = position;

            var instance = Instantiate(prefab, SgtFloatingRoot.Root);

            prefab.Seed          = oldSeed;
            prefabPoint.Position = oldPosition;

            instances.Add(instance);

            if (instance.OnSpawn != null)
            {
                instance.OnSpawn(instance.Seed);
            }

            return(instance);
        }
コード例 #3
0
        protected virtual void Update()
        {
            if (Warping == true)
            {
                Progress += Time.deltaTime;

                if (Progress > WarpTime)
                {
                    Progress = WarpTime;
                }

                var bend = SmoothStep(Progress / WarpTime, Smoothness);

                if (Point != null)
                {
                    Point.Position = SgtPosition.Lerp(ref StartPosition, ref TargetPosition, bend);

                    Point.PositionChanged();
                }

                if (Progress >= WarpTime)
                {
                    Warping = false;
                }
            }
        }
コード例 #4
0
ファイル: SgtStarfieldInfinite.cs プロジェクト: dqchess/twin
        protected virtual void Update()
        {
            if (TetherPoint != null)
            {
                var position = TetherPoint.Position;
                var sizeX    = Size.x * TetherScale;
                var sizeY    = Size.y * TetherScale;
                var sizeZ    = Size.z * TetherScale;
                var delta    = SgtPosition.Delta(ref position, ref SgtFloatingOrigin.CurrentPoint.Position);
                var deltaX   = delta.GlobalX * SgtPosition.CellSize + delta.LocalX;
                var deltaY   = delta.GlobalX * SgtPosition.CellSize + delta.LocalY;
                var deltaZ   = delta.GlobalX * SgtPosition.CellSize + delta.LocalZ;
                var stepX    = System.Math.Round(deltaX / sizeX);
                var stepY    = System.Math.Round(deltaY / sizeY);
                var stepZ    = System.Math.Round(deltaZ / sizeZ);

                if (stepX != 0 || stepY != 0 || stepZ != 0)
                {
                    position.LocalX -= stepX * sizeX;
                    position.LocalY -= stepY * sizeY;
                    position.LocalZ -= stepZ * sizeZ;
                    position.SnapLocal();

                    TetherPoint.Position = position;
                    TetherPoint.PositionChanged();
                }
            }
        }
コード例 #5
0
 public override void WarpTo(SgtPosition position)
 {
     warping        = true;
     progress       = 0.0;
     startPosition  = point.Position;
     targetPosition = position;
 }
コード例 #6
0
        protected SgtFloatingObject SpawnAt(SgtPosition position)
        {
            if (prefabs.Count > 0)
            {
                var index  = Random.Range(0, prefabs.Count);
                var prefab = prefabs[index];

                if (prefab != null)
                {
                    var oldSeed        = prefab.Seed;
                    var oldPosition    = prefab.Position;
                    var oldPositionSet = prefab.PositionSet;

                    prefab.Seed        = Random.Range(int.MinValue, int.MaxValue);
                    prefab.Position    = position;
                    prefab.PositionSet = true;

                    var instance = Instantiate(prefab, SgtFloatingRoot.Root);

                    prefab.Seed        = oldSeed;
                    prefab.Position    = oldPosition;
                    prefab.PositionSet = oldPositionSet;

                    instances.Add(instance);

                    instance.InvokeOnSpawn();

                    return(instance);
                }
            }

            return(null);
        }
コード例 #7
0
        public void Snap()
        {
            CheckForPositionChanges();

            snappedPoint    = position;
            snappedPointSet = true;

            snappedPoint.LocalX = System.Math.Floor(snappedPoint.LocalX);
            snappedPoint.LocalY = System.Math.Floor(snappedPoint.LocalY);
            snappedPoint.LocalZ = System.Math.Floor(snappedPoint.LocalZ);

            var oldPosition = transform.position;

            UpdatePositionNow();

            var newPosition = transform.position;
            var delta       = newPosition - oldPosition;

            if (OnSnap != null)
            {
                OnSnap(this, delta);
            }

            SgtHelper.InvokeSnap(delta);
        }
コード例 #8
0
 public override void WarpTo(SgtPosition position)
 {
     Warping        = true;
     Progress       = 0.0;
     StartPosition  = Point.Position;
     TargetPosition = position;
 }
コード例 #9
0
ファイル: SgtFloatingCamera.cs プロジェクト: dqchess/twin
        private void PreCull(Camera camera)
        {
            SgtFloatingOrigin.CurrentPoint.Position.SnapLocal();

            transform.position = CalculatePosition(ref SgtFloatingOrigin.CurrentPoint.Position);

            // Rotate to main camera?
            var mainCamera = Camera.main;

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

            // Snap scaled camera position?
            var position = transform.position;

            if (position.magnitude > SnapRadius)
            {
                SnappedPoint = SgtFloatingOrigin.CurrentPoint.Position;

                transform.position = expectedPosition = Vector3.zero;

                if (OnPositionChanged != null)
                {
                    OnPositionChanged(this);
                }
                if (LateOnPositionChanged != null)
                {
                    LateOnPositionChanged(this);
                }
            }
        }
コード例 #10
0
        protected SgtFloatingSpawnable SpawnAt(SgtPosition position)
        {
            if (prefabs.Count > 0)
            {
                var index  = Random.Range(0, prefabs.Count);
                var prefab = prefabs[index];

                if (prefab != null)
                {
                    var prefabObject = prefab.CachedObject;

                    // Universal position?
                    if (prefabObject.Point != null)
                    {
                        var oldSeed     = prefab.Seed;
                        var oldPosition = prefabObject.Point.Position;

                        prefab.Seed = Random.Range(int.MinValue, int.MaxValue);
                        prefabObject.Point.Position = position;

                        var instance = Instantiate(prefab, SgtFloatingRoot.Root);

                        prefab.Seed = oldSeed;
                        prefabObject.Point.Position = oldPosition;

                        instances.Add(instance);

                        instance.InvokeOnSpawn();

                        return(instance);
                    }
                    // Transform position?
                    else
                    {
                        var floatingCamera = default(SgtFloatingCamera);

                        if (SgtFloatingCamera.TryGetCamera(gameObject.layer, ref floatingCamera) == true)
                        {
                            var oldSeed = prefab.Seed;

                            prefab.Seed = Random.Range(int.MinValue, int.MaxValue);

                            var instance = Instantiate(prefab, SgtFloatingRoot.Root);

                            prefab.Seed = oldSeed;

                            instances.Add(instance);

                            instance.InvokeOnSpawn();

                            instance.transform.position = floatingCamera.CalculatePosition(ref position);

                            return(instance);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #11
0
        public static double SqrDistance(ref SgtPosition a, ref SgtPosition b)
        {
            var x = b.LocalX - a.LocalX + (b.GlobalX - a.GlobalX) * CellSize;
            var y = b.LocalY - a.LocalY + (b.GlobalY - a.GlobalY) * CellSize;
            var z = b.LocalZ - a.LocalZ + (b.GlobalZ - a.GlobalZ) * CellSize;

            return(x * x + y * y + z * z);
        }
コード例 #12
0
        /// <summary>This gives you the camera-relative position of the input SgtPosition in world space.</summary>
        public Vector3 CalculatePosition(ref SgtPosition input)
        {
            var x = (input.GlobalX - snappedPoint.GlobalX) * SgtPosition.CELL_SIZE + (input.LocalX - snappedPoint.LocalX);
            var y = (input.GlobalY - snappedPoint.GlobalY) * SgtPosition.CELL_SIZE + (input.LocalY - snappedPoint.LocalY);
            var z = (input.GlobalZ - snappedPoint.GlobalZ) * SgtPosition.CELL_SIZE + (input.LocalZ - snappedPoint.LocalZ);

            return(new Vector3((float)x, (float)y, (float)z));
        }
コード例 #13
0
        public static double Distance(ref SgtPosition a, ref SgtPosition b)
        {
            var x = (b.GlobalX - a.GlobalX) * CellSize + b.LocalX - a.LocalX;
            var y = (b.GlobalY - a.GlobalY) * CellSize + b.LocalY - a.LocalY;
            var z = (b.GlobalZ - a.GlobalZ) * CellSize + b.LocalZ - a.LocalZ;

            return(System.Math.Sqrt(x * x + y * y + z * z));
        }
コード例 #14
0
        // Get the world space vector between two positions
        public static Vector3 Vector(ref SgtPosition a, ref SgtPosition b)
        {
            var x = (b.GlobalX - a.GlobalX) * CellSize + b.LocalX - a.LocalX;
            var y = (b.GlobalY - a.GlobalY) * CellSize + b.LocalY - a.LocalY;
            var z = (b.GlobalZ - a.GlobalZ) * CellSize + b.LocalZ - a.LocalZ;

            return(new Vector3((float)x, (float)y, (float)z));
        }
コード例 #15
0
        public static double Distance(SgtPosition a, SgtPosition b)
        {
            var x = b.LocalX - a.LocalX + (b.GlobalX - a.GlobalX) * CellSize;
            var y = b.LocalY - a.LocalY + (b.GlobalY - a.GlobalY) * CellSize;
            var z = b.LocalZ - a.LocalZ + (b.GlobalZ - a.GlobalZ) * CellSize;

            return(System.Math.Sqrt(x * x + y * y + z * z));
        }
コード例 #16
0
        public static double SqrDistance(ref SgtPosition a, ref SgtPosition b)
        {
            var x = (b.GlobalX - a.GlobalX) * CELL_SIZE + b.LocalX - a.LocalX;
            var y = (b.GlobalY - a.GlobalY) * CELL_SIZE + b.LocalY - a.LocalY;
            var z = (b.GlobalZ - a.GlobalZ) * CELL_SIZE + b.LocalZ - a.LocalZ;

            return(x * x + y * y + z * z);
        }
コード例 #17
0
        /// <summary>This method allows you to change the whole <b>Position</b> state, and it will automatically call the <b>PositionChanged</b> method if the position is different.</summary>
        public void SetPosition(SgtPosition newPosition)
        {
            if (SgtPosition.Equal(ref newPosition, ref Position) == false)
            {
                Position = newPosition;

                PositionChanged();
            }
        }
コード例 #18
0
        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;
        }
コード例 #19
0
ファイル: SgtFloatingCamera.cs プロジェクト: dqchess/twin
        // Calculate the camera-relative position of an SgtPosition
        public Vector3 CalculatePosition(ref SgtPosition input)
        {
            var offsetX = (input.GlobalX - SnappedPoint.GlobalX) * SgtPosition.CellSize + (input.LocalX - SnappedPoint.LocalX);
            var offsetY = (input.GlobalY - SnappedPoint.GlobalY) * SgtPosition.CellSize + (input.LocalY - SnappedPoint.LocalY);
            var offsetZ = (input.GlobalZ - SnappedPoint.GlobalZ) * SgtPosition.CellSize + (input.LocalZ - SnappedPoint.LocalZ);
            var scaledX = offsetX / Scale;
            var scaledY = offsetY / Scale;
            var scaledZ = offsetZ / Scale;

            return(new Vector3((float)scaledX, (float)scaledY, (float)scaledZ));
        }
コード例 #20
0
        protected virtual void Update()
        {
            CheckForPositionChanges();

            if (OnDistance != null && SgtFloatingCamera.Instances.Count > 0)
            {
                var floatingCamera = SgtFloatingCamera.Instances.First.Value;
                var distance       = SgtPosition.Distance(position, floatingCamera.Position);

                OnDistance.Invoke(distance);
            }
        }
コード例 #21
0
        public static bool Equal(ref SgtPosition a, ref SgtPosition b)
        {
            if (a.GlobalX == b.GlobalX && a.GlobalY == b.GlobalY && a.GlobalZ == b.GlobalZ)
            {
                if (a.LocalX == b.LocalX && a.LocalY == b.LocalY && a.LocalZ == b.LocalZ)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #22
0
        /// <summary>Allows you to warp to the target point with the specified separation distance.</summary>
        public void WarpTo(SgtPosition position, double distance)
        {
            // Make sure we don't warp directly onto the star
            var direction = SgtPosition.Direction(ref Point.Position, ref position);

            position.LocalX -= direction.x * distance;
            position.LocalY -= direction.y * distance;
            position.LocalZ -= direction.z * distance;
            position.SnapLocal();

            WarpTo(position);
        }
コード例 #23
0
        public static SgtPosition Lerp(SgtPosition a, SgtPosition b, double t)
        {
            var o = a;

            o.LocalX += ((b.GlobalX - a.GlobalX) * CellSize + b.LocalX - a.LocalX) * t;
            o.LocalY += ((b.GlobalY - a.GlobalY) * CellSize + b.LocalY - a.LocalY) * t;
            o.LocalZ += ((b.GlobalZ - a.GlobalZ) * CellSize + b.LocalZ - a.LocalZ) * t;

            o.SnapLocal();

            return(o);
        }
コード例 #24
0
        public static SgtPosition Delta(ref SgtPosition a, ref SgtPosition b)
        {
            var o = default(SgtPosition);

            o.LocalX  = a.LocalX - b.LocalX;
            o.LocalY  = a.LocalY - b.LocalY;
            o.LocalZ  = a.LocalZ - b.LocalZ;
            o.GlobalX = a.GlobalX - b.GlobalX;
            o.GlobalY = a.GlobalY - b.GlobalY;
            o.GlobalZ = a.GlobalZ - b.GlobalZ;

            return(o);
        }
コード例 #25
0
        // Get the world space vector between two positions
        public static Vector3 Vector(SgtPosition a, SgtPosition b)
        {
            var ax = a.LocalX + a.GlobalX * CellSize;
            var ay = a.LocalY + a.GlobalY * CellSize;
            var az = a.LocalZ + a.GlobalZ * CellSize;
            var bx = b.LocalX + b.GlobalX * CellSize;
            var by = b.LocalY + b.GlobalY * CellSize;
            var bz = b.LocalZ + b.GlobalZ * CellSize;

            var x = bx - ax;
            var y = by - ay;
            var z = bz - az;

            return(new Vector3((float)x, (float)y, (float)z));
        }
コード例 #26
0
        public static Vector3 Direction(ref SgtPosition a, ref SgtPosition b)
        {
            var x = b.LocalX - a.LocalX + (b.GlobalX - a.GlobalX) * CellSize;
            var y = b.LocalY - a.LocalY + (b.GlobalY - a.GlobalY) * CellSize;
            var z = b.LocalZ - a.LocalZ + (b.GlobalZ - a.GlobalZ) * CellSize;
            var m = System.Math.Sqrt(x * x + y * y + z * z);

            if (m > 0.0)
            {
                x /= m;
                y /= m;
                z /= m;
            }

            return(new Vector3((float)x, (float)y, (float)z));
        }
コード例 #27
0
        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;
        }
コード例 #28
0
        /// <summary>This gives you the camera-relative position of the input SgtPosition in world space.</summary>
        public Vector3 CalculatePosition(ref SgtPosition input)
        {
            if (SnappedPointSet == false && UseOrigin == true)
            {
                SnappedPoint    = SgtFloatingOrigin.CurrentPoint.Position;
                SnappedPointSet = true;
            }

            var offsetX = (input.GlobalX - SnappedPoint.GlobalX) * SgtPosition.CellSize + (input.LocalX - SnappedPoint.LocalX);
            var offsetY = (input.GlobalY - SnappedPoint.GlobalY) * SgtPosition.CellSize + (input.LocalY - SnappedPoint.LocalY);
            var offsetZ = (input.GlobalZ - SnappedPoint.GlobalZ) * SgtPosition.CellSize + (input.LocalZ - SnappedPoint.LocalZ);
            var scaledX = offsetX / Scale;
            var scaledY = offsetY / Scale;
            var scaledZ = offsetZ / Scale;

            return(new Vector3((float)scaledX, (float)scaledY, (float)scaledZ));
        }
コード例 #29
0
        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;
        }
コード例 #30
0
        protected virtual void Update()
        {
            if (point != null)
            {
                CheckForPositionChanges();

                if (OnDistance != null)
                {
                    var distance = SgtPosition.Distance(ref SgtFloatingOrigin.currentPoint.Position, ref Point.Position);

                    OnDistance(distance);
                }
            }
            else
            {
                expectedPositionSet = false;
            }
        }