Exemplo n.º 1
0
    public void JoinCustom()
    {
        /*
         *      There should be only number-inputs
         */

        if (ChannelInput.text != "")
        {
            LocalUserData.SetUserName(InputName.text);

            Dictionary <string, string> data = new Dictionary <string, string> ();

            data ["name"]       = InputName.text;
            data ["roomnumber"] = ChannelInput.text;

            /*
             * TODO: player position will be set from server-side
             */
            Vector3 position = new Vector3(0f, 0f, 0f);
            data ["position"] = position.x + "," + position.y + "," + position.z;

            SocketIOComp.Emit("SERVER:JOINCUSTOM", new JSONObject(data));

            HideChannelWindow();
            GlobalGameState.DialogueUI.Show(DialogueUIController.DialogueTypes.JoiningRoom);
        }
        else
        {
            ChannelInputPlaceHolder.text = "Channel number is necessary!";
        }
    }
Exemplo n.º 2
0
    public void OnClickJoinBtn()
    {
        if (InputName.text != "")
        {
            LocalUserData.SetUserName(InputName.text);

            Dictionary <string, string> data = new Dictionary <string, string> ();

            data ["name"] = InputName.text;

            /*
             *      TODO: player position will be set from server-side
             *      probably send spawn area from here?
             */
            Vector3 position = new Vector3(0f, 0f, 0f);
            data ["position"] = position.x + "," + position.y + "," + position.z;

            Vector3 rotation = new Vector3(0f, 0f, 0f);
            data ["rotation"] = rotation.x + "," + rotation.y + "," + rotation.z;

            SocketIOComp.Emit("SERVER:JOIN", new JSONObject(data));

            GlobalGameState.DialogueUI.Show(DialogueUIController.DialogueTypes.JoiningRoom);
        }
        else
        {
            InputNamePlaceHolder.text = "Nickname is necessary!";
        }
    }
Exemplo n.º 3
0
    void UpdateInput()
    {
        // rotation //------------------------------------------------------------
        // default when there is no position input from player

        Vector3 newBodyRotation = CharacterObject.transform.rotation.eulerAngles;
        float   yaw             = UserInputControl.Yaw();

        if (yaw != 0f)
        {
            // reminder - Euler(pitch , yaw , roll)
            newBodyRotation = CharacterObject.transform.rotation.eulerAngles + new Vector3(0f, yaw * Sensitivity * Time.deltaTime, 0f);

            CharacterObject.transform.rotation = Quaternion.Euler(newBodyRotation);
        }

        Vector3 newPosition = CharacterObject.transform.position;

        CharacterObject.Rb.MovePosition(CharacterObject.transform.position +
                                        CharacterObject.transform.forward * MoveSpeed * Time.deltaTime * BoostValue);

        newPosition = CharacterObject.transform.position;

        // network //------------------------------------------------------------
        PacketTimer += Time.deltaTime;
        if (PacketTimer > PacketLimit)
        {
            Dictionary <string, string> data = new Dictionary <string, string> ();
            data ["transform"]   = newPosition.x + "," + newPosition.z + "," + newBodyRotation.y;
            data ["elapsedTime"] = Time.timeSinceLevelLoad.ToString();
            SocketIOComp.Emit("SERVER:MOVE", new JSONObject(data));

            PacketTimer = 0f;
        }
    }
Exemplo n.º 4
0
    void SendChat(string msg)
    {
        Dictionary <string, string> data = new Dictionary <string, string> ();

        data ["chatmsg"] = msg;

        SocketIOComp.Emit("SERVER:CHATSEND", new JSONObject(data));

        InputMsg.text = "";
    }
Exemplo n.º 5
0
    IEnumerator Connection()
    {
        yield return(new WaitForSeconds(1f));

        if (!ServerConnected)
        {
            DialogueUI.Show(DialogueUIController.DialogueTypes.ConnectingServer);
            SocketIOComp.Emit("SERVER:CONNECT");
        }
        StartCoroutine(Connection());
    }
Exemplo n.º 6
0
    public void ResetLobbyState()
    {
        GlobalGameState.IsPlayerReady = false;

        Dictionary <string, string> data = new Dictionary <string, string> ();

        data ["ready"] = "0";

        SocketIOComp.Emit("SERVER:USER_READY", new JSONObject(data));
        LeaveGameBtn.gameObject.SetActive(false);
        JoinGameBtn.gameObject.SetActive(true);
    }
