KSFramework踩坑

KSFramework是整合多种工具的Unity Asset Bundle开发框架,支持热重载。本文介绍其开源地址和文档,重点讲述在Windows 10、Unity 2021.3.21环境下打包时遇到的三个报错,如CS1615、FileNotFoundException、CS1061等,并给出了相应的解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简介

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文件路径如下所示:

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
### 完成S7协议与虚拟PLC通信后的Unity项目打包导出 在完成S7协议与虚拟PLC的通信后,将Unity项目打包导出为WebGL是一项常见的操作。以下是关于此过程的一些重要说明: #### 打包前的准备工作 为了确保Unity项目的顺利导出,在打包之前需要做好充分准备。这包括但不限于配置网络请求、优化资源以及处理可能存在的兼容性问题。 1. **网络请求设置** 使用HTTP或其他适合的方式实现Unity与服务器之间的数据交互是非常重要的一步。如果已经通过S7协议完成了与虚拟PLC的数据交换,则可以在此基础上进一步扩展功能[^1]。需要注意的是,当目标平台为WebGL时,某些原生插件可能会受到限制,因此建议优先考虑纯脚本方式来管理网络逻辑。 2. **资源优化** WebGL版本通常运行于浏览器环境中,这意味着性能和加载时间会成为影响用户体验的关键因素之一。可以通过压缩纹理、减少多边形数量等方式降低文件大小并提高渲染效率。 3. **安全性考量** 鉴于WebGL应用暴露在外网环境下容易遭受攻击,务必采取适当措施保护敏感信息不被窃取或篡改。例如启用HTTPS加密传输通道以防止中间人劫持等问题发生。 #### 导出流程概述 执行具体导出步骤如下所示: - 进入`File -> Build Settings...`菜单项; - 将场景拖拽至右侧列表框内确认要构建的内容; - 选择Target Platform为WebGL选项卡; - 设置好相关参数如分辨率适配模式等细节调整; - 开始正式Build进程直至结束即可获得最终产物。 此外还可以利用第三方框架简化部分工作量比如KSFramework提供了丰富的工具帮助开发者快速搭建跨平台应用程序结构[^2]。 ```bash # 示例命令用于自动化部署到远程主机上 (假定Linux环境) scp -r build/webgl/* user@remote_host:/var/www/html/ ``` 以上就是整个从建立基础通讯机制到最后成品交付的大致路线图描述了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值