Coder Social home page Coder Social logo

pink-fl0yd / unityaspectratiocontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from denchisoft/unityaspectratiocontroller

0.0 1.0 0.0 7.67 MB

Unity script to enforce window aspect ratio for standalone Windows 32/64bit builds.

License: MIT License

C# 22.98% ShaderLab 67.27% HLSL 9.75%

unityaspectratiocontroller's Introduction

UnityAspectRatioController

Unity script to enforce window aspect ratio for standalone Windows 32/64bit builds.

How to use?

Add the MonoBehaviour AspectRatioController.cs to any GameObject in your scene (see included example scene). Then set the desired aspect ratio and minimal resolution values in the inspector.

What does this do?

This script enforces the set aspect ratio for the Unity game window. That means that you can resize the window but it will always keep the aspect ratio you set.

This is done by intercepting window resize events (WindowProc callback) and modifying them accordingly. You can also set a min/max width and height in pixel for the window. Both the aspect ratio and the min/max resolutions refer to the game area, so, as you'd expect, the window title bar and borders aren't included.

This script will also enforce the aspect ratio when the application is in fullscreen. When you switch to fullscreen, the application will automatically be set to the maximum possible resolution on the current monitor while still keeping the aspect ratio. If the monitor doesn't have the same aspect ratio, black bars will be added to the left/right or top/bottom.

Make sure you activate "Resizable Window" in the player settings, otherwise your window won't be resizable. You might also want to uncheck all unsupported aspect ratios under "Supported Aspect Ratios" in the player settings.

NOTE: This uses WinAPI, so it will only work on Windows. Tested on Windows 10, but should work on all recent versions.

unityaspectratiocontroller's People

Contributors

denchisoft avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.