示例#1
0
 void SendTrigger(int contID, bool accept)
 {
     network_data.trigger m1 = new network_data.trigger();
     m1.set(contID, mychannel.GetChannel());
     m1.netID  = netID;
     m1.count  = counter;
     m1.on     = on;
     m1.accept = accept;
     byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.trigger>(m1);
     mychannel.SendToChannel(ref data1);
     if (!mychannel.GetNetwork().IsClient() && m1.accept)
     {
         DoActivate(contID);
     }
 }
示例#2
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);
    }
示例#3
0
    public void LoadShip(string prefab_name, string object_name)
    {
        GameObject Ship = Instantiate(Resources.Load(prefab_name, typeof(GameObject)), this.gameObject.transform) as GameObject;
        channel    s    = Ship.GetComponent <channel>();

        Ship.GetComponent <puppet>().InitTransform(Ship.transform.localPosition, Ship.transform.localRotation);// rotation);
        network n      = GameObject.FindObjectOfType <network>();
        int     unikID = 1;

        if (!Channel.GetNetwork().IsClient())
        {
            unikID = GetComponent <server>().GetFreeID();
        }
        int t = n.AddGameObjectToChannel(Ship, unikID);

        s.SetNetwork(n);
        s.SetChannel(t);
        Channel.RegisterEntity(Ship, s.GetChannel());
        object_name += "_" + t;
        Ship.name    = object_name;
        Ship.GetComponent <ship>().Init(this.gameObject);
        ShipList[s.GetChannel()] = Ship;
    }
示例#4
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);
                }
            }
        }
    }