Example #1
0
    public void ApplyLocalPosition(Platform platform)
    {
        if (localPositionPerPlatform != null)
        {
            foreach (LocalPositionPerPlatform pair in localPositionPerPlatform)
            {
                if (platform == pair.platform)
                {
                    transform.localPosition = pair.localPosition;
                    break;
                }
            }
        }

        if (Platforms.IsPlatformAspectBased(platform.ToString()) && localPositionPerAspectRatio != null)
        {
            foreach (LocalPositionPerAspectRatio pair in localPositionPerAspectRatio)
            {
                if (AspectRatios.GetAspectRatio() == pair.aspectRatio)
                {
                    transform.localPosition = pair.localPosition;
                    break;
                }
            }
        }
    }
Example #2
0
    public void ApplyLocalScale(Platform platform)
    {
        if (localScalePerPlatform != null)
        {
            foreach (LocalScalePerPlatform pair in localScalePerPlatform)
            {
                if (isCompatiblePlatform(platform, pair.platform))
                {
                    transform.localScale = pair.localScale;
                    break;
                }
            }
        }

        if (Platforms.IsPlatformAspectBased(platform.ToString()) && localScalePerAspectRatio != null)
        {
            foreach (LocalScalePerAspectRatio pair in localScalePerAspectRatio)
            {
                if (AspectRatios.GetAspectRatio() == pair.aspectRatio)
                {
                    transform.localScale = pair.localScale;
                    break;
                }
            }
        }
    }
Example #3
0
    public void ApplyLocalScale(Platform platform)
    {
                #if UNITY_4_6
        var rectTransform = GetComponent <RectTransform>();
                #endif

        if (localScalePerPlatform != null)
        {
            foreach (LocalScalePerPlatform pair in localScalePerPlatform)
            {
                if (isCompatiblePlatform(platform, pair.platform))
                {
                                        #if UNITY_4_6
                    if (rectTransform != null)
                    {
                        rectTransform.localScale = pair.localScale;
                    }
                    else
                    {
                        transform.localScale = pair.localScale;
                    }
                                        #else
                    transform.localScale = pair.localScale;
                                        #endif
                    break;
                }
            }
        }

        if (Platforms.IsPlatformAspectBased(platform.ToString()) && localScalePerAspectRatio != null)
        {
            foreach (LocalScalePerAspectRatio pair in localScalePerAspectRatio)
            {
                if (AspectRatios.GetAspectRatio() == pair.aspectRatio)
                {
                                        #if UNITY_4_6
                    if (rectTransform != null)
                    {
                        rectTransform.localScale = pair.localScale;
                    }
                    else
                    {
                        transform.localScale = pair.localScale;
                    }
                                        #else
                    transform.localScale = pair.localScale;
                                        #endif
                    break;
                }
            }
        }
    }
Example #4
0
    public void ApplyLocalPosition(Platform platform)
    {
        if (localPositionPerPlatform != null)
        {
            foreach (LocalPositionPerPlatform pair in localPositionPerPlatform)
            {
                if (isCompatiblePlatform(platform, pair.platform))
                {
                    transform.localPosition = pair.localPosition;
                    break;
                }
            }
        }

        if (Platforms.IsPlatformAspectBased(platform.ToString()) && localPositionPerAspectRatio != null)
        {
            foreach (LocalPositionPerAspectRatio pair in localPositionPerAspectRatio)
            {
                if (AspectRatios.GetAspectRatio() == pair.aspectRatio)
                {
                    transform.localPosition = pair.localPosition;
                    break;
                }
            }
        }

        // if an anchor position, it will override others
        if (anchorPositions != null)
        {
            foreach (AnchorPosition pair in anchorPositions)
            {
                // make sure we have a camera to align to
                var cam = pair.alignmentCamera;
                if (cam == null)
                {
                    Debug.LogError("No alignment camera is attached to GameObject: " + gameObject.name);
                    continue;
                }

                // get screen size
                float screenWidth = Screen.width, screenHeight = Screen.height;
                                #if UNITY_EDITOR
                if (UseEditorApplyMode)
                {
                    AspectRatios.getScreenSizeHack(out screenWidth, out screenHeight);
                }
                                #endif

                // get position
                var pos = pair.screenPosition;

                if (pair.positionXAsPercent)
                {
                    pos.x *= screenWidth;                    // * 0.01f;
                }
                if (pair.positionYAsPercent)
                {
                    pos.y *= screenHeight;                    // * 0.01f;
                }
                // global calculations
                var ray        = cam.ScreenPointToRay(pos);
                var planePoint = RayInersectPlane(ray, -cam.transform.forward, transform.position);

                ray = cam.ScreenPointToRay(Vector3.zero);
                var bottomLeft = RayInersectPlane(ray, -cam.transform.forward, transform.position);

                ray = cam.ScreenPointToRay(new Vector3(screenWidth, screenHeight, 0));
                var topRight = RayInersectPlane(ray, -cam.transform.forward, transform.position);

                // get object radius
                float radius = 0;
                if (renderer != null)
                {
                    radius = (renderer.bounds.max - renderer.bounds.min).magnitude * .5f;
                }

                // get new projected width and height
                var screenSize = (topRight - bottomLeft);
                screenWidth  = Vector3.Dot(screenSize, cam.transform.right);
                screenHeight = Vector3.Dot(screenSize, cam.transform.up);

                // horizontal alignment types
                switch (pair.horizontalAlignment)
                {
                case HorizontalAlignments.Left: planePoint += cam.transform.right * (!pair.centerX ? radius : 0); break;

                case HorizontalAlignments.Right: planePoint += cam.transform.right * (screenWidth - (!pair.centerX ? radius : 0)); break;

                case HorizontalAlignments.Center: planePoint += cam.transform.right * (screenWidth * .5f); break;
                }

                // vertical alignment types
                switch (pair.verticalAlignment)
                {
                case VerticalAlignments.Bottom: planePoint += cam.transform.up * (!pair.centerY ? radius : 0); break;

                case VerticalAlignments.Top: planePoint += cam.transform.up * (screenHeight - (!pair.centerY ? radius : 0)); break;

                case VerticalAlignments.Center: planePoint += cam.transform.up * (screenHeight * .5f); break;
                }

                // set final position
                transform.position = planePoint;
            }
        }
    }