Unity3d 开发之 ulua 在 IOS 上坑的总结

相同的 lua 代码在安卓上能正常运行,但在 IOS 上可能不会正常运行而导致报红,崩溃等,我在使用 lua 编程时遇到的一些坑总结如下:

1. File.ReadAllText, 诸如以下代码在 ios 上会崩:

local path="C:/1.txt";
local file=luanet.import_type("System.IO.File");
local text=file.ReadAllText(path);

正确写法如下:

local path="C:/1.txt";
local file=luanet.import_type("System.IO.File");
local encoding=luanet.import_type("System.Text.Encoding"); local text
=file.ReadAllText(path,encoding.UTF8);

需指定编码格式。

 

2. DateTime.AddMinutes 在 ios 会找不到 AddMinutes 方法,但 AddSeconds 方法是可以的。

local DateTime = luanet.import_type("System.DateTime");
local startTime=DateTime.Parse("...");
--local endTime=startTime:AddMinutes(1);  -- 在 ios 上报红:找不到 AddMinutes 方法
local endTime=startTime:AddSeconds(60);

  

3. 在 ios 64位 release 版本上,使用 Color 会导致崩溃。

local uiLabel=this.transform:Find("Label"):GetComponent("UILabel");
uiLabel.color=Color.red;    -- 其中,Color是ulua提供的类,此行代码将导致崩溃

 

4. 诸如以下代码在 ios 64 位 release 版本上会 crash,其中 c# 代码为:

public class LoadCardHandler
{
        public GameObject Load(string name, Transform parent, int depth = 0, string defaultName = null)
        {
           ...
        }
}

然后 LoadCardHandler 类通过 wraps 的方式映射到 lua 中,在 lua 中使用如下:

local loader=LoadCardHandler.New();
loader:Load(m_activityItemConfig.ad_pic,m_advertisementParent,100,"11400008");  -- 这行代码将导致崩溃。

 

5. 诸如以下代码会在 ios 上报红:

local button=rootTrans:GetComponent("UIButton");
button.onClick:Clear();				-- 在ios上此方法会报错

  

6. 以下代码会导致 ios 上闪退:

LuaUtils.ShowLoadSystemAnim("LoadAndClose", DelegateFactory.Action(Conceal));

 

你可能感兴趣的:(Unity3d 开发之 ulua 在 IOS 上坑的总结)