Esempio n. 1
0
    public static short PhotonSerialize(StreamBuffer i_OutStream, object i_Customobject)
    {
        tnMultiplayerIndexTable table = (tnMultiplayerIndexTable)i_Customobject;

        int index = 0;

        lock (memTnMultiplayerIndexTable)
        {
            byte[] bytes = memTnMultiplayerIndexTable;
            Protocol.Serialize(table.maxPlayers, bytes, ref index);
            Protocol.Serialize(table.keyCount, bytes, ref index);
            foreach (int key in table.keys)
            {
                List <int> assignedIndices = table.GetAssignedIndicesFor(key);
                Protocol.Serialize(key, bytes, ref index);
                Protocol.Serialize(assignedIndices.Count, bytes, ref index);
                for (int i = 0; i < assignedIndices.Count; ++i)
                {
                    int assignedIndex = assignedIndices[i];
                    Protocol.Serialize(assignedIndex, bytes, ref index);
                }
            }

            i_OutStream.Write(bytes, 0, (4 + (22 * 4) + (22 * 4)));
        }

        return(4 + (22 * 4) + (22 * 4));
    }
Esempio n. 2
0
    public static object PhotonDeserialize(StreamBuffer i_InStream, short i_Length)
    {
        tnMultiplayerIndexTable table = null;

        int index = 0;

        lock (memTnMultiplayerIndexTable)
        {
            i_InStream.Read(memTnMultiplayerIndexTable, 0, (4 + (22 * 4) + (22 * 4)));

            int maxPlayers;
            Protocol.Deserialize(out maxPlayers, memTnMultiplayerIndexTable, ref index);

            table = new tnMultiplayerIndexTable(maxPlayers);

            int keyCount;
            Protocol.Deserialize(out keyCount, memTnMultiplayerIndexTable, ref index);

            for (int i = 0; i < keyCount; ++i)
            {
                int key;
                Protocol.Deserialize(out key, memTnMultiplayerIndexTable, ref index);

                int count;
                Protocol.Deserialize(out count, memTnMultiplayerIndexTable, ref index);

                List <int> list = new List <int>();
                for (int j = 0; j < count; ++j)
                {
                    int assignedIndex;
                    Protocol.Deserialize(out assignedIndex, memTnMultiplayerIndexTable, ref index);

                    list.Add(assignedIndex);
                }

                table.AssignIndicesTo(key, list);
            }
        }

        return(table);
    }
    public static bool GetPhotonPlayerOwnerId(int i_OnlinePlayerIndex, out int o_Id)
    {
        o_Id = -1;

        tnMultiplayerIndexTable indexTable = null;

        if (PhotonUtils.TryGetRoomCustomProperty <tnMultiplayerIndexTable>(PhotonPropertyKey.s_RoomCustomPropertyKey_AssignedIndices, out indexTable))
        {
            if (indexTable != null)
            {
                int id = indexTable.GetIndexOwnerId(i_OnlinePlayerIndex);
                if (id != -1)
                {
                    o_Id = id;
                    return(true);
                }
            }
        }

        return(false);
    }