Exemplo n.º 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;
    }
Exemplo n.º 2
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;
    }