Exemplo n.º 1
0
    /// <summary>
    /// 生成单位
    /// </summary>
    /// <param name="_name">单位类型名称</param>
    /// <param name="_pos">单位一维坐标</param>
    /// <param name="_camp">单位阵营编号</param>
    public void AddUnit(string _name, int _pos, int _camp)
    {
        GameObject unit = UnitLoader.LoadUnitToBattleField(_name);

        unit.tag = "Player_" + _camp;
        Vector3 pos = GameObject.Find(_pos.ToString()).transform.position;

        pos.y = 0.5f;

        unit.transform.position = pos;

        // 单位池与战场单位池记录单位及其位置
        unitPool.Add(unit, _pos);
        bfm.AddUnit(unit, _pos);

        // 发送位置信息给单位
        unit.SendMessage("SetPosition", _pos);

        // 设置阵营
        unit.SendMessage("SetCamp", _camp);

        // 订阅死亡信息
        unit.SendMessage("subscribeUnitDead", (Action <GameObject>)RemoveUnit);
    }