手动设置启动屏幕以在任意时间出现 [英] Manually programming the splash screen to appear at arbitrary times

查看:96
本文介绍了手动设置启动屏幕以在任意时间出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,当我们在加载应用程序时启动该应用程序(或构建至Android设备)时,会出现splash screen,这是通过Unity的Edit -> Project Settings -> Player完成的,但现在我们有一个功能,有时会在中间的应用程序重新启动应用程序,因此我们希望对此行为进行编码,以便在应用程序重新启动时可以显示不同的启动屏幕>使用中.

In our app, the splash screen appears when we start the app (or build to Android device) as the app is loading, which is done through the Unity's Edit -> Project Settings -> Player but we now have a feature that sometimes in the middle of the app also re-starts the app, so we would like to code this behavior, so that we can show a different splash screen if the app re-starts mid-usage.

我们似乎无法弄清楚如何以编程方式或在应用程序代码中的确切位置进行操作,因此我们将不胜感激.

We cannot seem to be able to figure out how to do this programmatically, or where exactly in the app code, so we would appreictae any help.

我们确实知道(并且已经实施)的方法是:

What we do know (and have already implemented) is through:

PlayerPrefs.SetString("LastShownComponent", menuId);
PlayerPrefs.Save();

会记住这是应用程序第一次启动(原始启动图像)还是用户处于中间使用状态,但是当应用程序在中间重新加载时,我们如何指定另一个图像作为splash screen加载?用法?

which remembers if this is the first time the app is starting (original splash image) or whether the user is mid-usage, but how do we specify another image to be loaded as splash screen when the app is reloading mid-usage?

更多详细信息...

以前,我们只有以下代码:

Previously, we only had the following code:

if (_callbackUri == null)
{
    SceneManager.LoadScene("ReloadScene");
}

现在,我们强制通过以下方式重新启动应用的中端使用(出于特定原因):

Now, we force the app to re-start mid-usage (for a specific reason) by:

if (_callbackUri == null)
{
    PlayerPrefs.SetInt("Restarting", 1);
    PlayerPrefs.Save();
    #if UNITY_ANDROID && !UNITY_EDITOR
    AndroidPlugin.Restart();
    #else
    SceneManager.LoadScene("ReloadScene");
    #endif
}

但是,重新启动时,显然会重新加载播放器设置中的初始屏幕图像.

However, when it restarts, obviously it re-loads the same splash screen image that is in the player settings.

我们可能需要在AndroidPlugin.Restart();下方添加代码以加载新的初始屏幕图像,但是我们该怎么做呢?我们需要一个新的场景吗?

We probably need to add code just below AndroidPlugin.Restart(); to load a new splash screen image, but how do we do that? Do we need a new scene for that?

推荐答案

每个注释:

测试此问题的最快方法是创建一个空白场景,向该场景添加一个游戏对象,将其命名为SplashLoader之类的名称,然后为其提供脚本.

Quickest way to test this is to create a blank scene, add a gameobject to that scene name it something like SplashLoader and give it a script.

该脚本中唯一需要的是start方法,

the only thing you need in that script is the start method,

void Start()
{
    // Default to 0 incase this value isn't stored
    int reloaded = PlayerPrefs.GetInt("Restarting", 0); 

    // Reset to 0 so if the game is closed without restarting it will display the correct scene
    PlayerPrefs.SetInt("Restarting", 0); 

    PlayerPrefs.Save();
    if(reloaded == 1)
    {
        SceneManager.LoadScene("ReloadScene"); 
    }
    else
    {
        SceneManager.LoadScene("SplashScene");
    }
}

在这里,您将创建2个场景,一个用于普通SplashScene,另一个用于ReloadScene.在这些场景中,您可以创建一个画布对象并向其中添加图像,然后根据其所在的场景来更改图像.

From here you would create 2 scenes, one for your normal SplashScene and 1 for your ReloadScene. In those scene you can create a canvas object and add an image to it then change the image depending which scene it is.

如果您要使用单个场景并保持相同的动画说明您具有徽标淡入的效果,则可以使用另一种方法:

Another Option if you want to use a single scene and keep the same animation say you have an effect where your logo fades in, you can do this:

为您的启动屏幕创建一个场景,使您的索引索引为0,向其中添加画布和图像,然后使用动画制作器使启动屏幕效果正常运行.

Create a scene for your splash screen, make that your 0 index scene, add a canvas to it and an image, then use an animator to get your splash screen effect going.

向图像对象添加脚本,以根据首选项存储的内容更改图片,您可以使用与上面的start方法几乎相同的代码,而不用调用SceneManager来加载将要更新的场景图片.

Add a script to your image object, to change the picture depending on what the preference stores, you can use almost the same code as the start method above, instead of calling the SceneManager to load the scene you would just update the image.

这篇关于手动设置启动屏幕以在任意时间出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