示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (!Channel || !Channel.GetNetwork())
        {
            return;
        }

        if (!Channel.GetNetwork().IsClient())
        {
            InterpolateMovement(puppet.trans_flag_rotation);
            transform.localPosition += myrigidbody.gameObject.transform.localPosition;
            myrigidbody.gameObject.transform.localPosition = Vector3.zero;
//            transform.localRotation *= myrigidbody.gameObject.transform.localRotation;
//            myrigidbody.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);
        }
        else
        {
            if (!IsCockpitUsedByMe())
            {
                InterpolateMovement(puppet.trans_flag_position | puppet.trans_flag_rotation);
            }
            else
            {
                InterpolateMovement(puppet.trans_flag_position);
                transform.localRotation *= myrigidbody.gameObject.transform.localRotation;
                myrigidbody.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);
            }
        }

        DateTime now = new DateTime();

        now = DateTime.Now;
        TimeSpan duration = now - last_clientupdate;

        if (Channel.GetNetwork().IsClient())
        {
            int        id = Channel.GetNetwork().GetComponent <client>().ingameContID;
            GameObject g  = Channel.GetEntity(id);

            if (duration > TimeSpan.FromMilliseconds(100) && g != null)
            {
                float time = Time.time;
                last_clientupdate = now;
                network_data.move_player m = new network_data.move_player();
                m.set(id, Channel.GetChannel());
                m.position = g.transform.localPosition;
                m.rotation = g.transform.localRotation;
                m.time     = time;
                byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m);
                Channel.GetNetwork().Send(id, data1);

                if (IsCockpitUsedByMe())
                {
                    network_data.move_player m2 = new network_data.move_player();
                    m2.set(ShipContID, Game.GetComponent <channel>().GetChannel());
                    m2.position = transform.localPosition;
                    m2.rotation = transform.localRotation;
                    m2.velocity = targetVelocity;
                    m2.time     = time;
                    byte[] data = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m2);
                    Game.GetComponent <channel>().GetNetwork().Send(GetComponent <channel>().GetChannel(), data);
                }
            }
        }
        else
        {
            if (duration > TimeSpan.FromMilliseconds(100))
            {
                last_clientupdate = now;
                network_data.move_player m = new network_data.move_player();
                IDictionaryEnumerator    i = Channel.FirstEntity();
                while (i.MoveNext())
                {
                    GameObject g = (GameObject)i.Value;
                    m.set((int)i.Key, Channel.GetChannel());
                    m.position = ((GameObject)i.Value).transform.localPosition;
                    m.rotation = ((GameObject)i.Value).transform.localRotation;
                    byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m);
                    Channel.SendToChannel(ref data1);
                }
            }
        }
    }
示例#2
0
    public override void ProcessMessage(ref byte[] message)
    {
        network_utils.HEADER header = network_utils.nData.Instance.DeserializeMsg <network_utils.HEADER>(message);
        if (header.signum != network_utils.SIGNUM.BIN)
        {
            return;
        }
        switch (header.command)
        {
        case (int)network_data.COMMANDS.cmove_player:
        {
            network_data.move_player com = network_utils.nData.Instance.DeserializeMsg <network_data.move_player>(message);
            if (Channel.GetNetwork().IsClient())
            {
                GameObject g = Channel.GetEntity(com.header.containerID);
                ship       s = g.GetComponent <ship>();
                if (s != null)
                {
                    if (!s.IsCockpitUsedByMe())
                    {
                        g.GetComponent <ship>().SetTransform(com.position, com.rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, com.time);
                        g.GetComponent <ship>().SetMoveVector(com.position);
                        g.GetComponent <ship>().SetVelocity(com.velocity);
                    }
                    else
                    {
                        g.GetComponent <ship>().SetTransform(com.position, com.rotation, puppet.trans_flag_position, com.time);
                    }
                }
            }
            else
            {
                //                        g.transform.rotation = com.rotation;
                GameObject g = Channel.GetEntity(com.header.containerID);
                if (g == null)
                {
                    Debug.Log("ShipID " + com.header.containerID + " not found");
                }
                else
                {
                    g.GetComponent <ship>().SetTransform(com.position, com.rotation, puppet.trans_flag_rotation, Time.time);
                    //                        g.GetComponent<ship>().SetTransform(com.position,com.rotation);
                    g.GetComponent <ship>().SetMoveVector(com.position);
                    g.GetComponent <ship>().SetVelocity(com.velocity);
                    byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(com);
                    //                        g.GetComponent<ship>().GetChannel().SendToChannel(ref data1);
                }
            }


/*                    if (Channel.GetNetwork().IsClient())
 *                  {
 *                      int ownid = Channel.GetNetwork().GetComponent<client>().ingameContID;
 *                      GameObject g = Channel.GetEntity(com.header.containerID);
 *                      if (g != null)
 *                      {
 *                          g.GetComponent<puppet>().SetTransform(com.position, com.rotation);
 *                      }
 *                  }
 *                  else
 *                  {
 *                      GameObject g = Channel.GetEntity(com.header.containerID);
 *                      if (g != null)
 *                      {
 *                          g.GetComponent<puppet>().SetTransform(com.position, com.rotation);
 *                          g.GetComponent<ship>().SetVelocity(com.velocity);
 *                      }
 *                  }
 */
        }
        break;
        }
    }