Exemple #1
0
    public void ReplaceBagItemPos(UnityEngine.GameObject newItem, UnityEngine.GameObject oldItem)
    {
        Debug.LogWarning("setBagItemPos");
        Monitor.Enter(KBEngineApp.app.entities);
        KBEngine.Avatar player        = (KBEngine.Avatar)KBEngineApp.app.player();
        UInt64          old_serialnum = itemsDic[oldItem];
        UInt64          new_serialnum = itemsDic[newItem];

        player.rePlaceBagItemPos(new_serialnum, old_serialnum);
        Monitor.Exit(KBEngineApp.app.entities);
        Byte   new_frame    = 0;
        UInt16 new_bagindex = 0;

        foreach (var v in KnapSackInfo.inst.allKanpItems)
        {
            foreach (var mv in v.Value)
            {
                if (mv.Value.serialnum == new_serialnum)
                {
                    new_frame    = v.Key;
                    new_bagindex = mv.Key;
                }
            }
        }
        KnapsakItem new_ksi = KnapSackInfo.inst.allKanpItems[new_frame][new_bagindex];

        KnapSackInfo.inst.allKanpItems[new_frame].Remove(new_bagindex);

        Byte   old_frame    = 0;
        UInt16 old_bagindex = 0;

        foreach (var v in KnapSackInfo.inst.allKanpItems)
        {
            foreach (var mv in v.Value)
            {
                if (mv.Value.serialnum == old_serialnum)
                {
                    old_frame    = v.Key;
                    old_bagindex = mv.Key;
                }
            }
        }
        KnapsakItem old_ksi = KnapSackInfo.inst.allKanpItems[old_frame][old_bagindex];

        KnapSackInfo.inst.allKanpItems[old_frame].Remove(old_bagindex);

        old_ksi.bagFrameIndex = new_frame;
        old_ksi.bagItemIndex  = new_bagindex;
        new_ksi.bagFrameIndex = old_frame;
        new_ksi.bagItemIndex  = old_bagindex;
        KnapSackInfo.inst.allKanpItems[old_frame].Add(old_bagindex, new_ksi);
        KnapSackInfo.inst.allKanpItems[new_frame].Add(new_bagindex, old_ksi);
    }