Exemplo n.º 7
0
    public void LeaveRoom()
    {
        SocketIOComp.Emit("SERVER:LEAVE");

        //GlobalGameState.Disconnect ();
        GlobalGameState.HandleLeaveGame();
        GlobalGameState.HideAllUI();

        GlobalGameState.LoginUI.Show();

        // set spectate cam on!
        GlobalGameState.SpectateCam.gameObject.SetActive(false);
    }
Exemplo n.º 8
0
    void UpdateInput()
    {
        // rotation //------------------------------------------------------------
        // default when there is no position input from player

        Vector3 newBodyRotation = CharacterObject.transform.rotation.eulerAngles;
        float   yaw             = UserInputControl.Yaw();

//#if UNITY_EDITOR
        // debug purpose
        yaw = Input.GetAxis("Horizontal");
//#endif

        if (yaw != 0f)
        {
            // reminder - Euler(pitch , yaw , roll)
            newBodyRotation = CharacterObject.transform.rotation.eulerAngles + new Vector3(0f, yaw * RotationSensitivity * Time.deltaTime, 0f);
            CharacterObject.transform.rotation = Quaternion.Euler(newBodyRotation);
        }

        Vector3 newPosition    = CharacterObject.transform.position;
        Vector3 targetPosition = newPosition;
        float   smoothTime     = 0.3f;

        if (Bumping)
        {
            smoothTime = 0.038f;

            CharacterObject.transform.rotation = Quaternion.Euler(Vector3.SmoothDamp(CharacterObject.transform.rotation.eulerAngles, CharacterObject.transform.rotation.eulerAngles + new Vector3(0f, Random.Range(-15f, 15f), 0f), ref refRot, 0.02f));
            targetPosition = CharacterObject.transform.position + -CharacterObject.transform.forward * CarCollisionBounceDist * BumpRate;
        }
        else
        {
            targetPosition = CharacterObject.transform.position + CharacterObject.transform.forward * MoveSpeed * BoostValue;
        }

        CharacterObject.transform.position = Vector3.SmoothDamp(CharacterObject.transform.position, targetPosition, ref CurrentVelocity, smoothTime);
        newPosition = CharacterObject.transform.position;

        // network //------------------------------------------------------------
        PacketTimer += Time.deltaTime;
        if (PacketTimer > PacketLimit)
        {
            Dictionary <string, string> data = new Dictionary <string, string> ();
            data ["transform"]   = newPosition.x + "," + newPosition.z + "," + newBodyRotation.y;
            data ["elapsedTime"] = Time.timeSinceLevelLoad.ToString();
            SocketIOComp.Emit("SERVER:MOVE", new JSONObject(data));

            PacketTimer = 0f;
        }
    }
Exemplo n.º 9
0
    private void OnPlayerSetup(SocketIOEvent evt)
    {
        Debug.Log("creating character/controller");

        CharacterType PlayType = (CharacterType)JsonToInt(evt.data.GetField("type").ToString(), "\"");

        bool isSimulated = false;

        Debug.Log("Creating players controller and character:" + PlayType);

        if (PlayType == CharacterType.Blender)         // case blender
        {
            GameObject prefab = Instantiate(BlenderControllerPrefab);
            PlayerBlenderController = prefab.GetComponent <BlenderController> ();
            PlayerBlenderController.CharacterObject = CreateCharacter(evt, isSimulated, BlenderPrefab) as Blender;
            Debug.Log("Created Blender:" + PlayerBlenderController.CharacterObject);
            Blenders.Add(PlayerBlenderController.CharacterObject);

            // for blender 3rd person cam
            GameObject cam = Instantiate(ThirdCam, PlayerBlenderController.CharacterObject.transform.position + ThirdCam.transform.position, ThirdCam.transform.rotation);

            ThirdCamComp = cam.GetComponent <ThirdPersonCamera> ();
            ThirdCamComp.gameObject.SetActive(true);
            ThirdCamComp.GetComponent <ThirdPersonCamera>().Setup(PlayerBlenderController.CharacterObject.gameObject);
            ThirdCamComp.BlenderCamStick = PlayerBlenderController.JoystickCam;
        }
        else if (PlayType == CharacterType.Killer)
        {
            GameObject prefab = Instantiate(KillerControllerPrefab);
            PlayerKillerController = prefab.GetComponent <KillerController> ();
            PlayerKillerController.CharacterObject = CreateCharacter(evt, isSimulated, KillerPrefab) as Killer;
            Debug.Log("Created Killer:" + PlayerKillerController.CharacterObject);
            Killers.Add(PlayerKillerController.CharacterObject);

            // for killer 1st person cam
            GameObject cam = Instantiate(FirstCam);
            FirstCamComp = cam.GetComponent <FirstPersonCamera> ();
            FirstCamComp.gameObject.SetActive(true);
            FirstCamComp.gameObject.transform.position = PlayerKillerController.CharacterObject.HeadTransform.position;
            FirstCamComp.gameObject.transform.parent   = PlayerKillerController.CharacterObject.HeadTransform;
        }

        SocketIOComp.Emit("SERVER:CREATE_FOR_OTHERPLAYER");

        // create NPC blenders
        if (GlobalGameState.IsNPCBlenderMaster)
        {
            GlobalMapManager.CreateNPCBlenders(NPCCount);
        }
    }
