private static int SetSprite(ILuaState lua) { if (lua.IsFunction(4)) { var sp = LibUnity.FindCom <UISprite>(lua); if (sp) { var texPath = lua.ChkString(2); var func = lua.ToLuaFunction(4); var param = lua.ToAnyObject(5); sp.Load(texPath, (o, p) => { var L = func.GetLuaState(); var top = func.BeginPCall(); L.PushLightUserData(o); L.PushAnyObject(p); func.PCall(top, 2); func.EndPCall(top); func.Dispose(); }, param); } return(0); } var obj = lua.ToAnyObject(2); var path = obj as string; if (path != null) { var sp = LibUnity.FindCom <UISprite>(lua); if (sp) { if (path.StartsWith("Atlas")) { sp.spritePath = path; } else { sp.spriteName = path; } } return(0); } var sprite = obj as Sprite; if (sprite) { var img = LibUnity.FindCom <Image>(lua); if (img) { img.sprite = obj as Sprite; } return(0); } LogMgr.W("SetSprite: 未知的Sprite={0}", obj); return(0); }
private static int SetText(ILuaState lua) { var text = LibUnity.FindCom <Text>(lua); if (text) { text.text = lua.ToLuaString(2); } return(0); }
private static int SetTexture(ILuaState lua) { if (lua.IsFunction(4)) { var tex = LibUnity.FindCom <UITexture>(lua); if (tex) { var texPath = lua.ChkString(2); var func = lua.ToLuaFunction(4); var param = lua.ToAnyObject(5); tex.Load(texPath, (o, p) => { var L = func.GetLuaState(); var top = func.BeginPCall(); L.PushLightUserData(o); L.PushAnyObject(p); func.PCall(top, 2); func.EndPCall(top); func.Dispose(); }, param); } return(0); } var obj = lua.ToAnyObject(2); var path = obj as string; if (path != null) { var tex = LibUnity.FindCom <UITexture>(lua); if (tex) { tex.texturePath = path; } return(0); } var texture = obj as Texture; if (texture) { var img = LibUnity.FindCom <RawImage>(lua); if (img) { img.texture = texture; } return(0); } LogMgr.W("SetTexture: 未知的Texture={0}", obj); return(0); }
private static int SetPhoto(ILuaState lua) { var tex = LibUnity.FindCom <UITexture>(lua); string name = lua.ChkString(2); var funcRef = lua.ToLuaFunction(3); ZFrame.Asset.DelegateObjectLoaded onLoaded = null; if (funcRef != null) { onLoaded = (o, p) => { LogMgr.D("loaded {0}, {1}", o, p); funcRef.Invoke(o, p); funcRef.Dispose(); var disposer = p as System.IDisposable; if (disposer != null) { disposer.Dispose(); } }; } SDKMgr.Instance.OnLoadPhoto(tex, name, onLoaded); return(0); }