• [游戏开发][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文件报错:

    1. 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?)
    2. 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?)
    3. 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?)
    4. 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?)
    5. 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?)
    6. 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?)
    7. Assets\XLua\Gen\UnityEngine_AudioSourceWrap.cs(313,63): error CS0117: 'AudioSource' does not contain a definition for 'GamepadSpeakerSupportsOutputType'
    8. 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?)
    9. 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?)
    10. 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?)
    11. 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?)
    12. 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?)
    13. 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?)
    14. 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?)
    15. 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?)
    16. 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?)
    17. 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

    1. //黑名单
    2. [BlackList]
    3. public static Liststring>> BlackList = new Liststring>>() {
    4. new List<string>(){"System.Xml.XmlNodeList", "ItemOf"},
    5. new List<string>(){"UnityEngine.WWW", "movie"},
    6. #if UNITY_WEBGL
    7. new List<string>(){"UnityEngine.WWW", "threadPriority"},
    8. #endif
    9. new List<string>(){"UnityEngine.Texture2D", "alphaIsTransparency"},
    10. new List<string>(){"UnityEngine.Security", "GetChainOfTrustValue"},
    11. new List<string>(){"UnityEngine.CanvasRenderer", "onRequestRebuild"},
    12. new List<string>(){"UnityEngine.Light", "areaSize"},
    13. new List<string>(){"UnityEngine.Light", "lightmapBakeType"},
    14. #if UNITY_ANDROID
    15. new List<string>(){"UnityEngine.Light", "SetLightDirty"},
    16. new List<string>(){"UnityEngine.Light", "shadowRadius"},
    17. new List<string>(){"UnityEngine.Light", "shadowAngle"},
    18. #endif
    19. new List<string>(){"UnityEngine.WWW", "MovieTexture"},
    20. new List<string>(){"UnityEngine.WWW", "GetMovieTexture"},
    21. new List<string>(){"UnityEngine.AnimatorOverrideController", "PerformOverrideClipListCleanup"},
    22. #if !UNITY_WEBPLAYER
    23. new List<string>(){"UnityEngine.Application", "ExternalEval"},
    24. #endif
    25. new List<string>(){"UnityEngine.GameObject", "networkView"}, //4.6.2 not support
    26. new List<string>(){"UnityEngine.Component", "networkView"}, //4.6.2 not support
    27. new List<string>(){"System.IO.FileInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
    28. new List<string>(){"System.IO.FileInfo", "SetAccessControl", "System.Security.AccessControl.FileSecurity"},
    29. new List<string>(){"System.IO.DirectoryInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
    30. new List<string>(){"System.IO.DirectoryInfo", "SetAccessControl", "System.Security.AccessControl.DirectorySecurity"},
    31. new List<string>(){"System.IO.DirectoryInfo", "CreateSubdirectory", "System.String", "System.Security.AccessControl.DirectorySecurity"},
    32. new List<string>(){"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"},
    33. new List<string>(){"UnityEngine.MonoBehaviour", "runInEditMode"},
    34. };

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

    1. //Texture
    2. new List<string>(){"UnityEngine.Texture", "imageContentsHash"},
    3. //MeshRenderer
    4. new List<string>(){"UnityEngine.MeshRenderer", "scaleInLightmap"},
    5. new List<string>(){"UnityEngine.MeshRenderer", "receiveGI"},
    6. new List<string>(){"UnityEngine.MeshRenderer", "stitchLightmapSeams"},
    7. new List<string>(){"UnityEngine.MeshRenderer", "scaleInLightmap"},
    8. new List<string>(){"UnityEngine.MeshRenderer", "receiveGI"},
    9. new List<string>(){"UnityEngine.MeshRenderer", "stitchLightmapSeams"},
    10. //AudioSource
    11. new List<string>(){"UnityEngine.AudioSource", "gamepadSpeakerOutputType"},
    12. new List<string>(){"UnityEngine.AudioSource", "PlayOnGamepad","System.Int32"},
    13. new List<string>(){"UnityEngine.AudioSource", "DisableGamepadOutput"},
    14. new List<string>(){"UnityEngine.AudioSource", "SetGamepadSpeakerMixLevel","System.Int32","System.Int32"},
    15. new List<string>(){"UnityEngine.AudioSource", "SetGamepadSpeakerMixLevelDefault","System.Int32"},
    16. new List<string>(){"UnityEngine.AudioSource", "SetGamepadSpeakerRestrictedAudio","System.Int32","System.Boolean"},
    17. new List<string>(){"UnityEngine.AudioSource", "GamepadSpeakerSupportsOutputType","UnityEngine.GamepadSpeakerOutputType"},

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

  • 相关阅读:
    数据结构——线性表作业
    通讯录管理系统C++版本
    LeetCode 33. 搜索旋转排序数组(C++)
    QTableView练习实践00
    代码随想录 -- day23 -- ● 669. 修剪二叉搜索树 、108.将有序数组转换为二叉搜索树 、538.把二叉搜索树转换为累加树
    实时语音驱动实现Android端Avatar虚拟人表情表达
    ArcGIS地图投影与坐标系转换的方法
    Flink集群配置
    【cmake】cmake生成Visual Studio工程后的INSTALL项目使用
    MySQL 字段值按照分隔符拆分成列(行转列)
  • 原文地址:https://blog.csdn.net/liuyongjie1992/article/details/133993232