Esempio n. 1
0
    //送信する情報をキューに追加
    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);
    }
Esempio n. 2
0
    public override void OnMonobitSerializeViewRead(MonobitStream stream, MonobitMessageInfo info)
    {
        Active = (bool)stream.Dequeue();

        lookAtObject.localPosition = (Vector3)stream.Dequeue();
        lookAtObject.localRotation = (Quaternion)stream.Dequeue();

        waist.localPosition        = (Vector3)stream.Dequeue();
        waist.localRotation        = (Quaternion)stream.Dequeue();
        handL.enable               = (bool)stream.Dequeue();
        handR.enable               = (bool)stream.Dequeue();
        footL.enable               = (bool)stream.Dequeue();
        footR.enable               = (bool)stream.Dequeue();
        handL.target.localRotation = (Quaternion)stream.Dequeue();
        handR.target.localRotation = (Quaternion)stream.Dequeue();
        footL.target.localRotation = (Quaternion)stream.Dequeue();
        footR.target.localRotation = (Quaternion)stream.Dequeue();
        handL.target.localPosition = (Vector3)stream.Dequeue();
        handR.target.localPosition = (Vector3)stream.Dequeue();
        footL.target.localPosition = (Vector3)stream.Dequeue();
        footR.target.localPosition = (Vector3)stream.Dequeue();
        handL.weight               = (float)stream.Dequeue();
        handR.weight               = (float)stream.Dequeue();
        footL.weight               = (float)stream.Dequeue();
        footR.weight               = (float)stream.Dequeue();
    }
 /**
  * オブジェクトの位置・姿勢・倍率の同期処理関数.
  *
  * @param stream MonobitTransformViewの送信データ、または受信データのいずれかを提供するパラメータ
  * @param info 特定のメッセージやRPCの送受信、または更新に関する「送信者、対象オブジェクト、タイムスタンプ」などの情報を保有するパラメータ
  */
 public void OnMonobitSerializeView(MonobitStream stream, MonobitMessageInfo info)
 {
     if (stream.isWriting)
     {
         OnMonobitSerializeViewWrite(stream, info);
     }
     else
     {
         OnMonobitSerializeViewRead(stream, info);
     }
 }
 /// <summary>
 /// ストリームデータをシリアライズする
 /// </summary>
 /// <param name="stream">ストリームデータ</param>
 /// <param name="info">メッセージ情報</param>
 public override void SerializeView(MonobitStream stream, MonobitMessageInfo info)
 {
     Serialize(observed, stream, info);
     foreach (Component component in InternalObservedComponents)
     {
         Serialize(component, stream, info);
     }
     foreach (Component component in ObservedComponents)
     {
         Serialize(component, stream, info);
     }
 }
        /// <summary>
        /// 指定コンポーネントごとにストリームデータをシリアライズする
        /// </summary>
        /// <param name="component">指定コンポーネント</param>
        /// <param name="stream">ストリームデータ</param>
        /// <param name="info">メッセージ情報</param>
        private void Serialize(Component component, MonobitStream stream, MonobitMessageInfo info)
        {
            if (component == null)
            {
                return;
            }

            new Switch(component)
            .Case <MonobitAnimatorView>(p =>
            {
                ExecuteComponentOnSerialize <MonobitAnimatorView>(component, stream, info);
            })
            .Case <MonobitTransformView>(p =>
            {
                ExecuteComponentOnSerialize <MonobitTransformView>(component, stream, info);
            })
            .Case <MonoBehaviour>(p =>
            {
                ExecuteComponentOnSerialize <MonoBehaviour>(component, stream, info);
            })
            .Case <Transform>(p =>
            {
                Serialize <Transform, MonobitEngineBase.OnSerializeTransform>(
                    p,
                    stream,
                    new Serializer <Transform>[] {
                    trans => { return(trans.localPosition); },
                    trans => { return(trans.localRotation); },
                    trans => { return(trans.localScale); },
                });
            })
            .Case <Rigidbody>(p =>
            {
                Serialize <Rigidbody, MonobitEngineBase.OnSerializeRigidBody>(
                    p,
                    stream,
                    new Serializer <Rigidbody>[] {
                    rigid => { return(rigid.velocity); },
                    rigid => { return(rigid.angularVelocity); },
                });
            })
            .Case <Rigidbody2D>(p =>
            {
                Serialize <Rigidbody2D, MonobitEngineBase.OnSerializeRigidBody>(
                    p,
                    stream,
                    new Serializer <Rigidbody2D>[] {
                    rigid => { return(rigid.velocity); },
                    rigid => { return(rigid.angularVelocity); },
                });
            });
        }
