示例#1
0
    private void Awake()
    {
        other_player_prefab = Resources.Load("Prefabs/OtherPlayerPrefab", typeof(OtherPlayerPrafab)) as OtherPlayerPrafab;
        dummy_player_prefab = Resources.Load("Prefabs/DummyPlayerPrefab", typeof(DummyPlayerPrefab)) as DummyPlayerPrefab;

        nm = GameObject.FindWithTag("Network").GetComponent <NetworkManagerSingleton>();

        NetworkManager.ClearPacketProcessHandler();
        NetworkManager.SetPacketProcessHandler(packetProcess);

        msgQueue      = MessageQueue.getInstance;
        player_object = GameObject.FindWithTag("Player");//.GetComponent<Transform>() as GameObject;
        other_players = new Dictionary <int, OtherPlayerPrafab>();
        map_data      = new Dictionary <int, Map>();

        /*
         * Map HanGang = new Map();
         *
         * HanGang.Id = 100;
         * HanGang.Name = "한강";
         * HanGang.Thumbnail = "Sprite/MapImages/Hangang";
         * HanGang.SceneName = "TrackGameHangangMap";
         *
         * map_data[HanGang.Id] = HanGang;*/

        Map Track = new Map();

        Track.Id           = 101;
        Track.Name         = "원형 트랙";
        Track.Thumbnail    = "Sprite/MapImages/Track";
        Track.SceneName    = "TrackScene";
        map_data[Track.Id] = Track;

        SetActiveResetButton(false);
    }
示例#2
0
    private void ProcessMessage(Message msg)
    {
        switch (msg.Type)
        {
        case MessageType.SCENE_CHANGE_LOGIN_TO_LOBBY:
        {
            Message _msg = new Message(MessageType.SCENE_CHANGE_LOGIN_TO_LOBBY);

            server_ip   = msg.GetParam(0).ToString();
            server_port = (short)msg.GetParam(1);

            NetworkManager.Connect(server_ip, server_port);

            while (NetworkManager.isConnected() != true)
            {
            }

            PACKET_REQ_PLAYER_ENTER packet = new PACKET_REQ_PLAYER_ENTER();

            packet.Init();

            login_id  = msg.GetParam(2).ToString();
            login_pwd = msg.GetParam(3).ToString();

            packet.login_id = login_id;
            packet.password = login_pwd;

            byte[] data = Utility.ToByteArray((object)packet);

            NetworkManager.Send(data);

            break;
        }

        case MessageType.SCENE_CHANGE_TRACKGAME_TO_WORLD:
        {
            Vector3 pos = (Vector3)msg.GetParam(0);

            player_object.transform.position = pos;

            Debug.Log("Return from Track Game!");

            break;
        }

        case MessageType.NOTIFY_PLAYER_ENTER:
        {
            int uid = (int)msg.GetParam(0);

            if (other_players.ContainsKey(uid) == false)
            {
                OtherPlayerPrafab op = Instantiate(other_player_prefab, new Vector3(-1, 10.2f, -1), Quaternion.identity) as OtherPlayerPrafab;
                op.name.text = msg.GetParam(1).ToString();
                float x = (float)msg.GetParam(2);
                float y = (float)msg.GetParam(3);
                float z = (float)msg.GetParam(4);

                op.SetPosition(x, y, z);
                op.SetPath(pathes.nonplayer_front_path);

                other_players.Add(uid, op);
            }

            break;
        }

        case MessageType.NOTIFY_PLAYER_EXIT:
        {
            int uid = (int)msg.GetParam(0);

            if (other_players.ContainsKey(uid))
            {
                Destroy(other_players[uid].gameObject);
                other_players.Remove(uid);
            }

            break;
        }

        case MessageType.UPDATE_USER_POSITION:
        {
            float x = (float)msg.GetParam(1);
            float y = (float)msg.GetParam(2);
            float z = (float)msg.GetParam(3);
            float v = (float)msg.GetParam(4);

            user.x = x;
            user.y = y;
            user.z = z;

            if ((int)msg.GetParam(0) == user.userUid)
            {
                //float cz = player_object.transform.position.y;

                //Vector3 v = new Vector3(x, cz, y);
                //player_object.transform.position = v;
            }
            else
            {
                int uid = (int)msg.GetParam(0);

                if (other_players.ContainsKey(uid))
                {
                    //other_players[uid].UpdatePosition(x, y, z);
                    other_players[uid].Speed = v;
                }
            }

            break;
        }

        case MessageType.UPDATE_FORECAST_INFO:
        {
            switch ((byte)msg.GetParam(0))
            {
            case 1:
                current_forecast = Forecast.Rain;
                weather.SetRain(0.0f);
                break;

            case 2:
                current_forecast = Forecast.Snow;
                weather.SetSnow(0.0f);
                break;

            case 3:
                current_forecast = Forecast.Snow;
                weather.SetSnow(0.0f);
                break;

            default:
                current_forecast = Forecast.Sunny;
                weather.SetSunny();
                break;
            }

            try
            {
                // Param의 Index 0은 current_forecast에 사용.
                // 나머진 1부터 시작해서 총 10까지의 인덱스로 조회한다.

                /*
                 * [{"type":"LGT","value":1}, 낙뢰
                 * {"type":"PTY","value":1}, 강수 형태 없음(0), 비(1), 비/눈(2), 눈(3)
                 * {"type":"REH","value":90}, 습도   %
                 * {"type":"RN1","value":4.6}, 강수량 mm/h
                 * {"type":"SKY","value":4}, 하늘 상태  1 맑음 2,3 구름 4 흐림
                 * {"type":"T1H","value":22.5}, 기온    섭씨
                 * {"type":"UUU","value":-1.2}, 동서 풍속
                 * {"type":"VEC","value":99}, 풍향
                 * {"type":"VVV","value":0.2}, 남북 풍속
                 * {"type":"WSD","value":1.3}] 풍속  m/s
                 */
                weatherUI.DisplayUpdate((int)current_forecast,
                                        (float)msg.GetParam(4),
                                        (float)msg.GetParam(10),
                                        (float)msg.GetParam(6),
                                        (float)msg.GetParam(3));
            }
            catch (System.Exception)
            {
            }

            break;
        }

        case MessageType.RES_PLAYER_ENTER:
        {
            player_object.GetComponent <BikeControlMachine>().player_name = user.username;
            playerName.text = user.username;

            InitGamePlay();

            break;
        }

        case MessageType.UPDATE_FORECAST_HUD_INFO:
        {
            break;
        }

        case MessageType.GET_MY_REPLAY_DATA:
        {
            int    index       = (int)msg.GetParam(0);
            byte[] records     = (byte[])msg.GetParam(1);
            double record_time = (double)msg.GetParam(2);

            replayManager.Put(index, records, record_time);

            if (replayButtons[index].Index < 0)
            {
                replayButtons[index].Index = index;
                replayButtons[index].SetTimeString(record_time);
                replayButtons[index].play_event += OpenWorld_play_event;
                replayButtons[index].stop_event += OpenWorld_stop_event;
                replayButtons[index].Show();
            }

            break;
        }

        case MessageType.GET_MY_RECORD_DATA:
        {
            double record_time = (double)msg.GetParam(0);
            rankPage.SetMyBestRecord(record_time);
            Debug.Log("Get My Record " + record_time);
            break;
        }
        }
    }