Пример #1
0
    public IEnumerator load()
    {
        ResourceLoadTaskGroup group = new ResourceLoadTaskGroup();

        foreach (TileCfg tileCfg in TileCfg.dataList)
        {
            ResourceLoadTask task = new ResourceLoadTask();
            task.path = tileCfg.resourcePath;
            task.name = tileCfg.resourceName;
            group.addTask(task);
        }
        yield return(ResourceLoader.LoadGroupAsync(group));

        for (int i = 0; i < TileCfg.dataList.Count; i++)
        {
            ResourceLoadTask t = group.getTaskList()[i];
            textures.Add(t.asset as Texture2D);
            Tileset tileset = new Tileset();
            tileset.init(t.asset as Texture2D, TileLength);
            tilesets.Add(TileCfg.dataList[i].id, tileset);
        }
        ResourceLoadTask taskMapTilePrefab = new ResourceLoadTask();

        taskMapTilePrefab.path = PrefabCfg.get(2).resourcePath;
        taskMapTilePrefab.name = PrefabCfg.get(2).resourceName;
        yield return(ResourceLoader.LoadAssetAsync(taskMapTilePrefab));

        mapTilePrefab = taskMapTilePrefab.asset as GameObject;
    }
Пример #2
0
    //private static IEnumerator loadFromAssetaBundleAsync(ResourceLoadTask task)
    //{
    //    task.name = task.name.Trim().ToLower();
    //    task.path = task.path.Trim().ToLower();
    //    Dictionary<string, LoadedAssetBundle> loadedAssetBundles = new Dictionary<string, LoadedAssetBundle>();
    //    string key =  task.path + "|" + task.name.ToLower();

    //    if (!resources.ContainsKey(key))
    //    {
    //        Debug.LogError("*****" + key);
    //        foreach (var VARIABLE in resources.Keys)
    //        {
    //            Debug.LogError(VARIABLE);
    //        }
    //    }

    //    //先加载依赖资源
    //    foreach (AssetPathAndName assetPathAndName in resources[key])
    //    {
    //        yield return loadFromAssetaBundle(assetPathAndName.path, assetPathAndName.name, loadedAssetBundles);
    //    }
    //    //加载资源
    //    if (loadedAssetBundles.ContainsKey(task.path))
    //    {
    //        task.resource = loadedAssetBundles[task.path].assetBundle.LoadAsset(task.name);
    //    }
    //    else
    //    {
    //        WWW asset = new WWW(streamingAssetsPathURL   + task.path + "." + ResourceVariant);
    //        yield return asset;
    //        task.resource =  asset.assetBundle.LoadAsset(task.name.ToLower());
    //        asset.assetBundle.Unload(false);
    //    }
    //    //AssetBundleCreateRequest request= AssetBundle.LoadFromFileAsync(Application.dataPath + "/StreamingAssets/" + task.path + "." + ResourceVariant);
    //    //while (!request.isDone)
    //    //{
    //    //    yield return true;
    //    //}
    //    //AssetBundle bundle = request.assetBundle;
    //    foreach (LoadedAssetBundle loadedAssetBundle in loadedAssetBundles.Values)
    //    {
    //        loadedAssetBundle.assetBundle.Unload(false);
    //    }
    //    task.finished = true;
    //}

    //private string getKey(ResourceLoadTask task)
    //{
    //    task.name = task.name.Trim().ToLower();
    //    task.path = task.path.Trim().ToLower();
    //    string key = task.path + "|" + task.name;
    //}
    private static IEnumerator loadGroupFromAssetBundleAsync(ResourceLoadTaskGroup group)
    {
        group.state = STATE_LOADING;
        foreach (var task in group.getTaskList())
        {
            yield return(loadFromAssetaBundleAsync(task));

            group.progress++;
        }
        //foreach (LoadedAssetBundle loadedAssetBundle in loadedAssetBundles.Values)
        //{
        //    loadedAssetBundle.assetBundle.Unload(false);
        //}
        group.state = ResourceLoader.STATE_DONE;
    }
