代码更改Unity设置中的ICON

下面的代码是自己研究的可以实现更改unity设置中ICON的功能。


 void SetDefaultIcon(Texture2D tex)
    {
        var getIconFormPlatform = typeof(PlayerSettings).GetMethod("GetIconsForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
        var getIconSizesForPlatform = typeof(PlayerSettings).GetMethod("GetIconSizesForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
        var setIconsForPlatform = typeof(PlayerSettings).GetMethod("SetIconsForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
        var array = (Texture2D[])getIconFormPlatform.Invoke(null, new object[] { string.Empty });
        var iconSizesForPlatform = (int[])getIconSizesForPlatform.Invoke(null, new object[] { string.Empty });
        if (array.Length != iconSizesForPlatform.Length)
        {
            array = new Texture2D[iconSizesForPlatform.Length];
            setIconsForPlatform.Invoke(null, new object[] { string.Empty, array });
        }
        array[0] = tex;
        setIconsForPlatform.Invoke(null, new object[] { string.Empty, array });
        AssetDatabase.SaveAssets();
        defaultIconName = tex != null ? tex.name : string.Empty;

    }


你可能感兴趣的:(unity)