けいごのなんとか

Unityユーザーとしてのブログ。ギリギリ路線走ってます。

スクリプトからスプラッシュ画像を設定

SerializedObject経由で設定することが可能です。

プロパティ名

iPhoneSplashScreen
iPhoneHighResSplashScreen
iPhoneTallHighResSplashScreen
iPhone47inSplashScreen
iPhone55inPortraitSplashScreen
iPhone55inLandscapeSplashScreen
iPadPortraitSplashScreen
iPadHighResPortraitSplashScreen
iPadLandscapeSplashScreen
iPadHighResLandscapeSplashScreen
XboxSplashScreen
blackberryLandscapeSplashScreen
blackberryPortraitSplashScreen
blackberrySquareSplashScreen

iPhoneSplashScreen は MobileSplashScreen を指します。

以下のように実装します。

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class NewBehaviourScript
{
    static NewBehaviourScript ()
    {
        foreach (var player in Resources.FindObjectsOfTypeAll<PlayerSettings> ()) {
            var so = new SerializedObject (player);
            so.Update ();
            so.FindProperty ("iPhoneSplashScreen").objectReferenceValue = AssetDatabase.LoadAssetAtPath ("Assets/unitychan.jpg", typeof(Texture));
            so.ApplyModifiedProperties ();

            EditorUtility.SetDirty (player);

        }
        AssetDatabase.SaveAssets ();
    }
}