Ejemplo n.º 1
0
        private void doParallax()
        {
            foreach (var balancedList in balancedLists)
            {
                BalancedNode <Transform> node = balancedList.getRootNode();
                try
                {
                    float parallaxX = getXParallax(node);
                    float parallaxY = getYParallax(node);

                    float targetPositionX = getNodePositionX(node);
                    float targetPositionY = getNodePositionY(node);

                    if (parallaxHorizontal)
                    {
                        targetPositionX += parallaxX;
                    }

                    if (parallaxVertical)
                    {
                        targetPositionY += parallaxY;
                    }

                    Vector3 targetPosition = new Vector3(targetPositionX, targetPositionY, getNodePositionZ(node));

                    node.payload.position = Vector3.SmoothDamp(node.payload.position, targetPosition, ref speed,
                                                               smoothing * Time.deltaTime);
                }
                catch
                {
                    logger.LogError("Problem doing Parallax - Make sure root transform is set", "AutoParallax");
                    isError = true;
                }
            }
        }
Ejemplo n.º 2
0
        private void doBalancing()
        {
            float cameraHorizontalExtent = Camera.main.orthographicSize * Screen.width / Screen.height;

            foreach (var balancedList in balancedLists)
            {
                BalancedNode <Transform> leftestNode  = balancedList.getLeftestNode();
                BalancedNode <Transform> rightestNode = balancedList.getRightestNode();

                float edgeVisibleRightPosition =
                    getNodePositionX(rightestNode) + getNodeWidth(rightestNode) / 2 - cameraHorizontalExtent;
                float edgeVisibleLeftPosition =
                    getNodePositionX(leftestNode) - getNodeWidth(leftestNode) / 2 + cameraHorizontalExtent;


                if (camTransform.position.x > edgeVisibleRightPosition - offsetX)
                {
                    balancedList.popRight();
                }

                if (camTransform.position.x < edgeVisibleLeftPosition + offsetX)
                {
                    balancedList.popLeft();
                }
            }
        }
Ejemplo n.º 3
0
        private void alignAllRight(BalancedNode <Transform> node)
        {
            alignToRightBuddy(node);

            if (node.leftBuddy != null)
            {
                alignAllRight(node.leftBuddy);
            }
        }
Ejemplo n.º 4
0
        private void alignToRightBuddy(BalancedNode <Transform> node)
        {
            SetTransformX(node, getNodePositionX(node.getRightBuddy()) - getNodeWidth(node.getRightBuddy()) + 0.001f);
            SetTransformY(node, getNodePositionY(node.getRightBuddy()));
            SetTransformZ(node, getNodePositionZ(node.getRightBuddy()));

            var rightBuddyScale = node.getRightBuddy().payload.localScale;

            node.payload.localScale =
                tiled
                    ? new Vector3(rightBuddyScale.x * -1, rightBuddyScale.y, rightBuddyScale.z)
                    : node.getRightBuddy().payload.localScale;
        }
Ejemplo n.º 5
0
        private BalancedNode <Transform> spawn_buddy(BalancedNode <Transform> root)
        {
            Vector3 newPosition = new Vector3(getNodePositionX(root), getNodePositionY(root), getNodePositionZ(root));

            Transform sibling_transform = Instantiate(root.payload.transform, newPosition, root.payload.rotation);


            if (root.payload.parent != null)
            {
                sibling_transform.parent = root.payload.parent;
            }


            return(new BalancedNode <Transform>(sibling_transform));
        }
Ejemplo n.º 6
0
 private float getYParallax(BalancedNode <Transform> node)
 {
     return((previousCamPosition.y - camTransform.position.y) * getZDistanceFromCamera(camTransform, node) *
            scaleY);
 }
Ejemplo n.º 7
0
 private float getXParallax(BalancedNode <Transform> node)
 {
     return((previousCamPosition.x - camTransform.position.x) *
            (10 / getZDistanceFromCamera(camTransform, node)) * scaleX);
 }
Ejemplo n.º 8
0
 private static void SetTransformZ(BalancedNode <Transform> node, float n)
 {
     node.payload.position = new Vector3(node.payload.position.x, node.payload.position.y, n);
 }
Ejemplo n.º 9
0
 private static float getZDistanceFromCamera(Transform camTransform, BalancedNode <Transform> node)
 {
     return(Vector3.Distance(camTransform.position,
                             new Vector3(camTransform.position.x, camTransform.position.y, node.payload.transform.position.z)));
 }
Ejemplo n.º 10
0
 private static float getNodePositionZ(BalancedNode <Transform> node)
 {
     return(node.payload.position.z);
 }
Ejemplo n.º 11
0
 private static float getNodeWidth(BalancedNode <Transform> node)
 {
     return(node.payload.GetComponent <SpriteRenderer>().sprite.bounds.size.x *
            Mathf.Abs(node.payload.localScale.x));
 }