Exemple #1
0
    public Tank CreateTank(TankSyncInfo syncInfo, int playerId = 0)
    {
        GamePlayerController player;

        GameManager.AllPlayers.TryGetValue(playerId, out player);

        GameObject obj  = GameObjectPool.instance.Instantiate(unitPrefab);
        TankNode   node = obj.GetComponent <TankNode>();
        Tank       unit = obj.GetComponent <Tank>();

        //TankController ctrl = obj.GetComponent<TankController>();

        ResourceManager.instance.LoadUnitModel(syncInfo.baseInfo.model);  // high time cost
        ResourceManager.instance.AssignModelToUnitNode(syncInfo.baseInfo.model, node);

        unit.m_id = syncInfo.id;
        node.m_id = syncInfo.id;
        AddUnit(unit);

        //unit.m_client = player;
        unit.m_model = syncInfo.baseInfo.model;
        if (localClient.isServer)
        {
            unit.AI = UnitAI.instance;
        }

        unit.Name      = syncInfo.baseInfo.name;
        unit.MaxHpBase = (float)syncInfo.baseInfo.maxHp;
        if (syncInfo.baseInfo.attackSkill.valid)
        {
            AttackAct atk = new AttackAct(syncInfo.baseInfo.attackSkill.name, (float)syncInfo.baseInfo.attackSkill.cd, new AttackValue(AttackValue.NameToType(syncInfo.baseInfo.attackSkill.type), (float)syncInfo.baseInfo.attackSkill.value), (float)syncInfo.baseInfo.attackSkill.vrange);
            atk.CastRange      = (float)syncInfo.baseInfo.attackSkill.range;
            atk.CastHorizontal = syncInfo.baseInfo.attackSkill.horizontal;
            foreach (var ani in syncInfo.baseInfo.attackSkill.animations)
            {
                atk.AddCastAnimation(ModelNode.NameToId(ani));
            }
            atk.ProjectileTemplate      = ResourceManager.instance.LoadProjectile(syncInfo.baseInfo.attackSkill.projectile);
            atk.ProjectileTemplate.fire = "Straight";
            unit.AddActiveSkill(atk);
        }

        node.position      = syncInfo.position;
        node.rotation      = syncInfo.rotation;
        unit.Hp            = syncInfo.hp;
        unit.force.Force   = syncInfo.force;
        unit.MoveSpeedBase = (float)syncInfo.baseInfo.move;
        unit.Revivable     = syncInfo.baseInfo.revivable;
        unit.Fixed         = syncInfo.baseInfo.isfixed;

        for (int i = 0; i < syncInfo.guns.Count; ++i)
        {
            unit.AddGun(i);
            unit.SetGunPosition(i, syncInfo.guns[i].position);
            unit.SetGunRotation(i, syncInfo.guns[i].rotation);
            //syncInfo.guns[i].rotateSpeed;
        }

        return(unit);
    }