Ejemplo n.º 1
0
    public override void Awake()
    {
        base.Awake();

        m_PlayerCameras = new Camera[4];
        m_PlayerCameraConfigurations = new PlayerCameraData[4][];
        // P1                                            P2                                         P3                                            P4
        m_PlayerCameraConfigurations[0] = new PlayerCameraData[] { new PlayerCameraData(0f, 0f, 1f, 1f) };                                                                                                                                                      // 1 player
        m_PlayerCameraConfigurations[1] = new PlayerCameraData[] { new PlayerCameraData(0f, 0f, 0.5f, 1f), new PlayerCameraData(0.5f, 0f, 0.5f, 1f) };                                                                                                          // 2 players
        m_PlayerCameraConfigurations[2] = new PlayerCameraData[] { new PlayerCameraData(0f, 0.5f, 0.5f, 0.5f), new PlayerCameraData(0.5f, 0.5f, 0.5f, 0.5f), new PlayerCameraData(0.25f, 0f, 0.5f, 0.5f) };                                                     // 3 players
        m_PlayerCameraConfigurations[3] = new PlayerCameraData[] { new PlayerCameraData(0f, 0.5f, 0.5f, 0.5f), new PlayerCameraData(0.5f, 0.5f, 0.5f, 0.5f), new PlayerCameraData(0f, 0f, 0.5f, 0.5f), new PlayerCameraData(0.5f, 0f, 0.5f, 0.5f) };            // 4 players
    }
Ejemplo n.º 2
0
    // private void OnCompanionEquipped()

    private void OnDungeonBuilt(GameEvents.DungeonBuiltEvent e)
    {
        //Instantiate(m_CameraPrefab, null);
        //CameraManager.Instance.ToggleCameraSettings(true);

        // TODO
        // this should get moved to some other event when the item is equipped, so this is spawned
        Instantiate(m_CompanionPrefab, null);

        if (LobbyManager.Instance.OfflineGame)
        {
            int connectedPlayerCount = LobbyManager.Instance.ConnectedPlayerCount;
            for (int i = 0; i < connectedPlayerCount; i++)
            {
                GameObject playerObj    = (GameObject)Instantiate(m_PlayerPrefab, e.StartPosition, e.StartRotation);
                GameObject playerCam    = (GameObject)Instantiate(m_CameraPrefab, CameraManager.Instance.MainCamera.transform);
                GameObject hudCanvasObj = (GameObject)Instantiate(m_CanvasPrefab, null);

                int playerSaveSlot = LobbyManager.Instance.GetLobbyDataForPlayer(i).m_SaveSlot;

                // set each player camera to show the hud
                Camera camera = playerCam.GetComponent <Camera>();
                CameraManager.Instance.RegisterPlayerCamera(i, camera);

                // hacky hack
                // Unity doesn't support multiple AudioListeners, which is a problem for splitscreen! You downloaded a unity package has been downloaded for it, but for now, disable on player cameras
                AudioListener listener = camera.GetComponent <AudioListener>();
                listener.enabled = false;

                Canvas playerHudCanvas = hudCanvasObj.GetComponent <Canvas>();
                if (playerHudCanvas != null)
                {
                    playerHudCanvas.worldCamera   = camera;
                    playerHudCanvas.planeDistance = 1;
                }

                // there is a better way to do this (put a script on the canvas, get it, and it stores this info), but this is faster and it's late
                Transform   hudObj           = hudCanvasObj.transform.GetChild(0).GetChild(i);
                UIPlayerHUD currentPlayerHUD = hudObj.GetComponent <UIPlayerHUD>();
                if (currentPlayerHUD != null)
                {
                    CharacterProgress currentProgress = CharacterManager.Instance.GetProgressForCharacterInSlot(playerSaveSlot);
                    CharacterStats    currentStats    = currentProgress.m_Stats;

                    currentPlayerHUD.SetPlayerName(currentStats.PlayerName);
                    currentPlayerHUD.SetPlayerLevel(currentStats.Level);

                    currentStats.OnLevelChanged += currentPlayerHUD.SetPlayerLevel;
                    currentStats.OnEXPAdded     += currentPlayerHUD.SetXP;
                    currentStats.OnHPModified   += currentPlayerHUD.SetHP;
                    currentStats.OnMPModified   += currentPlayerHUD.SetMP;

                    // trigger a restore to fire the events
                    currentStats.Restore(Enums.eStatType.HP);
                    currentStats.Restore(Enums.eStatType.MP);
                    currentStats.AddEXP(0);
                }

                // init camera controller for each player
                CameraController camController = playerCam.GetComponent <CameraController>();
                if (camController != null)
                {
                    camController.SetPlayerInfo(i, playerObj.transform);
                    if (connectedPlayerCount > 1)
                    {
                        if (camera != null)
                        {
                            PlayerCameraData camData = CameraManager.Instance.GetCameraDataForPlayer(i, connectedPlayerCount - 1);
                            camera.rect = new Rect(camData.X, camData.Y, camData.W, camData.H);
                        }
                    }
                }

                Player p = playerObj.GetComponent <Player>();
                if (p != null)
                {
                    p.Init(i, playerSaveSlot);
                    p.AssignCamera(playerCam.transform);
                }
            }
        }
    }