Esempio n. 6
0
 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();
     }
 }
        /// <summary>
        /// MonobitAnimatorViewの同期データの読み書きを実行する
        /// </summary>
        /// <param name="stream">MonobitAnimatorViewの送信データ、または受信データのいずれかを提供するパラメータ</param>
        /// <param name="info">特定のメッセージやRPCの送受信、または更新に関する「送信者、対象オブジェクト、タイムスタンプ」などの情報を保有するパラメータ</param>
        public void OnMonobitSerializeView(MonobitStream stream, MonobitMessageInfo info)
        {
            if (this.m_Animator == null)
            {
                return;
            }

            if (stream.isWriting == true)
            {
                this.Serialize(stream);
            }
            else
            {
                this.Deserialize(stream);
            }
        }
    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);
            }
        }
    }
        /// <summary>
        /// アニメーションレイヤー&パラメータを受信データからデシリアライズ
        /// </summary>
        /// <param name="stream">アニメーションレイヤー&パラメータを受信データからデシリアライズ</param>
        private void Deserialize(MonobitStream stream)
        {
            // アニメーションレイヤーを受信データからデシリアライズ
            foreach (AnimLayerInfo layerInfo in this.m_SyncAnimLayers)
            {
                if (layerInfo.m_EnableSync)
                {
                    this.m_Animator.SetLayerWeight(layerInfo.m_Index, (float)stream.Dequeue());
                }
            }

            // アニメーションパラメータを受信データからデシリアライズ
            foreach (AnimParamInfo paramInfo in this.m_SyncAnimParams)
            {
                if (paramInfo.m_EnableSync && !m_Animator.IsParameterControlledByCurve(paramInfo.m_Name))
                {
                    switch (paramInfo.m_Type)
                    {
                    case AnimatorControllerParameterType.Bool:
                        if (stream.Peek() is bool)
                        {
                            this.m_Animator.SetBool(paramInfo.m_Name, (bool)stream.Dequeue());
                        }
                        break;

                    case AnimatorControllerParameterType.Float:
                        if (stream.Peek() is float)
                        {
                            this.m_Animator.SetFloat(paramInfo.m_Name, (float)stream.Dequeue());
                        }
                        break;

                    case AnimatorControllerParameterType.Int:
                        if (stream.Peek() is int)
                        {
                            this.m_Animator.SetInteger(paramInfo.m_Name, (int)stream.Dequeue());
                        }
                        break;

                    case AnimatorControllerParameterType.Trigger:
                        break;
                    }
                }
            }
        }
        /**
         * 書き込み専用オブジェクトの位置・姿勢・倍率の同期処理関数.
         *
         * @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 override void OnMonobitSerializeViewRead(MonobitStream stream, MonobitMessageInfo info)
        {
            // ネットワークからの更新を受信したことをフラグで検知
            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();
            }
        }
        /**
         * オブジェクトの位置・姿勢・倍率の同期処理関数.
         *
         * @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();
                }
            }
        }
Esempio n. 13
0
        /// <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="T">指定デシリアライズタイプ</typeparam>
 /// <param name="stream">ストリームデータ</param>
 /// <param name="procs">ストリームからのデータを設定するデリゲート</param>
 private void Desirialize <T>(MonobitStream stream, params Desirializer[] procs)
 {
     if (stream == null || procs == null || procs.Length == 0)
     {
         return;
     }
     if (typeof(T) == typeof(MonobitEngineBase.OnSerializeTransform))
     {
         foreach (Desirializer proc in procs)
         {
             proc(stream.Dequeue());
         }
     }
     else if (typeof(T) == typeof(MonobitEngineBase.OnSerializeRigidBody))
     {
         for (int i = 0; i < 2; i++)
         {
             procs[i](stream.Dequeue());
         }
     }
 }
        /// <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;
                    }
                }
            }
        }
        /// <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)
            {
                methodInfo.Invoke(component, new object[] { stream, info });
            }
        }
        /// <summary>
        /// 指定コンポーネントごとにストリームデータをデシリアライズする
        /// </summary>
        /// <param name="component">コンポーネント</param>
        /// <param name="stream">ストリームデータ</param>
        /// <param name="info">メッセージ情報</param>
        private void Desirialize(Component component, MonobitStream stream, MonobitMessageInfo info)
        {
            if (component == null)
            {
                return;
            }

            new Switch(component)
            .Case <MonobitAnimatorView>(p =>
            {
                ExecuteComponentOnSerialize <MonobitAnimatorView>(component, stream, info);
            })
            .Case <MonobitTransformView>(p =>
            {
                ExecuteComponentOnSerialize <MonobitTransformView>(component, stream, info);
            })
            .Case <MonoBehaviour>(p =>
            {
                ExecuteComponentOnSerialize <MonoBehaviour>(component, stream, info);
            })
            .Case <Transform>(p => {
                Desirialize <MonobitEngineBase.OnSerializeTransform>(
                    stream,
                    new Desirializer[] {
                    r => {
                        // Position
                        p.localPosition = (Vector3)r;
                    },
                    r => {
                        // Rotation
                        p.localRotation = (Quaternion)r;
                    },
                    r => {
                        // Scale
                        p.localScale = (Vector3)r;
                    }
                });
            })
            .Case <Rigidbody>(p => {
                Desirialize <MonobitEngineBase.OnSerializeRigidBody>(
                    stream,
                    new Desirializer[] {
                    r => {
                        // angularVelocity
                        p.angularVelocity = (Vector3)r;
                    },
                    r => {
                        // velocity
                        p.velocity = (Vector3)r;
                    }
                });
            })
            .Case <Rigidbody2D>(p => {
                Desirialize <MonobitEngineBase.OnSerializeRigidBody>(
                    stream,
                    new Desirializer[] {
                    r => {
                        // angularVelocity
                        p.angularVelocity = (float)r;
                    },
                    r => {
                        // velocity
                        p.velocity = (Vector2)r;
                    }
                });
            });
        }