Example #1
0
        public override void OnJoinedLobby()
        {
            networkState = NetworkState.Connected;

            gameSession = FindObjectOfType <ExampleGameSession>();
            if (gameSession)
            {
                gameSession.OnJoinedLobby();
            }
        }
Example #2
0
        public override void OnServerCreated()
        {
            // Create game session
            ExampleGameSession oldSession = FindObjectOfType <ExampleGameSession>();

            if (oldSession == null)
            {
                GameObject serverSession = Instantiate(gameSessionPrefab);
                NetworkServer.Spawn(serverSession);
            }
            else
            {
                Debug.LogError("GameSession already exists!");
            }
        }
        public override void OnStartClient()
        {
            if (instance)
            {
                Debug.LogError("ERROR: Another GameSession!");
            }
            instance = this;

            networkListener             = FindObjectOfType <ExampleListener>();
            networkListener.gameSession = this;

            _networkTransmitter = GetComponent <NetworkTransmitter> ();

            if (gameState != GameState.Lobby)
            {
                gameState = GameState.Lobby;
            }
        }
        public void Update()
        {
            string synced = locationSynced ? "SYNC" : "NO";

            totalPointsField.text = "Points: " + totalPoints.ToString() + synced;
            if (rollResult > 0)
            {
                rollResultField.text = "Roll: " + rollResult.ToString();
            }
            else
            {
                rollResultField.text = "";
            }

            if (Input.touchCount < 1)
            {
                return;
            }

            //the instantiation current curve logic
            ExampleGameSession gameSession = ExampleGameSession.instance;

            if (isLocalPlayer && gameSession && gameSession.gameState == GameState.WaitingForRolls)
            {
                Touch touch = Input.GetTouch(0);

                if (touch.phase == TouchPhase.Began)
                {
                    Debug.Log("touched");
                    //Ray raycast = Camera.main.ScreenPointToRay(touch.position);
                    //Vector3 point = raycast.GetPoint(0.1f);

                    //fire missile across all clients
                    CmdFireMissile();

                    // }else if(touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){
                    //     //if the user right click, then finished this bezier
                    //     Debug.Log("stop draw");
                    //     currentBezier.GetComponent<BezierMaster.BezierMaster>().stop = true;
                    //     currentBezier = null;
                    //     canStartDraw = true;
                }
            }
        }
        //the gui that is displayed on the user's screen

        void OnGUI()
        {
            if (isLocalPlayer)
            {
                GUILayout.BeginArea(new Rect(0, Screen.height * 0.8f, Screen.width, 100));
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                ExampleGameSession gameSession = ExampleGameSession.instance;
                if (gameSession)
                {
                    if (gameSession.gameState == GameState.Lobby ||
                        gameSession.gameState == GameState.Countdown)
                    {
                        if (GUILayout.Button(IsReady() ? "Not ready" : "Ready", GUILayout.Width(Screen.width * 0.3f), GUILayout.Height(100)))
                        {
                            if (IsReady())
                            {
                                SendNotReadyToBeginMessage();
                            }
                            else
                            {
                                SendReadyToBeginMessage();
                            }
                        }
                    }
                    else if (gameSession.gameState == GameState.WaitForLocationSync)
                    {
                        //world map is sent during location sync
                        //cmd is client to server
                        if (isServer && !locationSent)
                        {
                            gameSession.CmdSendWorldMap();
                            locationSent = true;
                        }
                    }
                    else if (gameSession.gameState == GameState.WaitingForRolls)
                    {
                        //enter if statement if touched the button
                        // if (GUILayout.Button ("Make Sphere", GUILayout.Width (Screen.width * 0.6f), GUILayout.Height (100))) {
                        //  Transform camTransform = _exampleARSessionManager.CameraTransform ();
                        //  Vector3 spherePosition = camTransform.position + (camTransform.forward.normalized * 0.02f); //place sphere 2cm in front of device
                        //  CmdMakeSphere (spherePosition,camTransform.rotation);
                        // }

                        //display player health on the screen
                        //need to get player health from playerHealthScript to display
                        // string health = "Health: " + playerHealth.ToString();
                        // GUILayout.Box(health, GUILayout.Width(Screen.width * 0.3f), GUILayout.Height(50));
                    }
                    else if (gameSession.gameState == GameState.GameOver)
                    {
                        if (isServer)
                        {
                            if (GUILayout.Button("Play Again", GUILayout.Width(Screen.width * 0.3f), GUILayout.Height(100)))
                            {
                                CmdPlayAgain();
                            }
                        }
                    }
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.EndArea();
            }
        }