示例#1
0
    public void SaveGame(SpawnPointData _spawnPoint)
    {
        currentSpawnPoint = _spawnPoint;
        SavePlayerState(_spawnPoint);

        SaveSaveFile(m_currentSaveFileIndex, m_state);
    }
示例#2
0
    //************************//
    //    Public Functions    //
    //************************//

    public void Transition(AreaData _fromArea, SpawnPointData _spawnPoint)
    {
        if (m_transitioning)
        {
            Debug.LogWarningFormat("{0}: Transition already in progress!", name);
            return;
        }

        if (_fromArea == null)
        {
            Debug.LogErrorFormat("{0}: Origin area is null!", name);
            return;
        }

        if (_spawnPoint == null)
        {
            Debug.LogErrorFormat("{0}: Target spawn point is null!", name);
            return;
        }

        if (_spawnPoint.area == null)
        {
            Debug.LogErrorFormat("{0}: Target spawn point's area is null!", name);
            return;
        }

        Debug.LogFormat("{0}: Transitioning from area {1} to area {2} with spawn point {3}.", name, _fromArea.sceneName, _spawnPoint.area.sceneName, _spawnPoint.name);

        GameObject player = GameManager.Instance.player;

        StartCoroutine(TransitionCoroutine(_spawnPoint.area.sceneName, player, _spawnPoint));
    }
示例#3
0
    //************************//
    //    Public Functions    //
    //************************//

    public void InitializeArea(GameObject _player, SpawnPointData _spawnPoint)
    {
        SpawnPoint spawnPoint = m_spawnPoints.Find(x => x.spawnPointData == _spawnPoint);

        if (spawnPoint)
        {
            GameState gameState = GameManager.Instance.state;
            AreaState areaState = gameState.GetAreaState(m_area);
            if (areaState == null)
            {
                gameState.areaStates.Add(m_state);
            }
            else
            {
                m_state = areaState;
            }

            InitializeNormalKeys();
            InitializeLevers();

            _player.transform.position = spawnPoint.transform.position;
            CinemachineVirtualCamera cam = Instantiate(m_playerFollowCamera, _player.transform.position, Quaternion.identity).GetComponent <CinemachineVirtualCamera>();
            cam.Follow = _player.transform;
            cam.GetComponent <CinemachineConfiner>().m_BoundingShape2D = m_areaCameraBounds;
        }
        else
        {
            Debug.LogErrorFormat("{0}: Could not find spawn point {1}!", name, _spawnPoint.name);
        }
    }
示例#4
0
    public void LoadGameScene(SpawnPointData _spawnPoint, Action _callback = null)
    {
        if (m_transitioning)
        {
            Debug.LogWarningFormat("{0}: Transition already in progress!", name);
            return;
        }

        Debug.LogFormat("{0}: Loading area {1} with spawn point {2}.", name, _spawnPoint.area.sceneName, _spawnPoint.name);

        GameObject player = GameManager.Instance.player;

        StartCoroutine(TransitionCoroutine(_spawnPoint.area.sceneName, player, _spawnPoint, _callback));
    }
示例#5
0
    private SpawnPointData FindSpawnPoint(string _id)
    {
        SpawnPointData spawnPoint = null;

        foreach (var area in m_areas)
        {
            spawnPoint = area.FindSpawnPoint(_id);

            if (spawnPoint)
            {
                break;
            }
        }

        return(spawnPoint);
    }