Exemplo n.º 10
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        if (JoystickRotate && CharacterObject)
        {
            // rotation //------------------------------------------------------------
            float yaw = JoystickRotate.Yaw();
            if (yaw != 0f)
            {
                // reminder - Euler(pitch , yaw , roll)
                Vector3 newBodyRotation = JoystickRotate.BaseBodyRotation + new Vector3(0f, yaw * SensitivityYaw, 0f);

                CharacterObject.transform.rotation = Quaternion.Euler(newBodyRotation);

                Dictionary <string, string> data = new Dictionary <string, string> ();
                data ["rotation"]    = 0 + "," + newBodyRotation.y;
                data ["elapsedTime"] = Time.timeSinceLevelLoad.ToString();

                SocketIOComp.Emit("SERVER:ROTATE_BLENDER", new JSONObject(data));
            }

            // position //------------------------------------------------------------
            // TODO: have to get walking animation turn off for local character when they are stuck in the wall and not moving
            if (movement > 0f)
            {
                //Debug.Log (CharacterObject.transform.forward * MoveSpeed * movement * Time.deltaTime);
                CharacterObject.Rb.MovePosition(CharacterObject.Rb.position + CharacterObject.transform.forward * MoveSpeed * movement * Time.deltaTime);
                movement -= 1f * Time.deltaTime;

                Vector3 newPosition = CharacterObject.transform.position;

                Dictionary <string, string> data = new Dictionary <string, string> ();
                data ["position"]    = newPosition.x + "," + newPosition.y + "," + newPosition.z;
                data ["elapsedTime"] = Time.timeSinceLevelLoad.ToString();

                //Debug.Log ("Attempting move:" + data["rotation"]);
                SocketIOComp.Emit("SERVER:WALK_BLENDER", new JSONObject(data));
            }
            else
            {
                if (CharacterObject.Anim.GetBool("Walk") == true)
                {
                    CharacterObject.Anim.SetBool("Walk", false);
                }
            }
        }
    }
Exemplo n.º 11
0
    private void OnGameState(SocketIOEvent evt)
    {
        GameStateEnum gameState = (GameStateEnum)JsonToInt(evt.data.GetField("gamestate").ToString(), "\"");

        Debug.Log("////////// GAMESTATE CHANGE ////////// ::" + gameState);

        if (gameState == GameStateEnum.Spectate)
        {
            HideAllUI();
            LobbyUI.Show();
            GameUI.ShowWithOption(GameUIController.GameUIState.Lobby);
            OnSpectateChangeCamera(gameState);
        }
        else if (gameState == GameStateEnum.IsWaitingForGameStart)
        {
            HideAllUI();
            LobbyUI.Show();
            GameUI.ShowWithOption(GameUIController.GameUIState.Lobby);
            OnSpectateChangeCamera(gameState);
        }
        else if (gameState == GameStateEnum.IsPlaying)
        {
            HideAllUI();
            GameUI.ShowWithOption(GameUIController.GameUIState.InGame);
            ChatUI.Show();

            OnSpectateChangeCamera(gameState);
            IsNPCBlenderMaster = JsonToBool(evt.data.GetField("npc_master").ToString(), "\"");
            NPCCount           = int.Parse(evt.data.GetField("npc_count").ToString());

            SocketIOComp.Emit("SERVER:READY_GAMESTART");
        }
        else if (gameState == GameStateEnum.EndedGame)
        {
            HideAllUI();

            WinSide winSide = (WinSide)JsonToInt(evt.data.GetField("winside").ToString(), "\"");
            GameEndUI.SetState(winSide);
            GameEndUI.Show();

            ClearScene();

            SocketIOComp.Emit("SERVER:ENDED_GAME");

            OnSpectateChangeCamera(gameState);
        }
    }
