// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created : 2019-05-20
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
namespace G
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using F;
using F.Item;
using UnityEngine;
public class ItemGroupHelper : IItemGroupHelper
{
private readonly Dictionary _itemClasses = new Dictionary();
private Dictionary _itemAssets;
public void AddClass(string className)
{
var t = typeof(T);
string assetName = (string)t.GetField("ASSET_NAME").GetValue(null);
_itemClasses.Add(t, assetName);
}
public void Begin()
{
_itemAssets = new Dictionary();
}
///
///ItemProxy代理类所有注册类型的配置数据
///
///
/////
///
public bool Load(List result) where T : IItem
{
var groupType = typeof(T);
if (_itemClasses.TryGetValue(groupType, out string assetName))
if (_itemAssets.TryGetValue(assetName, out byte[] jsonBytes))
{
var assetDict = jsonBytes.ToJsonTable();
groupType.GetMethod("LoadAll").Invoke(null, new object[] { assetDict, result });
return true;
}
return false;
}
public void End()
{
_itemAssets = null;
Resources.UnloadUnusedAssets();
}
System.Diagnostics.Stopwatch _loadSw;
public async Task BeginAsync()
{
_loadSw = System.Diagnostics.Stopwatch.StartNew();
var asyncOp = AssetProxy.Instance.GetAssetsAsync("config");
var textList = await asyncOp.Task;
_itemAssets = new Dictionary(textList.Count);
foreach (var text in textList)
{
_itemAssets[text.name] = text.bytes;
}
AssetProxy.Instance.Release(asyncOp);
LanguageProxy.Instance.LoadBytes(_itemAssets["language"]);
}
public async Task LoadAsync(List result) where T : IItem
{
var groupType = typeof(T);
if (_itemClasses.TryGetValue(groupType, out string assetName))
if (_itemAssets.TryGetValue(assetName, out byte[] jsonBytes))
{
var assetDict = jsonBytes.ToJsonTable();
groupType.GetMethod("LoadAll").Invoke(null, new object[] { assetDict, result });
return true;
}
//await Task.Yield();
return false;
}
public async Task EndAsync()
{
_itemAssets = null;
_loadSw.Stop();
//#if UNITY_EDITOR
Debug.Log("gsw " + _loadSw.ElapsedMilliseconds);
//#endif
await Task.Yield();
}
///
///
///
///
///
public void LoadCompleted(List result) where T : IItem
{
foreach (var item in result)
{
(item as Item).Init();
}
}
}
}