示例#6
0
    private string GetAreaName(string _spawnPointId)
    {
        SpawnPointData spawnPoint = FindSpawnPoint(_spawnPointId);

        if (spawnPoint == null)
        {
            Debug.LogErrorFormat("{0}: Could not find spawn point {1}! Maybe the area is missing from the GameManager or the area does not reference the spawn point?", name, _spawnPointId);
            return("");
        }

        if (spawnPoint.area == null)
        {
            Debug.LogErrorFormat("{0}: Spawn point {1} does not reference an area!", name, _spawnPointId);
            return("");
        }

        return(m_areas.Find(x => x.id.Equals(spawnPoint.area.id)).name);
    }
 /// <summary>
 /// Constructs a deathmatch game resource
 /// </summary>
 public DeathmatchGameResource()
 {
     Assets.AddAssetLoader <string[], ICharacters>((data) => new Characters(data), () => new Characters());
     Assets.AddAssetLoader <RulesData, IRules>((data) => new Rules(new Vector3(data.OutOfMapPosition.X, data.OutOfMapPosition.Y, data.OutOfMapPosition.Z), new Quaternion(data.OutOfMapRotation.X, data.OutOfMapRotation.Y, data.OutOfMapRotation.Z, data.OutOfMapRotation.W), data.PlayerCharacterHealth, data.PlayerCharacterRespawnTime, data.RoundTime, data.WeaponPickupRadius, data.WeaponPickupRespawnTime), () => new Rules());
     Assets.AddAssetLoader <SpawnPointData[], ISpawnPoints>
     (
         (data) =>
     {
         ISpawnPoint[] spawn_points = new ISpawnPoint[data.Length];
         Parallel.For(0, spawn_points.Length, (index) =>
         {
             SpawnPointData spawn_point_data = data[index];
             if ((spawn_point_data == null) || !spawn_point_data.IsValid)
             {
                 throw new InvalidDataException("Spawn points contain invalid entries.");
             }
             spawn_points[index] = new SpawnPoint(new Vector3(spawn_point_data.Position.X, spawn_point_data.Position.Y, spawn_point_data.Position.Z), new Quaternion(spawn_point_data.Rotation.X, spawn_point_data.Rotation.Y, spawn_point_data.Rotation.Z, spawn_point_data.Rotation.W));
         });
         return(new SpawnPoints(spawn_points));
     },
         () => new SpawnPoints()
     );
     Assets.AddAssetLoader <WeaponData[], IWeapons>
     (
         (data) =>
     {
         IWeapon[] weapons = new IWeapon[data.Length];
         Parallel.For(0, weapons.Length, (index) =>
         {
             WeaponData weapon = data[index];
             if ((weapon == null) || !weapon.IsValid)
             {
                 throw new InvalidDataException("Weapons contain invalid weapon entries.");
             }
             weapons[index] = new Weapon(weapon.Name, weapon.Damage, weapon.UsageCount);
         });
         return(new Weapons(weapons));
     },
         () => new Weapons()
     );
 }
示例#8
0
 public SpawnPointController(SpawnPointData data)
 {
     _data = data;
 }
示例#9
0
    //*************************//
    //    Private Functions    //
    //*************************//

    private IEnumerator TransitionCoroutine(string _sceneName, GameObject _player, SpawnPointData _spawnPoint = null, Action _callback = null)
    {
        m_transitioning = true;
        float halfTransitionTime = m_transitionTime / 2f;

        if (_player.activeInHierarchy)
        {
            _player.GetComponent <PlayerMovement>().DisableUserInput(true);
        }

        m_fader.FadeIn(halfTransitionTime);
        yield return(new WaitForSeconds(halfTransitionTime));

        List <Scene> loadedScenes = new List <Scene>();

        for (int i = 0; i < SceneManager.sceneCount; i++)
        {
            loadedScenes.Add(SceneManager.GetSceneAt(i));
        }

        foreach (Scene scene in loadedScenes)
        {
            AsyncOperation unloadSceneAsync = null;
            if (scene.buildIndex != 0 && scene.isLoaded)
            {
                unloadSceneAsync = SceneManager.UnloadSceneAsync(scene);
                while (unloadSceneAsync != null && !unloadSceneAsync.isDone)
                {
                    yield return(null);
                }
            }
        }

        _player.SetActive(false);

        AsyncOperation loadSceneAsync = null;

        if (!SceneManager.GetSceneByName(_sceneName).isLoaded)
        {
            loadSceneAsync = SceneManager.LoadSceneAsync(_sceneName, LoadSceneMode.Additive);
            while (loadSceneAsync != null && !loadSceneAsync.isDone)
            {
                Debug.LogFormat("{0}: Loading scene: {1}%", name, loadSceneAsync.progress * 100f);
                yield return(null);
            }
        }

        Scene toScene = SceneManager.GetSceneByName(_sceneName);

        SceneManager.SetActiveScene(toScene);

        if (_spawnPoint != null)
        {
            AreaController controller = FindObjectOfType <AreaController>();
            controller.InitializeArea(_player, _spawnPoint);

            _player.SetActive(true);
            _player.GetComponent <PlayerMovement>().DisableUserInput(false);
        }

        m_fader.FadeOut(halfTransitionTime);
        m_transitioning = false;

        SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(0));

        _callback?.Invoke();
        onAreaLoaded?.Invoke();
    }
示例#10
0
    //*************************//
    //    Private Functions    //
    //*************************//

    private void SavePlayerState(SpawnPointData _spawnPoint)
    {
        m_state.playerState.currentSpawnPoint = _spawnPoint.id;
        m_state.playerState.normalKeyCount    = m_currentPlayer.GetComponent <PlayerInventory>().normalKeyCount;
        m_state.playerState.health            = m_currentPlayer.GetComponent <PlayerCombat>().currentHealth;
    }
示例#11
0
 public PlayerState(SpawnPointData _currentSpawnPoint)
 {
     currentSpawnPoint = _currentSpawnPoint.id;
     normalKeyCount    = 0;
     health            = 10;
 }
示例#12
0
 public GameState(SpawnPointData _currentSpawnPoint)
 {
     playerState = new PlayerState(_currentSpawnPoint);
     areaStates  = new List <AreaState>();
 }