Пример #3
0
    private static IEnumerator loadGroupFromResourcesDirAsync(ResourceLoadTaskGroup group)
    {
        group.state = STATE_LOADING;
        foreach (var task in group.getTaskList())
        {
            yield return(loadFromResourcesDirAsync(task));

            ////加载resources文件夹里的文件,不能有后缀。
            //ResourceRequest resourceRequest = Resources.LoadAsync(task.path + "/" + task.name.Split('.')[0]);
            //while (!resourceRequest.isDone)
            //{
            //    yield return true;
            //}
            //task.asset = resourceRequest.asset;
            //task.state = STATE_DONE;
            group.progress++;
        }
        group.state = STATE_DONE;
    }
Пример #4
0
    public IEnumerator loadUnitType(int unitTypeId, LoaderResult result)
    {
        if (id2UnitType.ContainsKey(unitTypeId))
        {
            result.isDone = true;
            result.asset  = id2UnitType[unitTypeId];
            yield break;
        }
        UnitTypeCfg unitTypeCfg = UnitTypeCfg.get(unitTypeId);
        int         spriteCfgId = unitTypeCfg.spritId;

        if (!id2CharacterSprite.ContainsKey(spriteCfgId))
        {
            CharacterSpriteCfg spriteCfg = CharacterSpriteCfg.get(spriteCfgId);
            CharacterSprite    sprite    = new CharacterSprite();
            sprite.animations[(int)UnitAnimation.Run] = new CharacterAnimation();
            for (int i = 0; i < 8; i++)
            {
                int spriteAnimId = spriteCfg.runAnim[i];

                if (spriteAnimId == 0)
                {
                    sprite.animations[(int)UnitAnimation.Run].anim[i] = null;
                    continue;
                }
                if (!id2FrameAnimation.ContainsKey(spriteAnimId))
                {
                    FrameAnimationCfg     spriteAnimCfg = FrameAnimationCfg.get(spriteAnimId);
                    List <Sprite>         anim          = new List <Sprite>();
                    ResourceLoadTaskGroup group         = new ResourceLoadTaskGroup();
                    for (int j = spriteAnimCfg.nBegin; j <= spriteAnimCfg.nEnd; j++)
                    {
                        ResourceLoadTask task = new ResourceLoadTask();
                        task.path = spriteAnimCfg.resourcePath;
                        string resourceName = j + ".0.png";
                        task.name = resourceName;
                        group.addTask(task);
                    }
                    yield return(ResourceLoader.LoadGroupAsync(group));

                    for (int j = 0; j <= spriteAnimCfg.nEnd - spriteAnimCfg.nBegin; j++)
                    {
                        Texture2D texture2d = group.getTaskList()[j].asset as Texture2D;
                        Sprite    s         = Sprite.Create(texture2d,
                                                            new Rect(0, 0, texture2d.width, texture2d.height),
                                                            new Vector2(0.5f, 0),
                                                            spriteAnimCfg.fixelsPerUnit
                                                            );

                        anim.Add(s);
                    }
                    FrameAnimation frameanimation = new FrameAnimation();
                    frameanimation.frames           = anim;
                    frameanimation.frameRate        = spriteAnimCfg.frameRate;
                    id2FrameAnimation[spriteAnimId] = frameanimation;
                }

                sprite.animations[(int)UnitAnimation.Run].anim[i] = id2FrameAnimation[spriteAnimId].frames;
            }
            sprite.frameRate = spriteCfg.frameRate;
            id2CharacterSprite[spriteCfgId] = sprite;
        }
        UnitType unitType = new UnitType();

        unitType.sprite         = id2CharacterSprite[spriteCfgId];
        result.isDone           = true;
        result.asset            = unitType;
        id2UnitType[unitTypeId] = unitType;
        yield break;
    }