Пример #1
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.center_ship:
        {
            network_data.enter_ship com = network_utils.nData.Instance.DeserializeMsg <network_data.enter_ship>(message);
            if (Channel.GetNetwork().IsClient() == false)
            {
                GameObject g = GetNextSpawnPoint();
                SpawnPlayer(com.header.containerID, Channel.GetNetwork().IsClient(), false, g.transform.localPosition, g.transform.localRotation, 0);
            }
        }
        break;

        case (int)network_data.COMMANDS.ccreate_player:
        {
            network_data.create_player com = network_utils.nData.Instance.DeserializeMsg <network_data.create_player>(message);
            if (Channel.GetNetwork().IsClient() == true)
            {
                SpawnPlayer(com.header.containerID, Channel.GetNetwork().IsClient(), Channel.GetNetwork().GetComponent <client>().ingameContID == com.header.containerID, com.position, com.rotation, 0);
            }
        }
        break;

        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())
            {
                if (Channel.GetNetwork().GetComponent <client>().ingameContID != com.header.containerID)
                {
                    GameObject g = Channel.GetEntity(com.header.containerID);
                    if (g != null)
                    {
                        g.GetComponent <puppet>().SetTransform(com.position, com.rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, com.time);
                    }
                }
            }
            else
            {
                GameObject g = Channel.GetEntity(com.header.containerID);
                if (g != null)
                {
                    g.GetComponent <puppet>().SetTransform(com.position, com.rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, com.time);
                }
            }
        }
        break;

        case (int)network_data.COMMANDS.cdisconnect:
        {
            network_data.disconnect com = network_utils.nData.Instance.DeserializeMsg <network_data.disconnect>(message);
            UnregisterEntity(com.header.containerID);
        }
        break;

        case (int)network_data.COMMANDS.ctrigger:
        {
            network_data.trigger com = network_utils.nData.Instance.DeserializeMsg <network_data.trigger>(message);
            if (Triggers.ContainsKey(com.netID))
            {
                trigger t = Triggers[com.netID];
                if (Channel.GetNetwork().IsClient())
                {
                    if (com.accept)
                    {
                        t.SetTrigger(com.count, com.on);
                        t.GetLink().Accept(com.on, com.header.containerID);
                        t.DoActivate(com.header.containerID);
                    }
                }
                else
                {
                    t.TriggerRequest(com.header.containerID);
                    t.DoActivate(com.header.containerID);
                }
            }
        }
        break;
        }
    }
Пример #2
0
    public void SpawnPlayer(int contID, bool IsClient, bool ownPlayer, Vector3 position, Quaternion rotation, float time)
    {
        Vector3    re     = rotation.eulerAngles;
        GameObject Player = Instantiate(Resources.Load("Prefabs/Player", typeof(GameObject)), transform) as GameObject;

        Player.transform.localPosition = position;
        Player.transform.localRotation = rotation;
        Channel.RegisterEntity(Player, contID);
        if (IsClient && ownPlayer)
        {
            Transform t = Player.transform.FindChild("Camera");
            myCam = t.gameObject;
            t.gameObject.SetActive(true);
            Player.AddComponent <puppetcontrol>();
            Player.GetComponent <puppet>().InitTransform(position, rotation);// rotation);
            puppetcontrol f = Player.GetComponent <puppetcontrol>();
            f.SetChannel(Channel);
//            f.AddObjectToInteract(this.gameObject);
            GameObject GUI = GameObject.Find("GUI");
            if (GUI != null)
            {
                GUI.GetComponent <gui>().PushUserInterface(Player);
            }
        }
        else
        {
            Player.AddComponent <puppet>();
            Player.GetComponent <puppet>().InitTransform(position, rotation);// rotation);
        }
        Player.GetComponent <puppet>().SetTransform(position, rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, time);
        if (Player)
        {
            Debug.Log("Enter Ship (" + Channel.GetChannel() + ")" + " player " + contID + " pos: " + position + " rot:" + re.x + "," + re.y + "," + re.z);
        }

        if (IsClient == false)
        {
            network_data.create_player m = new network_data.create_player();
            m.set(contID, Channel.GetChannel());
            m.position = position;
            m.rotation = rotation;
            byte[] data = network_utils.nData.Instance.SerializeMsg <network_data.create_player>(m);
            Channel.SendToChannel(ref data);

            List <byte[]>         datalist = new List <byte[]>();
            IDictionaryEnumerator r        = Channel.FirstEntity();
            while (r.MoveNext())
            {
                if (contID != (int)r.Key)
                {
                    m.set((int)r.Key, Channel.GetChannel());
                    m.position = ((GameObject)r.Value).transform.localPosition;
                    m.rotation = ((GameObject)r.Value).transform.localRotation;
                    byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.create_player>(m);
                    Channel.GetNetwork().Send(contID, data1);
                }
            }
            foreach (KeyValuePair <int, trigger> j in Triggers)
            {
                trigger t = (trigger)j.Value;
                t.SendTriggerTo(contID);
            }
        }
    }