Exemplo n.º 1
0
        public void OnDestroy()
        {
            //By default, NetworkManager destroys game objects that were spawned into the game via NetworkServer.Spawn() or NetworkServer.SpawnWithClientAuthority().
            //This is why NetworkBehaviours and MonoBehaviours could not fire OnPlayerDisconnected() and OnDisconnectedFromServer() event methods. The
            //game objects the NetworkBehaviours and MonoBehaviours had been attached to are destroyed before they have the chance to fire the event methods.

            //This hasAuthority flag checking is still required, just like any other event methods from NetworkBehaviours.
            if (!this.hasAuthority)
            {
                return;
            }

            //This is called to destroy the camera panning. When the game ends, the player shouldn't be moving around.
            GameObject[] cams = GameObject.FindGameObjectsWithTag("MainCamera");
            foreach (GameObject cam in cams)
            {
                CameraPanning panning = cam.GetComponent <CameraPanning>();
                if (panning != null)
                {
                    GameObject minimap = GameObject.FindGameObjectWithTag("Minimap");
                    if (minimap != null)
                    {
                        MinimapStuffs stuffs = minimap.GetComponent <MinimapStuffs>();
                        if (stuffs != null)
                        {
                            stuffs.playerCameraPanning = null;
                        }
                    }

                    Debug.Log("Destroying camera panning.");
                    Destroy(panning);
                }
            }
        }
Exemplo n.º 2
0
        public void RpcLog()
        {
            //First, checks to see what type of recipient is receiving this message. If it's server, the output message should tell the user what the type is.
            Debug.Log("RPC: This is " + (this.isServer ? " Server" : " Client"));

            //Second, initialize everything that is common for both server and client.
            //Camera stuff
            GameObject[] cameraObjects = GameObject.FindGameObjectsWithTag("MainCamera");
            foreach (GameObject cam in cameraObjects)
            {
                GameObject minimap = GameObject.FindGameObjectWithTag("Minimap");
                if (minimap != null)
                {
                    Material borderMaterial = Resources.Load <Material>("Border");
                    if (borderMaterial != null)
                    {
                        if (cam.GetComponent <PostRenderer>() == null)
                        {
                            cam.AddComponent <PostRenderer>();
                        }
                        PostRenderer postRenderer = cam.GetComponent <PostRenderer>();
                        if (postRenderer != null)
                        {
                            postRenderer.borderMaterial = borderMaterial;
                            postRenderer.minimapCamera  = minimap.GetComponent <Camera>();
                            if (postRenderer.minimapCamera == null)
                            {
                                Debug.LogError("Unable to assign minimap camera to post renderer.");
                            }
                        }
                    }

                    if (cam.GetComponent <CameraPanning>() == null)
                    {
                        Debug.Log("Camera Panning is added to camera. Please check.");
                        CameraPanning panning = cam.AddComponent <CameraPanning>();
                        MinimapStuffs stuffs  = minimap.GetComponent <MinimapStuffs>();
                        if (stuffs != null)
                        {
                            stuffs.playerCameraPanning = panning;
                        }
                        panning.cameraPanning = true;
                    }
                    else
                    {
                        if (!cam.GetComponent <CameraPanning>().cameraPanning)
                        {
                            cam.GetComponent <CameraPanning>().cameraPanning = true;
                        }
                    }
                }
            }

            //Finally, initialize server only stuff or client only stuff.
            //Also, finally found a use-case for [Server] / [ServerCallback]. Simplifies things a bit.
            ServerInitialize();
        }
Exemplo n.º 3
0
    public void StartLANHost()
    {
        this.PreInitialization();

        this.networkManager.StartHost();
        this.initialMenu.SetActive(false);
        this.optionsMenu.SetActive(false);
        this.LANClientReady.SetActive(false);
        this.LANClientNotReady.SetActive(false);
        this.LANHost.SetActive(true);
        this.LANClientNotConnected.SetActive(false);
        EnableAttributeEditor enableEditorObj = this.optionsMenu.GetComponentInChildren <EnableAttributeEditor>();

        if (enableEditorObj != null)
        {
            enableEditorObj.TurnOffCanvasGroup();
        }

        this.PreUnitAttributesInitialization();

        MinimapStuffs stuffs = GameObject.FindObjectOfType <MinimapStuffs>();

        if (stuffs != null)
        {
            Camera minimapCamera = stuffs.GetComponent <Camera>();
            minimapCamera.enabled      = true;
            stuffs.playerCameraPanning = Camera.main.GetComponent <CameraPanning>();
        }

        string name = this.playerNameField.text;

        if (name.Length > 0)
        {
            GameMetricLogger.instance.playerName = name;
        }
        else
        {
            GameMetricLogger.instance.playerName = "Player";
        }

        if (Taskbar.Instance != null)
        {
            Taskbar.Instance.ShowTaskbar(true);
        }

        GameMetricLogger.instance.difficultyEquations = this.difficultyDropdown.options[this.difficultyDropdown.value].text;
        GameMetricLogger.SetGameLogger(GameLoggerOptions.StartGameMetrics);
    }
