[Unity] XLua Giant Pit Summary

table of Contents

1. The extension method does not take effect

Second, the localEulerAngles abnormal problem of obtaining transform in xLua


1. The extension method does not take effect

Recently I am using the GameFramework framework and connected to xlua. At the beginning of xlua, Init.lua I used the following code to obtain a global class declaration 

GameEntry = CS.StarForce.GameEntry    注意:Init.lua是游戏启动Lua时最先执行的lua文件用于require其他lua文件的

Then I used it in various UIs, and encountered that no matter how I checked, all types had been introduced into Lua (that is, in the LuaCallCSharp list), and I used the following code to report an error.

GameEntry.Sound:IsMuted("Music")

On the C# side, this method is an extension method of the SoundExtension static class!

I also tried to use the following code to try, and there was an error like a dime!

GameEntry.Sound.IsMuted("Music")

The solution is changed to CS.StarForce.GameEntry.GameEntry.Sound:IsMuted("Music"). The reason may be that the related expansion method of GameEntry that I obtained has not yet taken effect.


Updated: January 12, 2021

Second, the localEulerAngles abnormal problem of obtaining transform in xLua

The localEulerAngles may be different from the localEulerAngles on the C# side!
The localEulerAngles may be different from the localEulerAngles on the C# side!
The localEulerAngles may be different from the localEulerAngles on the C# side!

C# side (PS: path is a CinemachineSmoothPath, Cinemachine plug-in auxiliary custom path point class, tr is a path point quaternion, it will get the current point of the custom path according to the path length and return the rotation of the current point Yuan)

var tr = path.EvaluateOrientationAtUnit(p, CinemachineSmoothPath.PositionUnits.Distance).eulerAngles;                        
if (trans.localEulerAngles.y < tr.y - 1.5f || trans.localEulerAngles.y > tr.y + 1.5f)
{
    trans.rotation = Quaternion.RotateTowards(trans.rotation, Quaternion.Euler(0, tr.y, 0), 10 * Time.deltaTime);                            
}

Lua side (PS: trans.localEulerAngles.y, I changed it directly to trans.eulerAngles, which means that normal data yields normal results)

local tr = self.path:EvaluateOrientationAtUnit(self.p, CS.Cinemachine.CinemachineSmoothPath.PositionUnits.Distance).eulerAngles
if trans.eulerAngles.y < tr.y - 1.5 or trans.eulerAngles.y > tr.y + 1.5 then
    trans.rotation = CS.UnityEngine.Quaternion.RotateTowards(trans.rotation, CS.UnityEngine.Quaternion.Euler(0, tr.y, 0), 10 * Time.deltaTime)
    return
end

Therefore, the solution is to use eulerAngles instead. How to obtain the correct localEulerAngles has not been studied in depth (to be studied), and this problem may not occur. For example, different versions of xlua may be different, I think it should be xlua There is a problem with its own wrap conversion

Guess you like

Origin blog.csdn.net/qq_39574690/article/details/109733841