public void OnMonobitSerializeView(MonobitStream stream, MonobitMessageInfo info) { if (stream.isWriting) { stream.Enqueue(playerName); stream.Enqueue(vrmTitle); } else { playerName = (string)stream.Dequeue(); vrmTitle = (string)stream.Dequeue(); } }
/** * 書き込み専用オブジェクトの位置・姿勢・倍率の同期処理関数. * * @param stream MonobitTransformViewの送信データ、または受信データのいずれかを提供するパラメータ * @param info 特定のメッセージやRPCの送受信、または更新に関する「送信者、対象オブジェクト、タイムスタンプ」などの情報を保有するパラメータ */ public override void OnMonobitSerializeViewWrite(MonobitStream stream, MonobitMessageInfo info) { // ストリームへの送信処理、および、自身の座標を最新のtransform情報に更新 Transform transform = gameObject.transform; // gameObjectを参照するコストが重いので、1回にまとめる if (m_SyncPosition.m_EnableSync) { stream.Enqueue(transform.localPosition); } if (m_SyncRotation.m_EnableSync) { stream.Enqueue(transform.localRotation); } if (m_SyncScale.m_EnableSync) { stream.Enqueue(transform.localScale); } }
/** * オブジェクトの位置・姿勢・倍率の同期処理関数. * * @param stream MonobitTransformViewの送信データ、または受信データのいずれかを提供するパラメータ * @param info 特定のメッセージやRPCの送受信、または更新に関する「送信者、対象オブジェクト、タイムスタンプ」などの情報を保有するパラメータ */ public void OnMonobitSerializeView(MonobitStream stream, MonobitMessageInfo info) { if (stream.isWriting) { // ストリームへの送信処理、および、自身の座標を最新のtransform情報に更新 if (m_SyncPosition.m_EnableSync) { stream.Enqueue(gameObject.transform.localPosition); m_LastUpdatePosition = gameObject.transform.localPosition; } if (m_SyncRotation.m_EnableSync) { stream.Enqueue(gameObject.transform.localRotation); m_LastUpdateRotation = gameObject.transform.localRotation; } if (m_SyncScale.m_EnableSync) { stream.Enqueue(gameObject.transform.localScale); m_LastUpdateScale = gameObject.transform.localScale; } } else { // ネットワークからの更新を受信したことをフラグで検知 m_UpdateNetwork = true; // ストリームからの受信処理 if (m_SyncPosition.m_EnableSync) { m_LastUpdatePosition = (Vector3)stream.Dequeue(); } if (m_SyncRotation.m_EnableSync) { m_LastUpdateRotation = (Quaternion)stream.Dequeue(); } if (m_SyncScale.m_EnableSync) { m_LastUpdateScale = (Vector3)stream.Dequeue(); } } }
/// <summary> /// OnMonobitSerializeViewを呼び出してシリアライズさせる /// </summary> /// <typeparam name="T">呼び出し先のクラス型</typeparam> /// <param name="component">コンポーネント</param> /// <param name="stream">ストリームデータ</param> /// <param name="info">メッセージ情報</param> private void ExecuteComponentOnSerialize <T>(Component component, MonobitStream stream, MonobitMessageInfo info) { if (component == null) { return; } MethodInfo methodInfo = null; if (m_dicOnSerializeMethodInfos.TryGetValue(component, out methodInfo) != true) { var result = MonobitNetwork.GetMethod <T>(component, MonobitNetworkingMessage.OnMonobitSerializeView.ToString(), out methodInfo); if (result == false) { methodInfo = null; } m_dicOnSerializeMethodInfos.Add(component, methodInfo); } if (methodInfo != null) { string componentName = component.GetType().Name; if (stream.isWriting) { stream.Enqueue(new string[] { componentName, "start" }); } else { stream.SkipDequeue(); } methodInfo.Invoke(component, new object[] { stream, info }); if (stream.isWriting) { stream.Enqueue(new string[] { componentName, "end" }); } else { stream.SkipDequeue(); } } }
/// <summary> /// コンポーネントよりデータ取得してシリアライズする /// </summary> /// <typeparam name="T1">コンポーネントの型</typeparam> /// <typeparam name="T2">指定シリアライズタイプ</typeparam> /// <param name="component">コンポーネント</param> /// <param name="stream">ストリームデータ</param> /// <param name="procs">コンポーネントよりデータ取得するデリゲート</param> private void Serialize <T1, T2>(T1 component, MonobitStream stream, params Serializer <T1>[] procs) { if (stream == null || procs == null || procs.Length == 0) { return; } if (typeof(T2) == typeof(MonobitEngineBase.OnSerializeTransform)) { foreach (Serializer <T1> proc in procs) { stream.Enqueue(proc(component)); } } else if (typeof(T2) == typeof(MonobitEngineBase.OnSerializeRigidBody)) { foreach (Serializer <T1> proc in procs) { stream.Enqueue(proc(component)); } } }
/// <summary> /// アニメーションレイヤー&パラメータを送信データにシリアライズ /// </summary> /// <param name="stream">送信ストリーム情報</param> private void Serialize(MonobitStream stream) { // アニメーションレイヤーを送信データにシリアライズ foreach (AnimLayerInfo layerInfo in this.m_SyncAnimLayers) { if (layerInfo.m_EnableSync) { stream.Enqueue(this.m_Animator.GetLayerWeight(layerInfo.m_Index)); } } // アニメーションパラメータを送信データにシリアライズ foreach (AnimParamInfo paramInfo in this.m_SyncAnimParams) { if (paramInfo.m_EnableSync && !m_Animator.IsParameterControlledByCurve(paramInfo.m_Name)) { switch (paramInfo.m_Type) { case AnimatorControllerParameterType.Bool: stream.Enqueue(this.m_Animator.GetBool(paramInfo.m_Name)); break; case AnimatorControllerParameterType.Float: stream.Enqueue(this.m_Animator.GetFloat(paramInfo.m_Name)); break; case AnimatorControllerParameterType.Int: stream.Enqueue(this.m_Animator.GetInteger(paramInfo.m_Name)); break; case AnimatorControllerParameterType.Trigger: break; } } } }
public void OnMonobitSerializeView(MonobitStream stream, MonobitMessageInfo info) { if (stream.isWriting) { stream.Enqueue(serializeBytes); } else { serializeBytes = (byte[])stream.Dequeue(); if (MonobitEngineBase.CompressedStream.DeltaCompressed == monobitView.compressedStream) { ++serializeReadCount; UnityEngine.Debug.Log("serializeBytes[0]=" + serializeBytes[0] + " serializeReadCount=" + serializeReadCount); } } }
//送信する情報をキューに追加 public override void OnMonobitSerializeViewWrite(MonobitStream stream, MonobitMessageInfo info) { stream.Enqueue(Active); stream.Enqueue(lookAtObject.localPosition); stream.Enqueue(lookAtObject.localRotation); stream.Enqueue(waist.localPosition); stream.Enqueue(waist.localRotation); stream.Enqueue(handL.enable); stream.Enqueue(handR.enable); stream.Enqueue(footL.enable); stream.Enqueue(footR.enable); stream.Enqueue(handL.target.localRotation); stream.Enqueue(handR.target.localRotation); stream.Enqueue(footL.target.localRotation); stream.Enqueue(footR.target.localRotation); stream.Enqueue(handL.target.localPosition); stream.Enqueue(handR.target.localPosition); stream.Enqueue(footL.target.localPosition); stream.Enqueue(footR.target.localPosition); stream.Enqueue(handL.weight); stream.Enqueue(handR.weight); stream.Enqueue(footL.weight); stream.Enqueue(footR.weight); }