Exemplo n.º 4
0
    public void StopLANHost()
    {
        //NOTE(Thompson): This is the official method of resetting the LAN session if the
        //player wants to play a new LAN session after ending a previous LAN session.
        SceneManager.LoadScene("new_multiplayer");

        //NOTE(Thompson): When reloading a scene, the GUIs are not reset to its initial states. Therefore
        //the following reinitialization codes are necessary.
        this.networkManager.StopHost();
        this.LANHost.SetActive(false);
        this.LANClientReady.SetActive(false);
        this.LANClientNotReady.SetActive(false);
        this.LANClientNotConnected.SetActive(false);
        this.initialMenu.SetActive(true);
        this.optionsMenu.SetActive(true);
        EnableAttributeEditor enableEditorObj = this.optionsMenu.GetComponentInChildren <EnableAttributeEditor>();

        if (enableEditorObj != null && enableEditorObj.isCustomOptionSelected)
        {
            enableEditorObj.TurnOnCanvasGroup();
        }

        MinimapStuffs stuffs = GameObject.FindObjectOfType <MinimapStuffs>();

        if (stuffs != null)
        {
            stuffs.playerCameraPanning = Camera.main.GetComponent <CameraPanning>();
            Camera minimapCamera = stuffs.GetComponent <Camera>();
            minimapCamera.enabled = false;
        }

        if (Taskbar.Instance != null)
        {
            Taskbar.Instance.ShowTaskbar(false);
        }

        GameMetricLogger.DisableLoggerHotkey();
        //GameMetricLogger.SetGameLogger(GameLoggerOptions.StopGameMetrics);
    }
Exemplo n.º 5
0
    public void SetClientReady()
    {
        if (!ClientScene.ready)
        {
            if (ClientScene.Ready(this.networkManager.client.connection))
            {
                Camera       cam      = Camera.main.GetComponent <Camera>();
                PostRenderer renderer = cam.GetComponent <PostRenderer>();
                if (renderer != null)
                {
                    renderer.enabled = true;
                }
                MinimapStuffs stuffs = GameObject.FindObjectOfType <MinimapStuffs>();
                if (stuffs != null)
                {
                    Camera minimapCamera = stuffs.GetComponent <Camera>();
                    minimapCamera.enabled      = true;
                    stuffs.playerCameraPanning = Camera.main.GetComponent <CameraPanning>();
                }
                this.LANClientReady.SetActive(false);
                this.LANClientNotReady.SetActive(false);

                GameMetricLogger.EnableLoggerHotkey();

                NewSpawner[] spawners = GameObject.FindObjectsOfType <NewSpawner>();
                foreach (NewSpawner spawn in spawners)
                {
                    if (spawn != null && spawn.hasAuthority)
                    {
                        NewSpawner.Instance.CmdSetReadyFlag(ClientScene.ready && !NetworkServer.active);
                    }
                }

                GameMetricLogger.SetGameLogger(GameLoggerOptions.StartGameMetrics);
            }
            else
            {
                this.LANClientReady.SetActive(false);
                this.LANClientNotReady.SetActive(true);
            }
            if (ClientScene.localPlayers.Count == 0)
            {
                ClientScene.AddPlayer(0);
            }
        }
        else
        {
            this.LANClientReady.SetActive(false);
            this.LANClientNotReady.SetActive(false);

            Camera       cam      = Camera.main.GetComponent <Camera>();
            PostRenderer renderer = cam.GetComponent <PostRenderer>();
            if (renderer != null)
            {
                renderer.enabled = true;
            }
            MinimapStuffs stuffs = GameObject.FindObjectOfType <MinimapStuffs>();
            if (stuffs != null)
            {
                Camera minimapCamera = stuffs.GetComponent <Camera>();
                minimapCamera.enabled      = true;
                stuffs.playerCameraPanning = Camera.main.GetComponent <CameraPanning>();
            }

            this.LANClientReady.SetActive(false);
            this.LANClientNotReady.SetActive(false);

            string name = this.playerNameField.text;
            if (name.Length > 0)
            {
                GameMetricLogger.instance.playerName = name;
            }
            else
            {
                GameMetricLogger.instance.playerName = "Player";
            }
            GameMetricLogger.instance.difficultyEquations = this.difficultyDropdown.options[this.difficultyDropdown.value].text;
            GameMetricLogger.EnableLoggerHotkey();

            NewSpawner[] spawners = GameObject.FindObjectsOfType <NewSpawner>();
            foreach (NewSpawner spawn in spawners)
            {
                if (spawn != null && spawn.hasAuthority)
                {
                    NewSpawner.Instance.CmdSetReadyFlag(ClientScene.ready && !NetworkServer.active);
                }
            }

            GameMetricLogger.SetGameLogger(GameLoggerOptions.StartGameMetrics);
        }

        Canvas         canvas = GameObject.FindObjectOfType <Canvas>();
        TooltipLocator loc    = canvas.GetComponent <TooltipLocator>();

        if (loc != null)
        {
            loc.tooltip.SetToolTipHidden(true);
        }
    }