Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Android Screen flicking issue

Discussion in 'Android' started by Celovis, Mar 9, 2014.

  1. Celovis

    Celovis

    Joined:
    Feb 26, 2014
    Posts:
    4
    Currently on the app i'm working on i'm having the an issue with the screen resizing and causing it to flicker. The code which i'm currenly using is:

    Code (csharp):
    1. void Awake () {
    2. Screen.Setresolution(800, 600, false);
    3. }
    I found a way to attach a script to each camera that will resize all objects based on given float
    Code (csharp):
    1. public float floatable = 100.0f;
    2. void Update ()
    3. this.game.ortographicSize = Screen.heigh * gameObject.camera.rect.height / floatable / 2.0f;
    4.  
    How can I remove the flicker and what would be the best way to use the publicly set size?
     
  2. Celovis

    Celovis

    Joined:
    Feb 26, 2014
    Posts:
    4
    I found this guys method of fixing here is his code.


    GUI SIZER
    Code (csharp):
    1. public class GUISizer    
    2. {
    3.          private static float WIDTH = 1024;        
    4.         private static float HEIGHT = 768;          
    5.         static List<Matrix4x4>  stack = new List<Matrix4x4>();
    6.  
    7.         static public void BeginGUI()        
    8.         {                
    9.             stack.Add(UnityEngine.GUI.matrix);
    10.             var m = new Matrix4x4();            
    11.             var scaleX = 1f;          
    12.             var scaleY = 1f;          
    13.            
    14.             ScaleY = (Screen.height / HEIGHT);
    15.             ScaleX = (Screen.width / WIDTH);
    16.          
    17.             m.SetTRS(Vector3.zero, Quaternion.identity, new Vector3(ScaleX,ScaleY,1));
    18.              UnityEngine.GUI.matrix *= m;
    19.              
    20.  
    21.            }
    22.          
    23.          static public void EndGUI()        
    24.          {            
    25.              UnityEngine.GUI.matrix = stack[stack.Count - 1];
    26.               stack.RemoveAt(stack.Count-1);
    27.           }
    28. }
    29.  
    GUIButton Class
    Code (csharp):
    1. [System.Serializable]
    2.     public class GUIButton
    3.     {
    4.        
    5.         public string name;
    6.         public GUIContent content;
    7.         public float width=0;
    8.         public float height=0;
    9.         public Vector2 position;
    10.  
    11.         private Rect r;
    12.         public Rect rect
    13.         {
    14.             get
    15.             {
    16.                
    17.                if(width == 0  content.image.width != null)
    18.                 {
    19.  
    20.                     width =  content.image.width;
    21.                    
    22.                 }
    23.                 if(height == 0  content.image.height != null)
    24.                 {
    25.                     height = content.image.height;
    26.                 }
    27.  
    28.                 r = new Rect(position.x , position.y , width , height );
    29.                 Debug.Log(string.Format("Position: ({0},{1}), Size: ({2},{3})", position.x, position.y, width, height));
    30.                 return r;
    31.             }
    32.         }
    33.     }
    34.  
    OnGUI call
    Code (csharp):
    1.  
    2.  
    3. public GUIButton[] buttons;
    4. ...
    5. void OnGUI()
    6.     {
    7.         GUISizer.BeginGUI();
    8.         GUI.DrawTexture(new Rect(0, 0, 1024, 768), background);
    9.         GUI.DrawTexture(new Rect(0, 0, 1024, 768), MenuOverlay);
    10.  
    11.        
    12.         if(p_buttonStyle == null)
    13.         {
    14.             p_buttonStyle = GUI.skin.FindStyle(buttonStyle);
    15.         }
    16.      
    17.         foreach (var t in buttons)
    18.         {
    19.             GUI.Button(t.rect, t.content, p_buttonStyle);
    20.             //Pressed(buttons[i].name);
    21.         }
    22.  
    23.  
    24.         // Restore matrix before returning
    25.         GUISizer.EndGUI();
    26.     }
    27.  
    Source: http://www.3dbuzz.com/forum/threads/192888-iOS-and-Android-Stretch-and-Scaling-properly

    Now how can I implement this into my app
     
  3. Celovis

    Celovis

    Joined:
    Feb 26, 2014
    Posts:
    4