Ejemplo n.º 1
0
    // A "Voos Name" may be a 32-char GUID or just some string, like
    // __DEFAULT_BEHAVIOR__
    public static void WriteVoosName(this NET.NetworkWriter writer, string name)
    {
        if (name.IsNullOrEmpty())
        {
            writer.Write(VN_EMPTY);
            return;
        }

        System.Guid guid;
        if (System.Guid.TryParseExact(name, "N", out guid))
        {
            writer.Write(VN_GUID); // Indicate GUID
            byte[] bytes = guid.ToByteArray();
            Debug.Assert(bytes.Length == 16);
            for (int i = 0; i < 16; i++)
            {
                writer.Write(bytes[i]);
            }
        }
        else
        {
            // Some string, maybe null/empty
            writer.Write(VN_UTF16);
            writer.WriteUtf16(name);
        }
    }
Ejemplo n.º 2
0
    public void TestUtf16Serialize()
    {
        byte[] buffer = new byte[100];
        var    writer = new UnityEngine.Networking.NetworkWriter(buffer);

        string sample = "japanese いろはに";

        writer.WriteUtf16(sample);

        var    reader = new UnityEngine.Networking.NetworkReader(buffer);
        string actual = reader.ReadUtf16();

        Assert.AreEqual(sample, actual);
    }