Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Change Android splash screen background from script

Discussion in 'Android' started by robal1991, Oct 30, 2018.

  1. robal1991

    robal1991

    Joined:
    Mar 31, 2016
    Posts:
    27
    How can I change Android splash screen background from script before build? I have 2 versions of my game and before I build them I need to change the splash screen accordingly to the game version.
    I can change PlayerSettings.SplashScreen.background but it seems it does nothing. I don't see a way to change static splash screen image for Android.

    I'll need to change it too on iOS and windows, is there a general solution to this problem?
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    821
    There is no way to change the static splash screen image from the script. PlayerSettings.SplashScreen.background is for the animated / dynamic splash screen and should work if you use that type of splash screen in your project.
     
  3. Mulik

    Mulik

    Joined:
    Jun 3, 2016
    Posts:
    1
    1.Read guid from meta file of texture

    e.g.
    fileFormatVersion: 2
    guid: 083673308dc792f4c99f3d3e33b383f8
    timeCreated: 1543575763

    2.And replace it to guid in projectSettings

    e.g.
    Read file ProjectSettings.asset:

    string projectSettingsPath = Application.dataPath.Replace("/Assets", "/ProjectSettings/ProjectSettings.asset");
    string projectSettings = File.ReadAllText(projectSettingsPath);

    And Replace red marked text below with red marked text in step 1.

    androidSplashScreen: {fileID: 2800000, guid: 8d7f092f78c6bcb429a60803a22bf208, type: 3}
     
  4. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    153
    How about this? I wrote this for iOS, it should be basically the same for Android.


    static void ModifyIphoneAndIPadBackgroundColor(Color32 iphoneBg, Color32 ipadBg)
    {
    const string projectSettings = "ProjectSettings/ProjectSettings.asset";
    UnityEngine.Object obj = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(projectSettings)[0];
    SerializedObject psObj = new SerializedObject(obj);
    SerializedProperty iPhoneBgColor = psObj.FindProperty ("iOSLaunchScreenBackgroundColor.rgba");
    SerializedProperty iPadBgColor= psObj.FindProperty("iOSLaunchScreeniPadBackgroundColor.rgba");
    UInt32 iphoneBgC = ((UInt32)iphoneBg.a) << 24 | ((UInt32)iphoneBg.b) << 16 | ((UInt32)iphoneBg.g) << 8 | ((UInt32)iphoneBg.r);
    iPhoneBgColor.longValue = iphoneBgC;
    UInt32 ipadBgC = ((UInt32)ipadBg.a) << 24 | ((UInt32)ipadBg.b) << 16 | ((UInt32)ipadBg.g) << 8 | ((UInt32)ipadBg.r);
    iPadBgColor.longValue = ipadBgC;
    psObj.ApplyModifiedProperties();
    }

     
    cumi233 likes this.
  5. cumi233

    cumi233

    Joined:
    Oct 25, 2019
    Posts:
    3
    it's useful! I change Android's static splash image successfully!
    Code (CSharp):
    1. Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Logo/logo_default.png");
    2. const string projectSettings = "ProjectSettings/ProjectSettings.asset";
    3. UnityEngine.Object obj = AssetDatabase.LoadAllAssetsAtPath(projectSettings)[0];
    4. SerializedObject psObj = new SerializedObject(obj);
    5. SerializedProperty androidSplashFileId = psObj.FindProperty("androidSplashScreen.m_FileID");
    6. if (androidSplashFileId != null)
    7. {
    8.     androidSplashFileId.intValue = tex.GetInstanceID();
    9. }
    10. psObj.ApplyModifiedProperties();
     
    jhughes2112 likes this.
unityunity