gmhevinci / MotionFramework

MotionFramework is unity3d game framework.
MIT License
621 stars 116 forks source link

How can we load all assets by Type in a folder #5

Closed takaaptech closed 3 years ago

takaaptech commented 3 years ago

Hi @gmhevinci I have a folder that has some Scriptable files inside. How can I use ResourceManager to load all assets by Type inside the folder? (Maybe the same of Unity API: public Object[] LoadAllAssets(Type type);) I try ResourceManager.Instance.LoadSubAssetsAsync but it not works, maybe it only uses for Sprite and SpriteAtlas Thank you so much!

gmhevinci commented 3 years ago

There is no concept of "AssetBundle" in the game logic. Depending on the pack rules, the asset object may be pack into any Bundle. 在业务逻辑层并没有“AssetBundle”的概念,因为根据打包规则,资源对象可能被打进任意AB文件里。在业务逻辑层,我们只需要关心资源对象,至于这个资源对象在哪个AB里,我们并不需要知道。

takaaptech commented 3 years ago

Hi @gmhevinci Thank you for the detailed explanation, I want to get all the blocks asset in a folder like this code (Just example): ` IAssetBundle ab = m_Loader.LoadAssetBundle("data/blocks"); yield return ab.AsyncHandler; AsyncAssets assets = ab.LoadAllAssets(); while (!assets.IsDone) { yield return null; }

Object[] blocks = assets.Assets;

for (int i = 0; i < blocks.Length; i++) { Block block = blocks[i] as Block; m_BlocksMap.Add(block.Type, block); } `

How can we get the block array with MotionFramework? Thank you!

gmhevinci commented 3 years ago

I think you need a list of files that be write in Excel or a text config can be generated using a tools.

Look like ConfigManager.cs

public IEnumerator LoadConfigs(List<LoadPair> loadPairs)
{
    for(int i=0; i< loadPairs.Count; i++)
    {
        Type type = loadPairs[i].ClassType;
        string location = loadPairs[i].Location;
        AssetConfig config = LoadConfig(type, location);
        yield return config;
    }
}
takaaptech commented 3 years ago

@gmhevinci Thank you so much! That should be easy to do!