Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Spankenstein · Jan 21, 2014 at 05:13 PM · screenresize

Is there a callback function or event for a resolution change?

Is there an event that is raised or a function that is called when the screen resolution changes?

I do not wish to poll for Screen parameters.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jamora · Jan 21, 2014 at 05:20 PM

Nothing built-in that I know of. You will most likely have to raise an event yourself whenever your ChangeResolution(Screen size) or whatever method you use gets called.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Spankenstein · Jan 21, 2014 at 06:57 PM 0
Share

Sounds good to me. Thank you.

avatar image
3

Answer by Jessy · Jan 22, 2014 at 02:26 AM

I'm sick of trying to get this to format properly on this horrible site. PM me on the forum if you want better copy pasta.

   ScreenExtensions.ResolutionChanged += resolution => Debug.Log(resolution.width);
     new Resolution { width = 800, height = 500 }
         .ApplyToScreen(true);


 namespace UnityEngine
 {    
     using System;
 
     public static class ScreenExtensions
     {
         public static event Action<Resolution> ResolutionChanged;
 
         public static void ApplyToScreen(this Resolution resolution, bool fullscreen)
         {
             Screen.SetResolution(resolution.width, resolution.height, fullscreen, resolution.refreshRate);
             if (ResolutionChanged != null)
                 ( (Action)(() => ResolutionChanged(resolution)) )
                     .PerformAfterCoroutine<WaitForEndOfFrame>();
         }
     }

}

 namespace System
 {

 using System.Collections;
 using UnityEngine;

 public static class ActionExtensions
 {
     public static void PerformAfterCoroutine<T>(this Action action)
         where T : YieldInstruction, new()
     {
         CoroutineBehaviour.StartCoroutine<T>(action);
     }
 }

}

 namespace UnityEngine
 {    
     using System;
     using System.Collections;
 
     public static class MonoBehaviourExtensions
     {
         /// <summary>
         /// Performs an Action after a YieldInstruction. 
         /// </summary>
         public static void StartCoroutine<T>(this MonoBehaviour monoBehaviour, Action action)
             where T : YieldInstruction, new()
         {
             monoBehaviour.StartCoroutine(Coroutine<T>(action));
         }
 
         static IEnumerator Coroutine<T>(Action action) where T : YieldInstruction, new()                
         {
             yield return new T();
             action();
         }
     }
 
     public class CoroutineBehaviour : MonoBehaviour 
     {
         static MonoBehaviour Instance = new GameObject { hideFlags = HideFlags.HideAndDontSave }
             .AddComponent<CoroutineBehaviour>();
 
         public static void StartCoroutine<T>(Action action) where T : YieldInstruction, new()
         {
             Instance.StartCoroutine<T>(action);
         }
     }
 }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArkaneX · Jan 22, 2014 at 09:31 AM 0
Share

Crazy, but big +1 for taking end of the frame into account.

avatar image Spankenstein · Jan 22, 2014 at 10:07 AM 0
Share

It's a bit nutty, but I like it. :)

avatar image Jessy · Jan 22, 2014 at 03:26 PM 0
Share

Screen.Resolution should be a property that does what I offer here. Because you can't make a static extension method, or extension property, an extension method of Resolution is the cleanest thing I can think of. You of course need some back-end for this.

avatar image Fingar · Nov 03, 2015 at 11:13 PM 0
Share

@Jessy I have no idea how this works... and the formatting doesn't make things easier... :/ But can I make just some randomly named script and fill in everything you wrote, except:

 ScreenExtensions.ResolutionChanged += resolution => Debug.Log(resolution.width);
  new Resolution { width = 800, height = 500 }
      .ApplyToScreen(true);

...and then use something like this?:

 public void ResolutionChanged() {
     doSomething();
 }

That was what I tried.. Didn't get it to work... How in the world does this work?

avatar image Snoweuph · Apr 14, 2021 at 03:29 PM 0
Share

How works this? you sad you could give better copy pasta? whats about sourceb.in?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Testing orthographic camera at various resolutions -- detect window resize? 1 Answer

iphone screen too big? 0 Answers

Can you tell unity to resize the Game window by a button press? 2 Answers

Center an object in Ortographic view 1 Answer

GUITexture aspect ratio resize 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges