Example #1
0
    void CreateTestTank()
    {
        Vector2 sz = Utils.HalfCameraSize;
        // 创建普通单位
        TankSyncInfo syncInfo = new TankSyncInfo();

        //syncInfo.baseInfo = ResourceManager.instance.LoadUnit("", m_testUnits[Utils.Random.Next(m_testUnits.Count)].text);
        syncInfo.baseInfo.model     = "Test";
        syncInfo.baseInfo.maxHp     = 500;
        syncInfo.baseInfo.isfixed   = false;
        syncInfo.baseInfo.name      = "TestTank";
        syncInfo.baseInfo.revivable = true;
        syncInfo.baseInfo.move      = 2;
        syncInfo.position           = new Vector2((float)(-sz.x + Utils.Random.NextDouble() * sz.x * 2), (float)(-sz.y + Utils.Random.NextDouble() * sz.y * 2));
        syncInfo.rotation           = (float)Utils.Random.NextDouble() * 360.0f;
        syncInfo.id    = Utils.IdGen.nextId;
        syncInfo.hp    = (float)syncInfo.baseInfo.maxHp;
        syncInfo.force = Utils.Random.Next(8);
        TankGunSyncInfo gunInfo = new TankGunSyncInfo();

        gunInfo.position = new Vector3(0.0f, 0.0f, 0.0f);
        gunInfo.rotation = 0.0f;
        syncInfo.guns.Add(gunInfo);
        World.Current.CreateTank(syncInfo);
    }
Example #2
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);
    }
Example #3
0
    public void ServerCreateTanks()
    {
        Vector2 sz = Utils.HalfCameraSize;

        // 创建玩家单位
        foreach (GamePlayerController ctrl in GameManager.AllPlayers.Values)
        {
            Player playerInfo = ctrl.Player;
            //string path = string.Format("Units/[Player{0}]", ctrl.playerId);
            TankSyncInfo syncInfo = new TankSyncInfo();
            //syncInfo.baseInfo = ResourceManager.instance.LoadTank(path, playerInfo.heroData);
            syncInfo.baseInfo.model     = "Player";
            syncInfo.baseInfo.maxHp     = 2000;
            syncInfo.baseInfo.isfixed   = false;
            syncInfo.baseInfo.name      = "PlayerTank";
            syncInfo.baseInfo.revivable = true;
            syncInfo.baseInfo.move      = 2;
            AttackInfo attackSkill = new AttackInfo();
            attackSkill.cd                = 1.75f;
            attackSkill.type              = "Physical";
            attackSkill.value             = 60;
            attackSkill.vrange            = 0.2f;
            attackSkill.range             = 2.5f;
            attackSkill.horizontal        = false;
            attackSkill.animations        = new string[0];
            attackSkill.projectile        = "Projectiles/MageBolt";
            syncInfo.baseInfo.attackSkill = attackSkill;
            syncInfo.id    = Utils.IdGen.nextId;
            syncInfo.hp    = (float)syncInfo.baseInfo.maxHp;
            syncInfo.force = playerInfo.force;

            syncInfo.position = new Vector2((float)(-sz.x + Utils.Random.NextDouble() * sz.x * 2), (float)(-sz.y + Utils.Random.NextDouble() * sz.y * 2));
            syncInfo.rotation = (float)Utils.Random.NextDouble() * 360.0f;
            TankGunSyncInfo gunInfo = new TankGunSyncInfo();
            gunInfo.position    = new Vector3Serializable(0.0f, 0.0f, 0.0f);
            gunInfo.rotation    = 0.0f;
            gunInfo.rotateSpeed = 1.0f;
            syncInfo.guns.Add(gunInfo);
            Tank unit = World.Current.CreateTank(syncInfo, ctrl.playerId);
            if (ctrl.isLocalPlayer)
            {
                World.Current.SetCameraFollowed(unit.gameObject);
            }
        }

        // 随即创建单位
        StartCoroutine(RepeatCreateUnit("CreateTestTank"));

        //CreateOneTestUnit();

        // 世界开始运转
        World.Current.StartWorld();
    }
Example #4
0
 public SyncCreateTank(TankSyncInfo syncInfo, int playerId)
 {
     this.syncInfo = syncInfo;
     this.playerId = playerId;
 }