如何使用Photon PUN通过网络发送视频?

时间:2017-11-24 19:33:30

标签: c# unity3d networking photon

  

大家好!

我对Photon很陌生,而且我目前制作的手机应用程序基本上是一种游戏,您必须将特定主题的视频发送给与您在同一房间的玩家。我用Photon PUN构建了整个房间连接系统,现在我试图用RPC通过网络发送视频(顺便说一句,如果有更好的解决方案,请告诉我)。我的问题是关于序列化不可序列化的Unity VideoClip,然后使用RPC将其作为byte []发送到房间中的其他客户端。我该怎么做?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;
public static class DataConverter
{

    public static byte[] SerializeObject(T objectToSerialize)
    {
        BinaryFormatter bf = new BinaryFormatter();
        MemoryStream mStream = new MemoryStream();
        bf.Serialize(mStream, objectToSerialize);
        mStream.Position = 0;
        return mStream.ToArray();
    }
    public static T DeserializeObject(byte[] dataStream)
    {
        BinaryFormatter bf = new BinaryFormatter();
        MemoryStream mStream = new MemoryStream(dataStream);
        mStream.Position = 0;
        bf.Binder = new VersionFixer();
        T o = (T)bf.Deserialize(mStream);
        return o;
    }
sealed class VersionFixer : SerializationBinder
{
    public override Type BindToType(string assemblyName, string typeName)
    {
        Type typeToDeserialize = null;

        // For each assemblyName/typeName that you want to deserialize to
        // a different type, set typeToDeserialize to the desired type.
        String assemVer1 = Assembly.GetExecutingAssembly().FullName;
        if (assemblyName != assemVer1)
        {
            // To use a type from a different assembly version, 
            // change the version number.
            // To do this, uncomment the following line of code.
            assemblyName = assemVer1;
            // To use a different type from the same assembly, 
            // change the type name.
        }
        // The following line of code returns the type.
        typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, 
        assemblyName));
        return typeToDeserialize;

    }
 }

我在互联网上找到了一些用于序列化的代码,但我不了解VersionFixer部分,而且无论如何,问题是VideoClip不是Serializable。

0 个答案:

没有答案