Created
February 3, 2019 07:41
-
-
Save TakaakiIchijo/fa380aaca0824f19a75f66ed8926c660 to your computer and use it in GitHub Desktop.
UnityのSplashScreenに自動的にSpriteを追加して自分自身は消滅するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using UnityEngine; | |
using UnityEditor; | |
[InitializeOnLoad] | |
public class AutoAddImageToSplashScreen | |
{ | |
private static string IMAGEPATH = "Assets/Textures/SplashScreen/Image.png"; | |
private static string THISPATH = "Assets/Editor/AutoAddImageToSplashScreen.cs"; | |
static AutoAddImageToSplashScreen() | |
{ | |
EditorApplication.delayCall += () => AssignLogos(); | |
} | |
public static void AssignLogos() | |
{ | |
Sprite imageSprite = (Sprite) AssetDatabase.LoadAssetAtPath(IMAGEPATH, typeof(Sprite)); | |
var currentLogos = PlayerSettings.SplashScreen.logos; | |
if(currentLogos.Select(l => l.logo).Contains(imageSprite)) | |
{ | |
if (EditorUtility.DisplayDialog("Add image to SplashScreen","Image already added.", "OK")) | |
{ | |
Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings"); | |
} | |
return;; | |
} | |
var newLogos = new PlayerSettings.SplashScreenLogo[currentLogos.Length + 1]; | |
Array.Copy(currentLogos, newLogos, currentLogos.Length); | |
newLogos[newLogos.Length -1] = PlayerSettings.SplashScreenLogo.Create(2f, imageSprite); | |
PlayerSettings.SplashScreen.logos = newLogos; | |
PlayerSettings.SplashScreen.drawMode = PlayerSettings.SplashScreen.DrawMode.AllSequential; | |
if (EditorUtility.DisplayDialog("Add image to SplashScreen","Added Image SplashScreen.", "OK")) | |
{ | |
Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings"); | |
AssetDatabase.DeleteAsset(THISPATH); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment