Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (!Channel.GetNetwork().IsClient())
        {
            DateTime now = new DateTime();
            now = DateTime.Now;
            TimeSpan duration = now - last_clientupdate;
            if (duration > TimeSpan.FromMilliseconds(100))
            {
                float time = Time.time;
                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.velocity = ((GameObject)i.Value).GetComponent <ship>().GetVelocity();
                    m.rotation = ((GameObject)i.Value).transform.localRotation;
                    m.time     = time;
                    byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m);

                    foreach (KeyValuePair <int, GameObject> gg in ShipList)
                    {
                        gg.Value.GetComponent <channel>().SendToChannel(ref data1);
                    }
                }
            }
        }
        ServerTime.Update(Time.deltaTime);
    }
Exemple #2
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);
                }
            }
        }
    }