---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by Administrator.
--- DateTime: 2018/6/15 15:43
---
--local util = require("xlua.util")

local this={}
this.YKSupportLua = YKSupportLua
this.LuaSceneBase = YKSupportLua.LuaSceneBase
this.LuaWindow = YKSupportLua.LuaWindow
this.LuaStateBase = YKSupportLua.LuaStateBase
this.LuaTaskBase = YKSupportLua.LuaTaskBase
this.LuaUBBParser = YKSupportLua.LuaUBBParser
this.LuaMode = YKSupportLua.LuaMode
this.EventDispatcherNode = EventDispatcherNode
this.EventListenerDele = EventDispatcherNode.EventListenerDele
this.EventDef = EventDef
this.TweenUtils = TweenUtils
this.EventData = EventData
this.EventDataLua = EventDataLua
this.UIMgr = UIMgr
this.UIMgr = SceneBase
this.BaseUI = BaseUI
this.ResMgr = ResMgr
this.ABMgr = ABMgr
this.Net = Net
this.GameServerMsg = GameServerMsg
this.ServerResponseEvent = ServerResponseEvent
this.ServerErrorEvent = ServerErrorEvent
this.LoadGroupProgress = LoadGroupProgress
this.GroupProgress = GroupProgress
this.ResGroupLoadError = ResGroupLoadError
this.ResGroupLoadError = ResLoadGroupEvent
this.ResGroupLoadError = GamUtil
this.GameObject = UnityEngine.GameObject
this.Transform = UnityEngine.Transform;
this.GameMode = GameMode;
this.AsynTask = AsynTask;
this.SceneLoadTask = SceneLoadTask;
this.SceneMgr = SceneMgr;
this.UnitySceneMgr = UnityEngine.SceneManagement.SceneManager;
this.ComUtil = ComUtil;
this.Application = UnityEngine.Application
this.RuntimePlatform = UnityEngine.RuntimePlatform
this.Vector3 = UnityEngine.Vector3;
this.GameFlag = GameFlag;
this.Color = Color
this.SoundMgr = SoundMgr;

this.BGMMgr = BGMMgr;
this.Input = UnityEngine.Input;
this.Initialization = Initialization;
this.LuaMgr = LuaMgr;
this.PlayerPrefs = UnityEngine.PlayerPrefs;
this.Ray = Ray;
this.RaycastHit = RaycastHit;
this.Screen = UnityEngine.Screen
this.Physics = UnityEngine.Physics
this.MeshFilter = UnityEngine.MeshFilter
this.Mesh = UnityEngine.Mesh
this.Animator = UnityEngine.Animator
this.AppConst = AppConst
this.LayerMask = LayerMask
this.Log = Debugger
this.SystemInfo = UnityEngine.SystemInfo
this.Material = UnityEngine.Material
this.Texture2D = UnityEngine.Texture2D
this.ListLoadABTask = System.Collections.Generic.List_LoadABTask
this.ParallelTask = ParallelTask
this.TaskBase = TaskBase
this.ListTaskBase = System.Collections.Generic.List_TaskBase
this.StateMachine = StateMachine
this.RuntimePlatform = UnityEngine.RuntimePlatform
this.LocalGameCfgData = LocalGameCfgData
this.LocalGameCfgData = GameCfgMgr
this.Handheld = UnityEngine.Handheld
this.DownAPKTask = DownAPKTask
this.WXConstant = WXConstant
this.TextAsset = UnityEngine.TextAsset
this.EventListenerMgr = EventListenerMgr
this.KeyCode = UnityEngine.KeyCode
this.HotUpdateRessMgr = HotUpdateRessMgr
this.LoadingUI = LoadingUI

function this.LuaTaskBase_class(base)
    return csClass(base,this.LuaTaskBase)
end

function this.LuaUBBParser_Class(base)

    return csClass(base,this.LuaUBBParser)
end

function this.LuaStateBase_class(base)
    return csClass(base,this.LuaStateBase)
end

function this.wind_class(base)
    return csClass(base,this.LuaWindow)
end

function this.mode_class(base)
    return csClass(base,this.LuaMode)
end

function string.StartsWith(str, strs)
    local num = string.len(strs)
    if string.len(str) >= num then
        local subStr = string.sub(str, 1, num);
        return subStr == strs;
    else
        return false;
    end
end

function string.EndsWith(str, strs)
    local num = string.len(strs)
    --local allNum = string.len();

    if string.len(str) >= num then
        local subStr = string.sub(str, 1, num * -1);
        return subStr == strs;
    else
        return false;
    end
