SplashScreen textures from editor script

开屏图想放在框架中自动打包,而不用每个项目都要去拖动一次。

http://forum.unity3d.com/threads/splashscreen-textures-from-editor-script.187930/

到处搜索没搜到解决方案。。。

反编译了一下UnityEditor.dll,然后看到了。。。

SplashScreen textures from editor script_第1张图片
Paste_Image.png

结合ProjectSettings.asset

SplashScreen textures from editor script_第2张图片
Paste_Image.png

反射扩展 http://www.jianshu.com/p/cf05e80e4d1c

using System.IO;
using UnityEditor;
using UnityEngine;
using Babybus.Framework.ExtensionMethods;

namespace Babybus.Builder
{
    public class BuildPlayerBase
    {
        protected static void SetSplashScreens()
        {
#if UNITY_ANDROID
            SetSplashScreen("androidSplashScreen", "800x480");
#endif

#if UNITY_IOS
            if (!SetSplashScreen("iPhoneSplashScreen", "320x480"))
                SetSplashScreen("iPhoneSplashScreen", "480x320");

            if (!SetSplashScreen("iPhoneHighResSplashScreen", "640x960"))
                SetSplashScreen("iPhoneHighResSplashScreen", "960x640");

            if (!SetSplashScreen("iPhoneTallHighResSplashScreen", "640x1136"))
                SetSplashScreen("iPhoneTallHighResSplashScreen", "1136x640");

            if (!SetSplashScreen("iPhone47inSplashScreen", "750x1334"))
                SetSplashScreen("iPhone47inSplashScreen", "1334x750");

            SetSplashScreen("iPhone55inPortraitSplashScreen", "1242x2208");
            SetSplashScreen("iPhone55inLandscapeSplashScreen", "2208x1242");
            SetSplashScreen("iPadPortraitSplashScreen", "768x1024");
            SetSplashScreen("iPadHighResPortraitSplashScreen", "1536x2048");
            SetSplashScreen("iPadLandscapeSplashScreen", "1024x768");
            SetSplashScreen("iPadHighResLandscapeSplashScreen", "2048x1536");
#endif
        }

        private static bool SetSplashScreen(string name, string size)
        {
            var property = typeof(PlayerSettings).Invoke("FindProperty", name) as SerializedProperty;
            property.serializedObject.Update();

            var assetPath = "Assets/BabyFrameWork/SplashScreens/SplashScreen-" + size + ".jpg";

            var texture = AssetDatabase.LoadAssetAtPath(assetPath);

            property.objectReferenceValue = texture;
            property.serializedObject.ApplyModifiedProperties();

            return texture != null;
        }
    }
}

你可能感兴趣的:(SplashScreen textures from editor script)