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

Creating a Overlay style app (C#)

Discussion in 'Scripting' started by EX-RAY, Jul 12, 2020.

  1. EX-RAY

    EX-RAY

    Joined:
    Jul 14, 2019
    Posts:
    1
    I am trying to create a FPS counter for android, but i don't know how to create a small counter to run in the top corner even when the app is closed.
    I need no help with the script to calculate the fps.
    Thank you
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    Just make a canvas and put a UI text element in the top left corner. Update it each frame with the current frame rate.

    Not sure what you mean by doing it while the app is closed though. I'm not sure framerate really has meaning when you're not displaying anything on screen.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    Is that even possible? I don't develop for Android, so maybe there's some cool android-only API for displaying content even when an app isn't open/focused? To me, that sounds like the kind of behavior that would be heavily abused by apps, and would be disallowed. Are you sure this kind of thing is even possible at the OS level?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    You won't be doing this via any mechanism contained in Unity. You'll need to write a custom Android activity and bless it with background privileges, and it has a whole bunch of implications and OS-specific warts and whistles:

    https://stackoverflow.com/questions/15472383/how-can-i-run-code-on-a-background-thread-on-android

    Once you get the basic activity functional I imagine you might be able to get it into an AAR and start it under Unity, but I certainly haven't attempted such a brave thing myself.

    Good luck!
     
    alexeu likes this.