Exemplo n.º 1
0
        public void NetDataManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.GetStatus:
                NetData ngs = Manager.CreateNetData(NetID, (byte)NetStatus.SetStatus);
                ngs.Write(heart);
                ngs.Write((byte)Status);
                NetServer.SendTo(ngs, data.RemoteIP);
                break;

            case NetStatus.SetStatus:
                heart  = data.ReadInt();
                Status = (ShipStatus)data.ReadInt();
                break;

            case NetStatus.ShipStatus:
                Status = (ShipStatus)data.ReadByte();
                break;

            case NetStatus.Avatar:
                transform.position = data.ReadVector3();
                transform.rotation = data.ReadQuaternion();
                break;

            case NetStatus.Death:
                Death(data.RemoteIP);
                break;
            }
        }
Exemplo n.º 2
0
        public void NetDataManager(NetData data)
        {
            if (!isMain)
            {
                switch ((NetStatus)data.ReadByte())
                {
                case NetStatus.GetStatus:
                    NetData ngs = Manager.CreateNetData(NetID, (byte)NetStatus.SetStatus);
                    ngs.Write(Heart);
                    ngs.Write((byte)status);
                    NetServer.SendTo(ngs, data.RemoteIP);
                    break;

                case NetStatus.SetStatus:
                    heart  = data.ReadInt();
                    status = (PlayerStatus)data.ReadByte();
                    break;

                case NetStatus.Avatar:
                    head.transform.position = data.ReadVector3();
                    head.transform.rotation = data.ReadQuaternion();

                    left.transform.position = data.ReadVector3();
                    left.transform.rotation = data.ReadQuaternion();

                    right.transform.position = data.ReadVector3();
                    right.transform.rotation = data.ReadQuaternion();
                    break;

                case NetStatus.Death:
                    Death(data.RemoteIP);
                    break;

                case NetStatus.Hurt:
                    AttackInfo a = new AttackInfo();
                    a.Position = data.ReadVector3();
                    a.Rotation = data.ReadQuaternion();
                    a.Value    = data.ReadInt();
                    Hurt(a, data.RemoteIP);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private static void NetManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.GetLevel:
                NetData ngl = Manager.CreateNetData(NetID, (byte)NetStatus.SetLevel);
                ngl.Write(Level);
                NetServer.SendTo(ngl, data.RemoteIP);
                break;

            case NetStatus.SetLevel:
                int level = data.ReadInt();
                if (Level != level)
                {
                    LoadLevel(level);
                }
                break;

            case NetStatus.ResetLevel:
                LoadLevel(data.ReadInt());
                break;

            case NetStatus.GetPlayerIndex:
                NetData ngp = Manager.CreateNetData(NetID, (byte)NetStatus.SetPlayerIndex);
                ngp.Write(1);
                NetServer.SendTo(ngp, data.RemoteIP);
                break;

            case NetStatus.SetPlayerIndex:
                SetPlayerIndex(data.ReadInt());
                break;

            case NetStatus.GetGameStatus:
                NetData ngg = Manager.CreateNetData(NetID, (byte)NetStatus.SetGameStatus);
                ngg.Write((byte)GameStatus);
                NetServer.SendTo(ngg, data.RemoteIP);
                break;

            case NetStatus.SetGameStatus:
                SetGameStatus((GameStatus)data.ReadByte());
                break;

            case NetStatus.CreateGameObject:
                int        id = data.ReadInt();
                string     na = data.ReadString();
                Vector3    po = data.ReadVector3();
                Quaternion ro = data.ReadQuaternion();
                Instantiate(Prefabs[id], po, ro).name = na;
                break;

            case NetStatus.GetGameObjects:
                for (int i = 0; i < GameObjects.Count; i++)
                {
                    NetData    ng = Manager.CreateNetData(NetID, (byte)NetStatus.CreateGameObject);
                    GameObject g  = GameObjects[i];
                    ng.Write(int.Parse(g.name.Substring(0, g.name.IndexOf('_'))));
                    ng.Write(g.name);
                    ng.Write(g.transform.position);
                    ng.Write(g.transform.rotation);
                    NetServer.SendTo(ng, data.RemoteIP);
                }
                break;
            }
        }