Exemple #1
0
    /// <summary>
    /// 创建敌人
    /// </summary>
    /// <param name="uid"></param>
    /// <param name="spawnPos"></param>
    /// <param name="type">敌人的种类</param>
    /// <param name="behavior">对应敌人种类的行为</param>
    /// <param name="speed"></param>
    /// <returns></returns>
    public GameEntity CreateEnemy(ulong uid, Vector2 spawnPos, EnemyType type, EnemyBehavior behavior, float speed = 0)
    {
        CheckDuplicateEntity(uid);
        GameEntity gameEntity = context.CreateEntity();

        gameEntity.AddUID(uid);
        gameEntity.AddUnitType(UnitType.Enemy);
        gameEntity.AddPosition(spawnPos);
        gameEntity.AddRotation(Quaternion.identity);

        gameEntity.AddEnemyType(type);
        gameEntity.AddEnemyState(EnemyState.None);
        gameEntity.AddEnemyBehavior(behavior);


        gameEntity.isDestroyed = false;

        NormalEnemyInfo enemyInfo = configService.GetEnemyInfo();

        gameEntity.AddEnemyInfo(enemyInfo);
        //如果需要动态更改则动态改 否则读配置
        if (speed != 0)
        {
            gameEntity.AddSpeed(speed);
        }
        else
        {
            gameEntity.AddSpeed(enemyInfo.speed);
        }

        gameEntity.AddAsset("Enemy");

        return(gameEntity);
    }
Exemple #2
0
    public void ReplaceEnemyInfo(NormalEnemyInfo newValue)
    {
        var index     = GameComponentsLookup.EnemyInfo;
        var component = CreateComponent <EnemyInfoComponent>(index);

        component.value = newValue;
        ReplaceComponent(index, component);
    }