end
local fgui_internal = {}
--这里建立一个c# delegate到lua函数的映射，是为了支持self参数，和方便地进行remove操作
fgui_internal.EventDelegates = {}
setmetatable(fgui_internal.EventDelegates, {__mode = "k"})
function fgui_internal.GetDelegate(func, obj, createIfNone, delegateType)
    local mapping
    if obj~=nil then
        mapping = obj.EventDelegates
        if mapping==nil then
            mapping = {}
            setmetatable(mapping, {__mode = "k"})
            obj.EventDelegates = mapping
        end
    else
        mapping = fgui_internal.EventDelegates
    end

    local delegate = mapping[func]

    if createIfNone and delegate == nil then
        local realFunc
        if obj ~= nil then
            realFunc = function(context)
                return func(obj, context)
            end
        else
            realFunc = func
        end
        delegateType = delegateType or FairyGUI.EventCallback1
        delegate = delegateType(realFunc)
        mapping[func] = delegate
    end

    return delegate
end
function this.Init()

    local EventListener_mt = getmetatable(this.EventDispatcherNode)
    local oldListenerAdd = rawget(EventListener_mt, 'AttachListener');

    local oldListenerRemove = rawget(EventListener_mt, 'DetachListener');

    local function ListenerAdd(listener, typeid, func, obj, priority, dispatchOnce)
        dispatchOnce = dispatchOnce or false;
        priority = priority or 0;
        typeid = typeid or "";
        local delegate = fgui_internal.GetDelegate(func, obj, true, this.EventListenerDele)
        oldListenerAdd(listener, typeid, delegate, priority, dispatchOnce);
    end

    local function ListenerRemove(listener, type, func, obj)
        local delegate = fgui_internal.GetDelegate(func, obj, false)
        if delegate ~= nil then
            oldListenerRemove(listener, type, delegate)
        end
    end

    rawset(EventListener_mt, 'AttachListener', ListenerAdd)
    rawset(EventListener_mt, 'DetachListener', ListenerRemove)
end

function this.DOTweenFloat( _start, _end, _duration, _update, _delay, _ease, _onComplete)
    local tween = this.TweenUtils.TweenFloat(_start, _end, _duration, _update)
    if _delay ~= nil then
        this.TweenUtils.SetDelay(tween, _delay)
    end
    if _ease ~= nil then
        this.TweenUtils.SetEase(tween, _ease)
    end
    if _onComplete ~= nil then
        this.TweenUtils.OnComplete(tween, _onComplete)
    end
end

function this.TweenVector2( _start, _end, _duration, _update, _delay, _ease, _onComplete)
    local tween = this.TweenUtils.TweenVector2(_start, _end, _duration, _update)
    if _delay ~= nil then
        this.TweenUtils.SetDelay(tween, _delay)
    end
    if _ease ~= nil then
        this.TweenUtils.SetEase(tween, _ease)
    end
    if _onComplete ~= nil then
        this.TweenUtils.OnComplete(tween, _onComplete)
    end
end

function this.TweenVector3( _start, _end, _duration, _update, _delay, _ease, _onComplete)
    local tween = this.TweenUtils.TweenVector3(_start, _end, _duration, _update)
    if _delay ~= nil then
        this.TweenUtils.SetDelay(tween, _delay)
    end
    if _ease ~= nil then
        this.TweenUtils.SetEase(tween, _ease)
    end
    if _onComplete ~= nil then
        this.TweenUtils.OnComplete(tween, _onComplete)
    end
end

function this.Scene_class(base)
    return csClass(base,this.LuaSceneBase)
end

---@param com FairyGUI.GComponent
---@return SerializationComsInfo
function this.SerializationComs(com)
    local infos = {}
    infos.objs = {}
    infos.ctrls = {}
    infos.OnBtnClick = nil

    for i = 1, com.numChildren, 1 do
        local num = i - 1
        local obj = com:GetChildAt(num)
        infos.objs[obj.name] = obj
        if string.StartsWith(obj.name, "Btn") then
            obj.onClick:Clear()
            obj.onClick:Add(function()
                if infos.OnBtnClick then
                    infos.OnBtnClick(obj)
                end
            end)
        end
    end

    ---@type System.Collections.Generic.List<FairyGUI.Controller>
    local ctrls = com.Controllers;
    local ctrlCount = ctrls.Count;
    if ctrlCount > 0 then
        for i = 1, ctrlCount, 1 do
            local num = i - 1;
            local ctrl = com:GetControllerAt(num);
            infos.ctrls[ctrl.name] = ctrl;
        end
    end
    return infos
end
return this
