// calls OnPhotonSerializeView (through ExecuteOnSerialize)
// the content created here is consumed by receivers in: ReadOnSerialize
private Hashtable OnSerializeWrite(PhotonView view)
{
object[] dataArray;
// 1=Specific data
if (view.observed is MonoBehaviour)
{
MonoBehaviour monob = (MonoBehaviour)view.observed;
PhotonStream pStream = new PhotonStream(true, null);
PhotonMessageInfo info = new PhotonMessageInfo(this.mLocalActor, this.ServerTimeInMilliSeconds, view);
this.ExecuteOnSerialize(monob, pStream, info);
if (pStream.Count == 0)
{
// if an observed script didn't write any data, we don't send anything
return null;
}
dataArray = pStream.ToArray();
}
else if (view.observed is Transform)
{
Transform trans = (Transform)view.observed;
List<object> data = new List<object>();
if (view.onSerializeTransformOption == OnSerializeTransform.OnlyPosition
|| view.onSerializeTransformOption == OnSerializeTransform.PositionAndRotation
|| view.onSerializeTransformOption == OnSerializeTransform.All)
data.Add(trans.localPosition);
else
data.Add(null);
if (view.onSerializeTransformOption == OnSerializeTransform.OnlyRotation
|| view.onSerializeTransformOption == OnSerializeTransform.PositionAndRotation
|| view.onSerializeTransformOption == OnSerializeTransform.All)
data.Add(trans.localRotation);
else
data.Add(null);
if (view.onSerializeTransformOption == OnSerializeTransform.OnlyScale
|| view.onSerializeTransformOption == OnSerializeTransform.All)
data.Add(trans.localScale);
dataArray = data.ToArray();
}
else if (view.observed is Rigidbody)
{
Rigidbody rigidB = (Rigidbody)view.observed;
List<object> data = new List<object>();
if (view.onSerializeRigidBodyOption != OnSerializeRigidBody.OnlyAngularVelocity)
data.Add(rigidB.velocity);
else
data.Add(null);
if (view.onSerializeRigidBodyOption != OnSerializeRigidBody.OnlyVelocity)
data.Add( rigidB.angularVelocity);
dataArray = data.ToArray();
}
else
{
Debug.LogError("Observed type is not serializable: " + view.observed.GetType());
return null;
}
// HEADER
// 0=View ID
// 1=View Prefix
// 2=Timestamp of this msg
Hashtable messageData = new Hashtable();
messageData[(byte)0] = (int)view.viewID.ID; // LIMITS NETWORKVIEWS&PLAYERS
if (view.prefix > 0)
{
messageData[(byte)1] = view.prefix;
}
messageData[(byte)2] = this.ServerTimeInMilliSeconds;
// EVDATA:
// 0=MessageData is the header
// 1=data of observed type (different per type of observed object)
Hashtable evData = new Hashtable();
evData[(byte)0] = messageData;
evData[(byte)1] = dataArray; // this is the actual data (script or observed object)
if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
{
// copy the full data set
Hashtable copy = new Hashtable();
copy.Merge(evData);
// compress content of data set (by comparing to view.lastOnSerializeDataSent)
this.DeltaCompressionWrite(view, evData);
// buffer the full data set (for next compression)
view.lastOnSerializeDataSent = copy;
}
return evData;
}