local breakSocketHandle, debugXpCall = require("LuaDebugjit")("localhost", 7003) local timer = Timer.New(function() breakSocketHandle() end, 1, -1, false) timer:Start(); require "Core.init" json = require 'cjson' require 'FairyGUI' require 'Game.ControllerManager' require 'Game.ViewManager' require 'Game.DataManager' require "Game.ExtendManager" require "Game.ExtendHotupdate" require "TableData" MsgParser = require("MsgParser") Utils = Game.Utils PlayerPrefs = UnityEngine.PlayerPrefs RuntimePlatform = UnityEngine.RuntimePlatform Application = UnityEngine.Application Screen = UnityEngine.Screen ResourcesManager = taurus.unity.ResourcesManager -- require 'tolua.reflection' -- tolua.loadassembly('Assembly-CSharp') -- local BindingFlags = require 'System.Reflection.BindingFlags' local _game_info local panel = nil oldGameVersion = 2 --1 原始 2 老游戏新加功能 --主入口函数。从这里开始lua逻辑 function Main() --PlayerPrefs.DeleteKey('session_id') Application.targetFrameRate = 60 FairyGUI.UIConfig.buttonSound = FairyGUI.NAudioClip(ResourcesManager.LoadObject("base/common/sound/click.mp3", typeof(UnityEngine.AudioClip))) FairyGUI.UIConfig.defaultFont = "FZDaBiaoSong-B06S" FairyGUI.FontManager.RegisterFont(FairyGUI.DynamicFont.New("SIYUAN", "base/static/fonts/SIYUAN.TTF"), null) --FairyGUI.FontManager.RegisterFont(FairyGUI.DynamicFont.New("FZCuYuan-M03","base/static/fonts/FZCuYuan-M03.TTF"),null) --FairyGUI.FontManager.RegisterFont(FairyGUI.DynamicFont.New("HYFangLiJ","base/static/fonts/HYFangLiJ.ttf"),null) _game_info = json.decode(GameApplication.Instance.GameInfo) --_game_info["login_url"]="http://8.134.59.224:8101/" --pt(_game_info) debug_print = false --GetGameInfo("debug_print") if Application.platform == RuntimePlatform.WindowsEditor then debug_print = true end local NetManager = taurus.client.NetManager NetManager.debug_print = debug_print -- 网络延时8秒 NetManager.TIMEOUT_TIME = 10 UIPackage.AddPackage("base/common/ui/Common") panel = UIPackage.CreateObjectFromURL("ui://Common/UIPanel") GRoot.inst:AddChildAt(panel, 0) panel:MakeFullScreen() panel:AddRelation(GRoot.inst, RelationType.Size) --web网络API版本号 NetManager.VERSION = GetGameInfo("net_version") TimerManager.New() -- test:DynamicInvoke("222") --ExtendManager.Init() ControllerManager.Init() ViewManager.Init() ControllerManager.ChangeController(LoginController) ViewManager.ChangeView(ViewManager.View_Login) DataManager.AppVersion = GetGameInfo("app_version") get_gps() local timer = 0 local DSTweenManager = ds.tween.DSTweenManager UpdateBeat:Add(function() local deltaTime = Time.deltaTime DSTweenManager.Update(deltaTime) timer = timer + deltaTime if timer >= 60 then timer = 0 local ctr = ControllerManager.GetCurrenController() if DataManager.CurrenRoom and ctr.baseType == GameController then ctr:GetGPS() else get_gps() end end end) end function GetGameInfo(key) return _game_info[key] end function GetPlatform() return ResourcesManager.OS_Dir end function GetGameInfoPlatform(key) local p_key = GetPlatform() local _platfrom = _game_info[p_key] return _platfrom[key] end function BlurView(view, enabled) if enabled then local bf = FairyGUI.BlurFilter() bf.blurSize = 0.05 view.filter = bf else view.filter = null end end function ShareScreenShotWithOption(callback, index) --分享目标选择,包括分享截图到 微信/支付宝 local wx_win = BaseWindow.new("ui://Common/Win_WXShareWin", nil) wx_win._close_destroy = true wx_win._view:GetController("c1").selectedIndex = index or 3 local cb = function() if callback then callback() end end wx_win._view:GetChild("btn_wx_session").onClick:Add(function() wx_win:Destroy() ShareScreenShot(1, callback) end) wx_win:Show() end function ShareScreenShot(n, callback) local json_data = {} json_data["title"] = "湘北联赛" local mediaObject = {} mediaObject["path"] = Application.persistentDataPath mediaObject["filename"] = "screenshot" mediaObject["type"] = 1 json_data["mediaObject"] = mediaObject json_data["description"] = "一款现实中朋友约局休闲娱乐的场所!速度约朋友一起来玩吧!" json_data["scene"] = 0 local json_str = json.encode(json_data) TakeScreenShot.Take(function() -- 1微信 2支付宝 GameApplication.Instance:ShareLink(n or 1, json_str, nil) if callback then callback() end end) end function shareQRCodePicture(url, secene) ---- print(debug.traceback()) -- print(url) -- print(secene) local json_data = {} json_data["title"] = "湘北联赛" local mediaObject = {} local filename = "qrcode" .. DataManager.SelfUser.account_id -- print(Application.persistentDataPath) mediaObject["path"] = Application.persistentDataPath mediaObject["filename"] = filename mediaObject["type"] = 1 json_data["mediaObject"] = mediaObject json_data["description"] = "一款现实中朋友约局休闲娱乐的场所!速度约朋友一起来玩吧!" json_data["scene"] = secene -- print("json_data==================") local json_str = json.encode(json_data) pt(json_str) local tex2 = QRCodePicture.GenerateQRcode(url, 250, 250) local tex1 = ResourcesManager.LoadObject("base/lobby/bg/bg.png", typeof(UnityEngine.Texture2D)) filename = filename .. ".jpg" -- print("text2==========") -- print(tex2) -- print("text1==========") -- print(tex1) -- print("filename==========") -- print(filename) QRCodePicture.CombanitePicture(tex1, tex2, 393, 1334 - 802 - 250, filename) GameApplication.Instance:ShareLink(1, json_str, nil) end function ShareChatRoom(room_id, share_time, round, game_name, group_id, player_list, _root_view, play_name) end function UISetController(root, controller_name, gear_display, selectedIndex) local ctr = root:GetController(controller_name) local gear = gear_display:GetGear(0) gear.controller = ctr gear.pages = { ctr:GetPageId(selectedIndex) } gear_display:HandleControllerChanged(ctr) end local bg_url = nil function LoadGameBg(url, main_view) local win_mode = main_view:GetChild("win_mode") win_mode:RemoveChildren(0, -1, true) local tex_bg = ResourcesManager.LoadObjectByGroup(url .. ".png", typeof(UnityEngine.Texture), url) -- print("===========================mainbg") -- print(url..".png",typeof(UnityEngine.Texture), url) local bg = GImage() bg.texture = FairyGUI.NTexture(tex_bg) bg.width = win_mode.width bg.height = win_mode.height bg:AddRelation(win_mode, RelationType.Size) win_mode:AddChild(bg) -- 卸载资源 if url ~= bg_url and bg_url then ResourcesManager.UnLoadGroup(bg_url) end bg_url = url end function AddPanel(child) child:MakeFullScreen() child:AddRelation(GRoot.inst, RelationType.Size) panel:AddChild(child) end function AddPanelAt(child, index) child:MakeFullScreen() child:AddRelation(GRoot.inst, RelationType.Size) panel:AddChildAt(child, index) end function AddPanelCenter(child) panel:AddChild(child) child:Center(true) end --重启游戏 function RestartGame() DSTweenManager.ClearTween() panel:Dispose() coroutine.stopAll() BaseWindow.DestroyAll() GameApplication.Instance:RestartGame() end --场景切换通知 function OnLevelWasLoaded(level) Time.timeSinceLevelLoad = 0 end --程序切到后台 function OnApplicationPause() -- ViewUtil.CloseModalWait() ViewManager.OnApplicationPause() end --程序从后台切回 function OnApplicationActive() ViewManager.OnApplicationActive() end function pt(...) if debug_print then local arg = { ... } local has = false for _, v in pairs(arg) do if v and type(v) == "table" then has = true break end end if not has then -- print(...) end local content = "" for _, v in pairs(arg) do if v == "table" then content = content .. tostring(v) .. "\n" else content = content .. "==>[T]:" .. LuaPrint(v, limit), debug.traceback() .. "\n" end -- print(content) end end end function LuaPrint(lua_table, limit, indent, step) step = step or 0 indent = indent or 0 local content = "" if limit ~= nil then if step > limit then return "..." end end if step > 10 then return content .. "..." end if lua_table == nil then return "nil" end if type(lua_table) == "userdata" or type(lua_table) == "lightuserdata" or type(lua_table) == "thread" then return tostring(lua_table) end if type(lua_table) == "string" or type(lua_table) == "number" then return "[No-Table]:" .. lua_table end for k, v in pairs(lua_table) do if k ~= "_class_type" then local szBuffer = "" Typev = type(v) if Typev == "table" then szBuffer = "{" end local szPrefix = string.rep(" ", indent) if Typev == "table" and v._fields then local kk, vv = next(v._fields) if type(vv) == "table" then content = content .. "\n\t" .. kk.name .. "={" .. LuaPrint(vv._fields, 5, indent + 1, step + 1) .. "}" else content = content .. "\n\t" .. kk.name .. "=" .. vv end else if type(k) == "table" then if k.name then if type(v) ~= "table" then content = content .. "\n" .. k.name .. "=" .. v else content = content .. "\n" .. k.name .. " = list:" local tmp = "\n" for ka, va in ipairs(v) do tmp = tmp .. "#" .. ka .. "_" .. tostring(va) end content = content .. tmp end end elseif type(k) == "function" then content = content .. "\n fun=function" else formatting = szPrefix .. tostring(k) .. " = " .. szBuffer if Typev == "table" then content = content .. "\n" .. formatting content = content .. LuaPrint(v, limit, indent + 1, step + 1) content = content .. "\n" .. szPrefix .. "}," else local szValue = "" if Typev == "string" then szValue = string.format("%q", v) else szValue = tostring(v) end content = content .. "\n" .. formatting .. (szValue or "nil") .. "," end end end end end return content end function printlog(...) if debug_print then -- print(...) end end