[游戏开发][Unity] Xlua生成wrap文件报错、打AB包Wrap报错

 Xlua生成wrap文件,自带添加了ref字段报错

例如Material生成MaterialWrap时,EnableKeyword(in LocalKeyword keyword);带着in关键字,所以在Wrap文件中会自动在参数前生成ref关键字导致编译不过

解决办法:

换Xlua版本就好了,也不知道我xlua当时从哪个版本copy过来的,换了xlua-master里的Xlua源码,再次生成wrap就没问题了。

 打包时Xlua Wrap文件报错:

Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(169,57): 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?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(197,57): error CS1061: 'AudioSource' does not contain a definition for 'DisableGamepadOutput' and no accessible extension method 'DisableGamepadOutput' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(227,57): error CS1061: 'AudioSource' does not contain a definition for 'SetGamepadSpeakerMixLevel' and no accessible extension method 'SetGamepadSpeakerMixLevel' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(256,57): error CS1061: 'AudioSource' does not contain a definition for 'SetGamepadSpeakerMixLevelDefault' and no accessible extension method 'SetGamepadSpeakerMixLevelDefault' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(286,57): error CS1061: 'AudioSource' does not contain a definition for 'SetGamepadSpeakerRestrictedAudio' and no accessible extension method 'SetGamepadSpeakerRestrictedAudio' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(311,33): error CS0234: The type or namespace name 'GamepadSpeakerOutputType' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(313,63): error CS0117: 'AudioSource' does not contain a definition for 'GamepadSpeakerSupportsOutputType'
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(982,54): error CS1061: 'AudioSource' does not contain a definition for 'gamepadSpeakerOutputType' and no accessible extension method 'gamepadSpeakerOutputType' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(1396,29): error CS0234: The type or namespace name 'GamepadSpeakerOutputType' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(1397,23): error CS1061: 'AudioSource' does not contain a definition for 'gamepadSpeakerOutputType' and no accessible extension method 'gamepadSpeakerOutputType' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_MeshRendererWrap.cs(137,60): error CS1061: 'MeshRenderer' does not contain a definition for 'scaleInLightmap' and no accessible extension method 'scaleInLightmap' accepting a first argument of type 'MeshRenderer' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_MeshRendererWrap.cs(151,54): error CS1061: 'MeshRenderer' does not contain a definition for 'receiveGI' and no accessible extension method 'receiveGI' accepting a first argument of type 'MeshRenderer' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_MeshRendererWrap.cs(165,61): error CS1061: 'MeshRenderer' does not contain a definition for 'stitchLightmapSeams' and no accessible extension method 'stitchLightmapSeams' accepting a first argument of type 'MeshRenderer' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_MeshRendererWrap.cs(211,35): error CS1061: 'MeshRenderer' does not contain a definition for 'scaleInLightmap' and no accessible extension method 'scaleInLightmap' accepting a first argument of type 'MeshRenderer' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_MeshRendererWrap.cs(227,23): error CS1061: 'MeshRenderer' does not contain a definition for 'receiveGI' and no accessible extension method 'receiveGI' accepting a first argument of type 'MeshRenderer' could be found (are you missing a using directive or an assembly reference?)
Assets\XLua\Gen\UnityEngine_MeshRendererWrap.cs(242,35): error CS1061: 'MeshRenderer' does not contain a definition for 'stitchLightmapSeams' and no accessible extension method 'stitchLightmapSeams' accepting a first argument of type 'MeshRenderer' could be found (are you missing a using directive or an assembly reference?)
Error building Player because scripts had compiler errors

解决方法

 Xlua的配置文件有个专门添加[LuaCallCSharp]、[CSharpCallLua]、[BlackList]的方法,在xlua-master源码里是ExampleGenConfig.cs或者ExampleConfig.cs

BlackList的作用:生成的wrap文件中屏蔽字段和方法

BlackList如何配置:

屏蔽变量和方法的方式如下,都罗列出来了,对号入座。

屏蔽变量 

new List<string>(){"UnityEngine.AudioSource", "gamepadSpeakerOutputType"},

 屏蔽无参方法

new List<string>(){"UnityEngine.AudioSource", "DisableGamepadOutput"},

 屏蔽参数是Int32的方法

new List<string>(){"UnityEngine.AudioSource", "PlayOnGamepad","System.Int32"},

屏蔽多参数方法 

new List<string>(){"UnityEngine.AudioSource", "SetGamepadSpeakerRestrictedAudio","System.Int32","System.Boolean"},

请注意,AudioSource前面的命名空间不能省略

找到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"},
    #if UNITY_ANDROID
                new List<string>(){"UnityEngine.Light", "SetLightDirty"},
                new List<string>(){"UnityEngine.Light", "shadowRadius"},
                new List<string>(){"UnityEngine.Light", "shadowAngle"},
    #endif
                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"},
            };

然后把我下面这一段加入到中间

    //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"},

再次执行Clear Generated Code、Generated Code后,会发现Wrap文件里的相关变量和方法都消失了。再次打包则不会报错

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
Unity生成报错GUI实用性:过程事件。 Unity是一款强大的跨平台游戏引擎,内置了强大而易用的GUI系统,用于创建游戏中的用户界面。然而,在打生成游戏的过程中,可能会遇到一些与GUI相关的报错,这些错误会影响到界面的正常显示和交互。 报错的实用性可以从两个方面考虑:过程和事件。 首先,过程方面。Unity生成过程中的GUI报错可能会导致无法正常启动游戏,或者在游戏运行过程中出现界面问题。这些报错括但不限于:界面元素错位、按钮无法点击、文字显示异常等。这些问题不仅会影响到玩家的游戏体验,也会给开发者增加修复bug的工作量。因此,报错GUI对于打生成的过程而言,具有重要的实用性,可以帮助开发者发现和解决问题,保证游戏在各种平台上的正常运行。 其次,事件方面。GUI报错可能会伴随着一些特定的事件,例如用户点击按钮时出现报错,或者切换游戏界面时出现问题。这些事件可以为开发者提供线索,帮助他们定位出错的地方,并进行相应的修复。通过分析报错事件,开发者可以深入了解GUI系统的运行机制,进而改进和优化游戏的用户界面,提升用户体验。 综上所述,Unity生成中的GUI报错具有重要的实用性。它们在保证游戏界面正确显示、和保证游戏正常运行的过程中起到承上启下的重要作用。开发者需要重视并解决这些报错,同时利用其中含的信息来优化游戏界面,提升用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Little丶Seven

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值