Пример #1
0
    public static IEnumerator LoadResourceById(int resourceId, Action <List <Sprite> > callBack)
    {
        var d = TableUtility.GetDeploy <TextureResourceDeploy>(resourceId);

        if (d == null)
        {
            Debug.LogError("资源ID在表中找不到,ID:" + resourceId);
            yield break;
        }


        //找不到资源则加载并缓存
        Texture2D texture;

        if (!_texturesCache.TryGetValue(d.texture, out texture))
        {
            yield return(LoadTexture(d.texture, tex =>
            {
                texture = tex;
            }));

            _texturesCache[d.texture] = texture;
        }

        var sprites = LoadSpriteGroup(texture, d.startX, d.startY, d.width, d.height, d.xCount, d.yCount);

        callBack(sprites);
    }
Пример #2
0
    //创建角色 static
    public static IEnumerator Create(int playerId, Action <Player> callBack)
    {
        var deploy = TableUtility.GetDeploy <PlayerDeploy>(playerId);

        var playerObject = new GameObject(deploy.name);

        playerObject.SetActiveSafe(false);
        playerObject.transform.SetParent(null);
        yield return(Yielders.Frame);

        //创建显示模型
        var model      = new GameObject(deploy.name + "_model");
        var mainSprite = model.AddComponent <SpriteRenderer>();

        mainSprite.sortingOrder = SortingOrder.Player;
        mainSprite.material     = new Material(GameSystem.DefaultRes.CommonShader);
        model.transform.SetParent(playerObject.transform, false);
        yield return(Yielders.Frame);


        //设置贴图
        var player = playerObject.AddComponent <Player>();

        for (int i = 0; i < deploy.resoureIds.Length; i++)
        {
            var resourceId = deploy.resoureIds[i];
            yield return(TextureUtility.LoadResourceById(resourceId, sprites =>
            {
                player.SpriteDic[(PlayerMoveStyle)i] = sprites;
            }));
        }
        yield return(Yielders.Frame);


        //Collider
        var collider = playerObject.AddComponent <CircleCollider2D>();

        collider.radius = deploy.radius;

        //判定点
        var pointObj = ResourceMgr.LoadImmediately("player/point.prefab");
        var point    = ResourceMgr.Instantiate(pointObj);

        point.transform.SetParent(playerObject.transform, false);
        var script = point.GetComponent <SlowPoint>();

        player.Init(mainSprite, script, deploy);
        playerObject.SetActiveSafe(true);
        callBack(player);
        player.AfterInit();
    }
Пример #3
0
    public static IEnumerator Load(int levelId, Action <StageBase> finishAction = null)
    {
        var deploy = TableUtility.GetDeploy <StageDeploy>(levelId);

        if (string.IsNullOrEmpty(deploy.resource))
        {
            if (finishAction != null)
            {
                finishAction.Invoke(null);
            }
            Debug.LogError(string.Format("sceneId url : {0} not exist", deploy.resource));
            yield break;
        }

        yield return(LoadImpl(deploy, finishAction));
    }
Пример #4
0
    public static void Show(int bgmId)
    {
        var soundDeploy = TableUtility.GetDeploy <SoundDeploy>(bgmId);

        if (soundDeploy == null)
        {
            return;
        }
        if (string.IsNullOrEmpty(soundDeploy.name))
        {
            return;
        }

        UiManager.Show <UIBgmTip>(view =>
        {
            view.Refresh(soundDeploy.name);
        });
    }
Пример #5
0
    //创建怪物
    public static IEnumerator Create(int enemyId, float bornX = 0f, float bornY = 150f)
    {
        var deploy = TableUtility.GetDeploy <EnemyDeploy>(enemyId);

        var gameObj = new GameObject(deploy.name);

        gameObj.SetActiveSafe(false);
        gameObj.transform.SetParent(null);
        yield return(Yielders.Frame);

        //创建显示模型
        var model      = new GameObject(deploy.name + "_model");
        var mainSprite = model.AddComponent <SpriteRenderer>();

        mainSprite.sortingOrder = SortingOrder.Enemy;
        mainSprite.material     = new Material(GameSystem.DefaultRes.CommonShader);
        model.transform.SetParent(gameObj.transform, false);
        yield return(Yielders.Frame);

        //设置贴图
        var enemy = deploy.isBoss ? gameObj.AddComponent <Boss>() : gameObj.AddComponent <Enemy>();

        for (int i = 0; i < deploy.resoureIds.Length; i++)
        {
            var resourceId = deploy.resoureIds[i];
            yield return(TextureUtility.LoadResourceById(resourceId, sprites =>
            {
                enemy.SpriteDic[(EnemyMoveStyle)i] = sprites;
            }));
        }

        //Collider
        var collider = gameObj.AddComponent <CircleCollider2D>();

        collider.radius    = deploy.radius;
        collider.isTrigger = true;

        //init
        enemy.Material           = mainSprite.material;
        enemy.transform.position = Vector2Fight.New(bornX, bornY);
        enemy.Init(mainSprite, deploy);
        gameObj.SetActiveSafe(true);
    }
Пример #6
0
    public void AddSupport()
    {
        var deploy = TableUtility.GetDeploy <PlayerSupportDeploy>(_master.Deploy.supprotId);

        if (deploy == null)
        {
            Debug.LogError("僚机ID不存在:" + _master.Deploy.supprotId);
            return;
        }

        var gameObj = new GameObject("support");

        gameObj.transform.SetParent(null, false);
        gameObj.transform.localScale = _master.transform.localScale;
        gameObj.transform.position   = _master.transform.position;

        TextureEffectFactroy.CreateEffect(deploy.idleEffectId, SortingOrder.PlayerSupport, effect =>
        {
            effect.transform.Bind(gameObj.transform);
            var script = gameObj.AddComponent <PlayerSupport>();
            script.Init(deploy, effect.gameObject);
            _supportList.Add(script);
        });
    }