简介
KSFramework是一个整合KEngine、SLua、xLua、ILRuntime的Unity Asset Bundle开发框架,并为程序、美术、策划、运营提供辅助工具集。(支持热重载)
KSFramework开源地址: https://github.com/mr-kelly/KSFramework
文档: https://mr-kelly.github.io/KSFramework/
环境
- Windows 10
- Unity 2021.3.21
打包报错
坑1:
Assets\XLua\Gen\UnityEngine_MaterialWrap.cs(628,58): error CS1615: Argument 1 may not be passed with the ‘ref’ keyword
解决: 找到 LuaClassWrap.tpl.txt 文件。其中有一句:
if pi ~= 0 then %>, <% end; if parameter.IsOut and
parameter.ParameterType.IsByRef then %>out <% elseif
parameter.ParameterType.IsByRef then %>ref <% end
%><%=LocalName(parameter.Name)%><% end) %> );
修改为:
if pi ~= 0 then %>, <% end; if parameter.IsOut and
parameter.ParameterType.IsByRef then %>out <% elseif parameter.IsIn
and parameter.ParameterType.IsByRef then %>in <% elseif
parameter.ParameterType.IsByRef then %>ref <% end
%><%=LocalName(parameter.Name)%><% end) %> );
然后执行:XLua->Clear Generated Code清除生成的代码;再重新执行打包流程。
坑2:
FileNotFoundException: Could not find file
‘F:\Unity\Project\KSFramework-master\KSFramework\Product\Windows-version.txt’.
解决: 找到下图.bat(根据打包的目标平台选择对应的bat文件)文件双击执行会自动
自动生成的version文件路径如下所示:
再次执行KEngine->AutoBuilder\Windows L2CPP,该错误消失。
坑3:
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(169,58): error CS1061: ‘AudioSource’ does not contain a definition for ‘PlayOnGamepad’ and no accessible extension method ‘PlayOnGamepad’ accepting a first argument of type ‘AudioSource’ could be found (are you missing a using directive or an assembly reference?)
解决:
找到ExampleGenConfig.cs文件,搜索 [BlackList],定位到如下位置:
//黑名单
[BlackList]
public static List<List<string>> BlackList = new List<List<string>>() {
new List<string>(){"System.Xml.XmlNodeList", "ItemOf"},
new List<string>(){"UnityEngine.WWW", "movie"},
#if UNITY_WEBGL
new List<string>(){"UnityEngine.WWW", "threadPriority"},
#endif
new List<string>(){"UnityEngine.Texture2D", "alphaIsTransparency"},
new List<string>(){"UnityEngine.Security", "GetChainOfTrustValue"},
new List<string>(){"UnityEngine.CanvasRenderer", "onRequestRebuild"},
new List<string>(){"UnityEngine.Light", "areaSize"},
new List<string>(){"UnityEngine.Light", "lightmapBakeType"},
new List<string>(){"UnityEngine.WWW", "MovieTexture"},
new List<string>(){"UnityEngine.WWW", "GetMovieTexture"},
new List<string>(){"UnityEngine.AnimatorOverrideController", "PerformOverrideClipListCleanup"},
#if !UNITY_WEBPLAYER
new List<string>(){"UnityEngine.Application", "ExternalEval"},
#endif
new List<string>(){"UnityEngine.GameObject", "networkView"}, //4.6.2 not support
new List<string>(){"UnityEngine.Component", "networkView"}, //4.6.2 not support
new List<string>(){"System.IO.FileInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
new List<string>(){"System.IO.FileInfo", "SetAccessControl", "System.Security.AccessControl.FileSecurity"},
new List<string>(){"System.IO.DirectoryInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
new List<string>(){"System.IO.DirectoryInfo", "SetAccessControl", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"System.IO.DirectoryInfo", "CreateSubdirectory", "System.String", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"UnityEngine.MonoBehaviour", "runInEditMode"},
};
在 #if UNITY_WEBGL上方插入一下代码:
//Texture
new List<string>(){"UnityEngine.Texture", "imageContentsHash"},
//MeshRenderer
new List<string>(){"UnityEngine.MeshRenderer", "scaleInLightmap"},
new List<string>(){"UnityEngine.MeshRenderer", "receiveGI"},
new List<string>(){"UnityEngine.MeshRenderer", "stitchLightmapSeams"},
new List<string>(){"UnityEngine.MeshRenderer", "scaleInLightmap"},
new List<string>(){"UnityEngine.MeshRenderer", "receiveGI"},
new List<string>(){"UnityEngine.MeshRenderer", "stitchLightmapSeams"},
//AudioSource
new List<string>(){"UnityEngine.AudioSource", "gamepadSpeakerOutputType"},
new List<string>(){"UnityEngine.AudioSource", "PlayOnGamepad","System.Int32"},
new List<string>(){"UnityEngine.AudioSource", "DisableGamepadOutput"},
new List<string>(){"UnityEngine.AudioSource", "SetGamepadSpeakerMixLevel","System.Int32","System.Int32"},
new List<string>(){"UnityEngine.AudioSource", "SetGamepadSpeakerMixLevelDefault","System.Int32"},
new List<string>(){"UnityEngine.AudioSource", "SetGamepadSpeakerRestrictedAudio","System.Int32","System.Boolean"},
new List<string>(){"UnityEngine.AudioSource", "GamepadSpeakerSupportsOutputType","UnityEngine.GamepadSpeakerOutputType"},
先XLua->Clear Generated Code清除生成的代码;再次执行KEngine->AutoBuilder\Windows L2CPP,该错误消失。
参考:
- https://blog.youkuaiyun.com/liuyongjie1992/article/details/133993232