Exemplo n.º 1
0
    // 批量更新小地图实体位置
    public void BatchUpdateEntityPos(Dictionary <int, EntityPosAngleInfo> hTable)
    {
        // 要更新的列表
        Dictionary <EntityView, EntityPosAngleInfo> updateList = new Dictionary <EntityView, EntityPosAngleInfo>();

        foreach (var keypair in hTable)
        {
            EntityPosAngleInfo info = (EntityPosAngleInfo)keypair.Value;

            EntityView ev = EntityFactory.getEntityViewByID(info.id);
            if (ev == null)
            {
                continue;
            }
            //if (ev.CanUpdateMinimap())
            {
                updateList.Add(ev, info);
            }
        }
        if (updateList.Count == 0)
        {
            return;
        }

        //根据ID创建AS对象,并存入数组,传到AS
        Value batchArray = this.CreateArray();

        batchArray.SetArraySize((uint)updateList.Count);

        uint index = 0;

        foreach (var item in updateList)
        {
            EntityView         ev   = item.Key;
            EntityPosAngleInfo info = item.Value;

            // 防御塔
            int nIsTower = 0;
            if (ev != null && ev.Type == ENTITY_TYPE.TYPE_MONSTER)
            {
                nIsTower = ev.Flag;
            }

            ASObjectEx entityPos;
            entityPos.values = new object[] { info.id, info.pos.x, info.pos.z, info.dir.y, nIsTower };
            entityPos.names  = new string[]  { "entityID", "fPosX", "fPosZ", "fAngle", "isTower" };
            entityPos.types  = new Type[]    { typeof(int), typeof(float), typeof(float), typeof(float), typeof(int) };

            Value asPos = Value.ConvertToASObjectEx(entityPos, this, "Com.Scaleform.Common.MinimapEntityPos");
            if (!Value.IsValueValid(asPos))
            {
                Trace.Warning("ConvertToASObjectEx failed asPos == null");
            }
            // 小地图更新后处理
            ev.OnUpdateMinimap();

            batchArray.SetElement(index, asPos);
            ++index;
        }

        MyInvokeQ._Invoke("BatchUpdateEntityPos", batchArray);
    }