using System;
using System.Collections;
using System.Collections.Generic;
using Core.AssetLoadTool.Asset;
using Fort23.Core;
using Fort23.Mono;
using Fort23.UTool;
using GameLogic.Combat;
using GameLogic.Combat.CombatTool;
using UnityEngine;
using UnityEngine.UI;
using Utility.CTween;
using Utility.UITool;

public class GameApplction : MonoBehaviour
{
    public BundleLoadType BundleLoadType;
    public string h5Url;
    private Entity _root;
    private Entity _scene;

    private async void Start()
    {
        await InitGameApplication();
        Debug.Log("初始化完成");
    }

    private async CTask InitGameApplication()
    {
        _scene = new Scene();
        _root = new Entity();
        _root.Parent = _scene;

        _root.AddComponent<TimerComponent>();
        _root.AddComponent<CoroutineLockComponent>();
        AssetBundleLoadManager.Instance.BundleLoadType = BundleLoadType;
        AssetBundleLoadManager.Instance.h5Url = h5Url;
        await AssetBundleLoadManager.Instance.InitAssetsManager(null);

        await ConfigComponent.Instance.Preload(true);
    
        UGUIPackLoad uguiPackLoad = new UGUIPackLoad();
        UGUIPackManager.Instance.SetIUGUIPackLoad(uguiPackLoad);
        await uguiPackLoad.InitPack();
        _root.AddComponent<StaticUpdater>();
        _root.AddComponent<UIManager, Transform>(transform);

        await UIManager.Instance.InitUI();
        CustomTweenManager.Init();

        CombatDrive.Instance.AddCombatController(new CombatController());

    }

    public void Update()
    {
        EventSystem.Instance.Update();
        AssetBundleLoadManager.Instance.UpdateBundle();
        TimeHelper.clientFrame = TimeHelper.ClientFrame() + (long)(Time.deltaTime * 1000);
    }

    public void LateUpdate()
    {
        EventSystem.Instance.LateUpdate();
    }
}