Fading iOS Splash Screen

533 views
Skip to first unread message

Luke Kellett

unread,
Apr 17, 2012, 6:53:18 PM4/17/12
to unity3dm...@googlegroups.com
Yo Guys,

I've coded up a nice little perl script which allows a 2 second fade out of the Unity splash screens without having to touch a single line of C#/JavaScript (i.e. it uses the actual UIImageView from ObjC and the correct image sizes as auto determined by Unity).

Just throw the below lines into an executable perl script named 'PostprocessBuildPlayer' or 'PostprocessBuildPlayer_SplashScreen' if you have multiple scripts with a main caller already (under Assets/Editor/'.

I hope you guys find it useful, oh and this is for Unity 3.5 only.

#!/usr/bin/perl

# PostprocessBuildPlayer #
# Grabs the plugin info from the filename after the '_'

# Dont run on any builds that are not iPhone builds
if( $ARGV[1] ne "iPhone" )
{
exit;
}

use File::Basename;
use Foundation;

# Dont run on any builds that are not iPhone builds
if( $ARGV[1] ne "iPhone" )
{
exit;
}

$installPath = $ARGV[0];
$currDir = `pwd`;
chomp $currDir;
$xcodeFiles = $currDir;

# Error handling.
sub handler
{
my($msg) = @_;
`osascript -e \'tell application \"Finder\" to display dialog \"$msg\" buttons \"OK\"\'`;
die "$msg\n";
}
$SIG{'__DIE__'}  = \&handler;

$filename = $installPath . "/Classes/AppController.mm";
open ( FILE, $filename) or die "Cannot open file: $!";

while ( $line = <FILE> ) {
# Add a call to our new fading splash screen method
    $line =~ s/(\w*)RemoveSplashScreen\(\);/RemoveSplashScreenFading();/;
# Add that method...
    $line =~ s/^void RemoveSplashScreen\(\)$/void RemoveSplashScreenFading()
{
    [UIView animateWithDuration:2 
                     animations:^{
                         _splashView.alpha = 0;
                     }
                     completion:^(BOOL finished) {
                         [_splashView removeFromSuperview];
                         [_splashView release];
                         _splashView = nil;
                     }];    

}

void RemoveSplashScreen\(\) \/\/ ALREADY MODIFIED/i;

    push(@outLines, $line);
}

close FILE;

open ( OUTFILE, ">$filename" );
print ( OUTFILE @outLines );
close ( OUTFILE );

Kind Regards,
Luke Kellett - Ruma Studios

Ruma Claw Web:  www.rumastudios.com 
Twitter:  @rumastudios 
Facebook:  www.facebook.com/rumastudios

Itamar Degani

unread,
Feb 25, 2013, 1:38:48 AM2/25/13
to unity3dm...@googlegroups.com
Luke, 

Thanks for posting this.

I was wondering what this script actually does. (Will be trying this out later today)

I'm assuming this is for iOS Basic users and is referring to the mandatory Unity logo? I've been experiencing long loading times on both iOS and Android and have been wondering if this is a built in delay after the splash screen.

Luke Kellett

unread,
Feb 25, 2013, 8:00:06 PM2/25/13
to unity3dm...@googlegroups.com
Hey Itmar,

Actually this should work for both Unity basic and Pro, I've only tested it on Pro though.

I've also attached an updated version for Unity 4 if you're interested as the ObjC side has changed in 4.0.

As far as I am aware there is no standard delay in hiding the splash screen, it is normally hidden after the first scene has finished loading. Try it out on an empty project/scene!

You will also want to put the following lines into a C# script somewhere to call when you've decided that your game is ready to play, not when Unity decides the scene has finished loading...


// This one is wedged into the AppController.mm file via the PostprocessBuildPlayer_SplashScreen editor script
[DllImport("__Internal")]
private static extern void _rumaExtrasHideUnitySplashScreen();

public static void HideUnitySplashScreen() {
// Call plugin only when running on real device

        if(Application.platform == RuntimePlatform.IPhonePlayer)
_rumaExtrasHideUnitySplashScreen();

}


Enjoy!



Kind Regards,
Luke Kellett - Ruma Studios

Ruma Claw Web:  www.rumastudios.com 
Twitter:  @rumastudios 
Facebook:  www.facebook.com/rumastudios


--
You received this message because you are subscribed to the Google Groups "Unity 3D Melbourne" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unity3dmelbour...@googlegroups.com.
To post to this group, send email to unity3dm...@googlegroups.com.
Visit this group at http://groups.google.com/group/unity3dmelbourne?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Luke Kellett

unread,
Mar 11, 2013, 8:16:47 AM3/11/13
to unity3dm...@googlegroups.com
Hey Guys,

I've done an update for this code for Unity 4 and had a few people ask for the code, so I thought I'd post it up...

It comes in two parts, one the post build script to change the Unity ObjC to not hide the splash screen, until you say to. And when it does that it does a nice little fade out.

  1. The first part is attached and is the post build script to go into the Assets/Editor folder.
  2. The second part is a bit of C# code to tell the Unity engine to hide the splash screen, which you will have to call manually from your own scripts. It is:

public static class RumaExtras {


[DllImport("__Internal")]
private static extern void _rumaExtrasHideUnitySplashScreen();

public static void HideUnitySplashScreen() {
// Call plugin only when running on real device

        if(Application.platform == RuntimePlatform.IPhonePlayer)
_rumaExtrasHideUnitySplashScreen();

}

}


Kind Regards,
Luke Kellett - Ruma Studios

Ruma Claw Web:  www.rumastudios.com 
Twitter:  @rumastudios 
Facebook:  www.facebook.com/rumastudios


PostprocessBuildPlayer_SplashScreen_iPhone_View_Unity4

Luke Kellett

unread,
Mar 12, 2013, 2:30:26 AM3/12/13
to unity3dm...@googlegroups.com
Dang, looks like I forgot the post build script :-/

Here tis!


Kind Regards,
Luke Kellett - Ruma Studios

Ruma Claw Web:  www.rumastudios.com 
Twitter:  @rumastudios 
Facebook:  www.facebook.com/rumastudios


PostprocessBuildPlayer_SplashScreen_iPhone_View_Unity4

Damian Trimboli

unread,
Nov 21, 2014, 11:25:31 AM11/21/14
to unity3dm...@googlegroups.com
Hi! Im interested in this. Can you confirm that this works with the new iPhone resolutions?
Also, it's possible to make it compatible with Android builds so I works the same way?

Thank you!


On Tuesday, March 12, 2013 3:30:26 AM UTC-3, Luke Kellett wrote:
Dang, looks like I forgot the post build script :-/

Here tis
 
 
Kind Regards,

Luke Kellett

unread,
Dec 31, 2014, 6:49:38 PM12/31/14
to unity3dm...@googlegroups.com
Hey Damian,

This script broke a while ago as Unity changed their trampoline code... What I do now is load the splash screen image into Unity and display it exactly the same way the trampoline code does. So when it starts rendering your first scene the user still sees the same image.

You can load the image via url on iOS but on Android you will need some native code to read the bytes and return it to your Unity code.

Take a look at the attached script, specifically the TryGetSplashImage methods (iOS/Android). These work on Unity 4.5.5 and should also work on Unity 4.6.

You'll also need to create a .jar with your own class that has the following public method:

    public byte[] TryGetSplashImage() {
        byte[] splashImageBytes = null; // What we return in the event of an error....
        
        AssetManager assetManager = _unityPlayerBridge.GetActivity().getAssets();
        InputStream inputStream = null;
        ByteArrayOutputStream outputStream = null;
        
        try {
            inputStream = assetManager.open("bin/Data/splash.png");
            outputStream = new ByteArrayOutputStream(inputStream.available());
            
            int readByteCount = 0;
            byte[] readByteBuffer = new byte[16384];
            
            while((readByteCount = inputStream.read(readByteBuffer, 0, readByteBuffer.length)) != -1) {
                outputStream.write(readByteBuffer, 0, readByteCount);
            }
            
            splashImageBytes = outputStream.toByteArray();
            
        } catch (IOException ex) {
            Log.error("Failed to read splash image", ex);
        } finally {
            FileUtils.CleanUpClosable(outputStream);
            FileUtils.CleanUpClosable(inputStream);
        }
        
        return splashImageBytes;

    }


It's all a little more work than before, but more future proof :-)



Kind Regards,
Luke Kellett - Ruma Studios

Ruma ClawWeb:  www.rumastudios.com 
Twitter:  @rumastudios 
Facebook:  www.facebook.com/rumastudios

SkynetNative.cs
Reply all
Reply to author
Forward
0 new messages