Exemplo n.º 12
0
    public void LeaveGame(bool IsByPlayerWill)
    {
        SocketIOComp.Emit("SERVER:LEAVE_GAME");

        //GlobalGameState.Disconnect ();
        GlobalGameState.HandleLeaveGame();
        GlobalGameState.HideAllUI();

        if (IsByPlayerWill)
        {
            GlobalGameState.LobbyUI.ResetLobbyState();
        }
        GlobalGameState.LobbyUI.Show();
        GlobalGameState.GameUI.ShowWithOption(GameUIController.GameUIState.Lobby);

        // set spectate cam on!
        GlobalGameState.SpectateCam.gameObject.SetActive(true);
    }
Exemplo n.º 13
0
    public void TryKill()
    {
        RaycastHit objectHit;
        Vector3    fwd = CharacterObject.gameObject.transform.forward + new Vector3(0f, 0.5f, 0f);

        if (Physics.Raycast(CharacterObject.gameObject.transform.position, fwd, out objectHit, KillDist))
        {
            if (objectHit.collider == null || objectHit.collider.gameObject == null)
            {
                return;
            }

            Blender blender = objectHit.collider.gameObject.GetComponent <Blender>();
            if (blender != null)
            {
                Debug.Log("Killing blender:" + blender.gameObject.name);

                blender.Kill(CharacterObject.gameObject.name);

                Dictionary <string, string> data = new Dictionary <string, string> ();
                data ["id"] = blender.id;
                SocketIOComp.Emit("SERVER:KILL_BLENDER", new JSONObject(data));

                if (blender.IsNPC)
                {
                    KillerLife--;
                    KillerLifeUI [KillerLife].gameObject.SetActive(false);

                    LeanTween.value(DamageUI.gameObject, DamageClrStart, DamageClrPeak, .07f).setOnUpdate((Color val) => {
                        DamageUI.color = val;
                    }).setLoopPingPong(1);

                    if (KillerLife == 0)
                    {
                        KillerDie();
                    }
                }
            }
        }
    }
Exemplo n.º 14
0
    IEnumerator PingUpdate()
    {
        SocketIOComp.Emit("SERVER:PING");
        pingtime = Time.timeSinceLevelLoad;

        yield return(new WaitForSeconds(1f));

        // check server is connected
        float lastpongduration = Mathf.Abs(Time.timeSinceLevelLoad - lastpongtime);

        if (lastpongduration > 4f)
        {
            DisconnectBehaviour();
        }

        if (pingdone)
        {
            pongtime          = pongtime * 1000f;
            ResponseText.text = (int)pongtime + "ms";
            pingdone          = false;
        }
        StartCoroutine(PingUpdate());
    }
Exemplo n.º 15
0
    public void CreateNPCBlenders(int count)
    {
        RandomizeArray(NPCSpawnPointsArray);

        for (int i = 0; i < count; i++)
        {
            Transform t = NPCSpawnPointsArray [i].transform;

            GameObject npcBlender = Instantiate(GlobalGameState.BlenderNPCPrefab, t.position, t.rotation);

            string npcid = "npcid_" + i.ToString();
            npcBlender.GetComponent <BlenderNPCController> ().blender.id = npcid;
            npcBlender.GetComponent <Blender> ().IsNPC = true;

            Dictionary <string, string> data = new Dictionary <string, string> ();
            data ["npcid"]    = npcid;
            data ["name"]     = npcid;
            data ["position"] = npcBlender.transform.position.x + "," + npcBlender.transform.position.y + "," + npcBlender.transform.position.z;
            data ["rotation"] = 0 + "," + npcBlender.transform.position.y;
            SocketIOComp.Emit("SERVER:BLENDER_NPC_CREATE", new JSONObject(data));

            GlobalGameState.BlenderNPCs.Add(npcBlender.GetComponent <Blender>());
        }
    }
