- Home /
Set Android's Static Splash Image using API?
I couldn't found any API function to set the static splash image in Android, is that not supported? I can find Unity's splash screen but not the static image.
I may expecting something like this:
PlayerSettings.Android.staticSplashImage = mySprite;
And it sets the Android splash image like this (NOT Unity's Splash Screen!):
P.S. I am building a bunch of Android games and writing a tools to set all player settings include my splash screen without the need to change 1by1.
Answer by Chris333 · Apr 05, 2019 at 07:42 AM
It seems that you can set the general splash images that way which should also change the splashscreen on android.
using UnityEngine;
using UnityEditor;
public class ExampleScript
{
[MenuItem("SplashScreen/AssignLogos")]
public static void AssignLogos()
{
var logos = new PlayerSettings.SplashScreenLogo[2];
// Company logo
Sprite companyLogo = (Sprite)AssetDatabase.LoadAssetAtPath("Assets/SplashScreen/companylogo.jpg", typeof(Sprite));
logos[0] = PlayerSettings.SplashScreenLogo.Create(2.5f, companyLogo);
// Set the Unity logo to be drawn after the company logo.
logos[1] = PlayerSettings.SplashScreenLogo.CreateWithUnityLogo();
PlayerSettings.SplashScreen.logos = logos;
}
}
Source: PlayerSettings.SplashScreen.logos
Also node that it seems you cant do that with a personal subscription. Source:
Customizing an Android Splash Screen
Hi Chris, Thanks for the answer. However that's not the one I looked for. I did want the static splash image but not Unity's splash screen...
Answer by cumi233 · Apr 21, 2020 at 11:54 AM
I have the same problem, I can't find the API to set Android's static splash image. but I find another way, maybe not very good but helpful, hope there is a better way.
string projectSettingsPath = Application.dataPath.Replace("/Assets", "/ProjectSettings/ProjectSettings.asset");
StreamReader r = new StreamReader(projectSettingsPath);
StringBuilder builder = new StringBuilder();
while (!r.EndOfStream)
{
string str = r.ReadLine();
if (str != null && str.Contains("androidSplashScreen"))
{
string newStr = " androidSplashScreen: {fileID: 2800000, guid: "
+ AssetDatabase.AssetPathToGUID("Assets/logo.png")
+ ", type: 3}";
builder.AppendLine(newStr);
continue;
}
builder.AppendLine(str);
}
r.Close();
File.WriteAllText(projectSettingsPath,builder.ToString());
Update! I find another way in this forum, and finally I change Android's static splash image in this way. link text
Texture2D tex = AssetDatabase.LoadAssetAtPath("Assets/Logo/logo_default.png");
const string projectSettings = "ProjectSettings/ProjectSettings.asset";
UnityEngine.Object obj = AssetDatabase.LoadAllAssetsAtPath(projectSettings)[0];
SerializedObject psObj = new SerializedObject(obj);
SerializedProperty androidSplashFileId = psObj.FindProperty("androidSplashScreen.m_FileID");
if (androidSplashFileId != null)
{
androidSplashFileId.intValue = tex.GetInstanceID();
}
psObj.ApplyModifiedProperties();