iOSはユニティスプラッシュを書き換え、黒い画面を取り除き、オープニングアニメーションビデオを再生します

iOSはユニティスプラッシュを書き換え、黒い画面を排除し、オープニングアニメーションビデオをカスタマイズし、クラックする必要はありません

このチュートリアルはunity5.xシリーズでのみ使用されます。2018年の新しいチュートリアルを参照してください

私が使用しているUnityは無料バージョンであるため、スプラッシュを削除することはできません。そのため、IOSとAndroidでUnityをブロックするViewの開始アニメーションにスパルシュを追加しました。これにより、黒い画面が削除され、ビデオやその他の機能が再生されます。インターネットでは、Androidバージョンのチュートリアルのみが見つかります。 、それで私はAndroidの方法を模倣してIOSバージョンを書きました

Androidチュートリアル:リンクをクリック


iOSバージョンのチュートリアル:

最初にUnityプロジェクトをIOSプロジェクトにエクスポートし、Xcodeで開きます

ファイルを変更します。

UnityAppController.h

新しい方法

+(void)showMainView;

ここに画像の説明を挿入


UnityAppController.mm

新しいポインタ変数:

static UIWindow*  currentWindow  = nil;
static UIView*  currentRootView  = nil;
static UIViewController* currentRootController;

ここに画像の説明を挿入

ポインター変数の割り当て
:-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsメソッドで値を割り当てます

currentWindow = _window;
currentRootView = _rootView;
currentRootController = _rootController;

ここに画像の説明を挿入

新しい方法:

+(void)showMainView{
    
    
    [currentWindow addSubview: currentRootView];
    currentWindow.rootViewController = currentRootController;
    [currentWindow bringSubviewToFront: currentRootView];
    
    //指针释放,不知道对不对,平时很少写OC和C++
	currentRootView= nil;
	currentRootController = nil;
	currentRootView = nil;
	//
    HideStartAim();
}

ここに画像の説明を挿入


SplashScreen.h

新しい方法:

void HideStartAim();

ここに画像の説明を挿入


SplashScreen.mm

変数を増やす:

static UIView* animView;

ここに画像の説明を挿入

新しい方法:

void HideStartAim()
{
    
    
    [animView removeFromSuperview];
    animView = nil;
}

ここに画像の説明を挿入

createメソッドを変更し、ユニティウィンドウを開くのを遅らせ、カスタムビューを追加します。

メソッド:-(void)create:(UIWindow)window *

- (void)create:(UIWindow*)window
{
    
    
    NSArray* supportedOrientation = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"UISupportedInterfaceOrientations"];
    bool isIphone = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;
    bool isIpad = !isIphone;
    
    // splash will be shown way before unity is inited so we need to override autorotation handling with values read from info.plist
    _canRotateToPortrait            = [supportedOrientation containsObject: @"UIInterfaceOrientationPortrait"];
    _canRotateToPortraitUpsideDown  = [supportedOrientation containsObject: @"UIInterfaceOrientationPortraitUpsideDown"];
    _canRotateToLandscapeLeft       = [supportedOrientation containsObject: @"UIInterfaceOrientationLandscapeRight"];
    _canRotateToLandscapeRight      = [supportedOrientation containsObject: @"UIInterfaceOrientationLandscapeLeft"];
    
    CGSize size = [[UIScreen mainScreen] bounds].size;
    // iPads, iPhone 6+ and iPhone X have orientable splash screen. Also, looks like iOS 11 also has orientable
    // launch screen on all devices, but not updating this due to regression potential
    _isOrientable = isIpad || (size.height == 736 || size.width == 736) || (size.height == 812 || size.width == 812);
    
    // Launch screens are used only on iOS8+ iPhones
    const char* xib = UnityGetLaunchScreenXib();
#if !UNITY_TVOS
    _usesLaunchscreen = false;
    if (_ios80orNewer && xib != NULL)
    {
    
    
        const char* expectedName = isIphone ? "LaunchScreen-iPhone" : "LaunchScreen-iPad";
        if (std::strcmp(xib, expectedName) == 0)
            _usesLaunchscreen = true;
    }
#else
    _usesLaunchscreen = false;
#endif
    
    if (_usesLaunchscreen && !(_canRotateToPortrait || _canRotateToPortraitUpsideDown))
        _nonOrientableDefaultOrientation = landscapeLeft;
    else
        _nonOrientableDefaultOrientation = portrait;
    
    animView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, size.width, size.height)];
    animView.contentScaleFactor = [UIScreen mainScreen].scale;
    
    if (_isOrientable)
    {
    
    
        animView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        animView.autoresizesSubviews = YES;
    }
    else if (_canRotateToPortrait || _canRotateToPortraitUpsideDown)
    {
    
    
        _canRotateToLandscapeLeft = false;
        _canRotateToLandscapeRight = false;
    }
    // On non-orientable devices with launch screens, landscapeLeft is always used if both
    // landscapeRight and landscapeLeft are enabled
    if (!_isOrientable && _usesLaunchscreen && _canRotateToLandscapeRight)
    {
    
    
        if (_canRotateToLandscapeLeft)
            _canRotateToLandscapeRight = false;
        else
            _nonOrientableDefaultOrientation = landscapeRight;
    }
    
    self.view = animView;
    
#if !UNITY_TVOS
    self.wantsFullScreenLayout = TRUE;
#endif
    
    //读取本地视频路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"logovideo" ofType:@"mp4"];
    //为即将播放的视频内容进行建模
    AVPlayerItem *avplayerItem = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:path]];
    //创建监听(这是一种KOV的监听模式)
    [avplayerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:avplayerItem];
    //给播放器赋值要播放的对象模型
    AVPlayer *avplayer = [AVPlayer playerWithPlayerItem:avplayerItem];
    //指定显示的Layer
    AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:avplayer];
    layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    layer.frame = CGRectMake(0, 0, size.width, size.height);
    [animView.layer addSublayer:layer];
    
    [window addSubview:animView];
    //    [window addSubview: _splash];
    window.rootViewController = self;
    [window bringSubviewToFront:animView];
    [avplayer play];
}


UnityAppController + ViewHandling.mm

showGameUIは3行コメントします

//    [_window addSubview: _rootView];
//    _window.rootViewController = _rootController;
//    [_window bringSubviewToFront: _rootView];

ここに画像の説明を挿入


資源管理

ビデオリソースをResourcesフォルダーに配置します:
ファイル名:logovideo.mp4。ファイル名または他のビデオ形式を変更する必要がある場合は、上のカスタムビューのコードでUnity-iPhone構成を変更してビデオファイル
画像の説明はこちら
追加する必要があります。
ここに画像の説明を挿入


Unity側はこのメソッドを呼び出して、開始アニメーションページを閉じ、Unityインターフェースを表示します

 [UnityAppController showMainView];

UnityがIOSチュートリアルを呼び出す:リンクをクリックします

						*****************到此完成!************************

効果のデモ:

Unityは開始アニメーションと黒い境界線を排除します

おすすめ

転載: blog.csdn.net/weixin_40137140/article/details/103329442