Exemplo n.º 16
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        if (JoystickMove && JoystickCam && CharacterObject)
        {
            // debug ray for kill
            Vector3 fwd = CharacterObject.gameObject.transform.forward + new Vector3(0f, 0.5f, 0f);
            Debug.DrawRay(CharacterObject.gameObject.transform.position, fwd * KillDist, Color.red);

            float x = JoystickMove.Vertical();
            float z = JoystickMove.Horizontal();

            float yaw   = JoystickCam.Yaw();
            float pitch = JoystickCam.Pitch();

            bool IsDirtyPlayerPositionOnNetwork = false;
            bool IsDirtyPlayerRotationOnNetwork = false;

            //debug
            //Vector3 forward = CharacterObject.gameObject.transform.forward * 2f;
            //Debug.DrawRay(CharacterObject.gameObject.transform.position, forward, Color.green);

            GameObject playerGameObject = CharacterObject.gameObject;

            // position //------------------------------------------------------------
            // default when there is no position input from player
            Vector3 newPosition = playerGameObject.transform.position;

            if (x != 0f || z != 0f)
            {
                newPosition = playerGameObject.transform.position
                              + playerGameObject.transform.forward * x * SensitivityX
                              + playerGameObject.transform.right * z * SensitivityZ;

                CharacterObject.Rb.MovePosition(newPosition);
                //playerGameObject.transform.position = newPosition;
                IsDirtyPlayerPositionOnNetwork = true;
            }

            // rotation //------------------------------------------------------------
            // default when there is no rotation input from player
            Vector3 newBodyRotation = playerGameObject.transform.rotation.eulerAngles;
            Vector3 newHeadRotation = CharacterObject.HeadTransform.localRotation.eulerAngles;

            if (yaw != 0f || pitch != 0f)
            {
                // reminder - Euler(pitch , yaw , roll)
                newBodyRotation = /*JoystickCam.BaseBodyRotation*/ playerGameObject.transform.rotation.eulerAngles + new Vector3(0f, yaw * SensitivityYaw, 0f);
                //newHeadRotation = JoystickCam.BaseHeadLocalRotation + new Vector3 (pitch * SensitivityPitch, 0f, 0f);
                newHeadRotation = JoystickCam.BaseHeadLocalRotation - new Vector3(pitch * SensitivityPitch, 0f, 0f);

                playerGameObject.transform.rotation         = Quaternion.Euler(newBodyRotation);
                CharacterObject.HeadTransform.localRotation = Quaternion.Euler(newHeadRotation);

                IsDirtyPlayerRotationOnNetwork = true;
            }

            // network //------------------------------------------------------------
            if (IsDirtyPlayerPositionOnNetwork || IsDirtyPlayerRotationOnNetwork)
            {
                Dictionary <string, string> data = new Dictionary <string, string> ();
                data ["position"] = newPosition.x + "," + newPosition.y + "," + newPosition.z;
                data ["rotation"] = newHeadRotation.x + "," + newBodyRotation.y;

                //Debug.Log ("Attempting move:" + data["position"]);
                SocketIOComp.Emit("SERVER:MOVE_KILLER", new JSONObject(data));
            }
        }
    }
Exemplo n.º 17
0
    void Update()
    {
        /*
         * TODO: this should control any clients NPC's action handle. e.g. eating, attacking and stuff
         */

        if (!GlobalGameState.IsNPCBlenderMaster)
        {
            return;
        }

        if (GlobalGameState.IsNPCOnSiren && !IsOneRest)
        {
            StopCoroutine(routine);
            routine = null;

            IsOneRest = true;

            float nextActionDue = Random.Range(0.5f, 1.5f);
            Invoke("DoResting", nextActionDue);
        }
        else if (!GlobalGameState.IsNPCOnSiren && IsOneRest)
        {
            IsOneRest = false;

            RestartNPCAction();

            float nextActionDue = Random.Range(1.5f, 2.5f);
            Invoke("DoWalking", nextActionDue);
        }

        if (Vector3.Distance(navMeshAgent.destination, gameObject.transform.position) < 4f)
        {
            navMeshAgent.SetDestination(GetNewDestination());
        }

        float threshold = navMeshAgent.speed * 0.086f;

        if (navMeshAgent.velocity.magnitude < threshold)
        {
            blender.Anim.SetBool("Walk", false);
        }
        else if (navMeshAgent.velocity.magnitude > threshold && blender.Anim.GetBool("Walk") == false)
        {
            blender.Anim.SetBool("Walk", true);
        }

        if (!navMeshAgent.isStopped)
        {
            Dictionary <string, string> data = new Dictionary <string, string> ();
            data ["position"]    = gameObject.transform.position.x + "," + gameObject.transform.position.y + "," + gameObject.transform.position.z;
            data ["elapsedTime"] = Time.timeSinceLevelLoad.ToString();
            data ["npcid"]       = blender.id.ToString();
            SocketIOComp.Emit("SERVER:BLENDER_NPC_MOVE", new JSONObject(data));
        }

        if (prevRot != gameObject.transform.rotation)
        {
            Dictionary <string, string> data = new Dictionary <string, string> ();
            data ["rotation"]    = 0 + "," + gameObject.transform.rotation.eulerAngles.y;
            data ["elapsedTime"] = Time.timeSinceLevelLoad.ToString();
            data ["npcid"]       = blender.id.ToString();
            SocketIOComp.Emit("SERVER:BLENDER_NPC_ROTATE", new JSONObject(data));

            prevRot = gameObject.transform.rotation;
        }
    }
Exemplo n.º 18
0
 void JoinGame()
 {
     SocketIOComp.Emit("SERVER:JOIN");
 }