浏览代码

Merge branch 'main' of https://github.com/Wiecio/open-project-1 into ciro

# Conflicts:
#	UOP1_Project/Assets/Scenes/Managers/PersistentManagers.unity
#	UOP1_Project/Assets/Scripts/Events/ScriptableObjects/LoadEventChannelSO.cs
#	UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs
#	UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs
#	UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs
/main
Ciro Continisio 3 年前
当前提交
065751a8
共有 16 个文件被更改,包括 124 次插入87 次删除
  1. 2
      UOP1_Project/Assets/Prefabs/Gameplay/SpawnSystem.prefab
  2. 6
      UOP1_Project/Assets/Scenes/Managers/PersistentManagers.unity
  3. 6
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/LoadEventChannelSO.cs
  4. 42
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/UI/FadeChannelSO.cs
  5. 21
      UOP1_Project/Assets/Scripts/Gameplay/SpawnSystem.cs
  6. 11
      UOP1_Project/Assets/Scripts/Gameplay/SpawnSystem.cs.meta
  7. 3
      UOP1_Project/Assets/Scripts/Input/InputReader.cs
  8. 4
      UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs
  9. 2
      UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs
  10. 30
      UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs
  11. 36
      UOP1_Project/Assets/Scripts/UI/FadeManager.cs
  12. 2
      UOP1_Project/Assets/Scripts/UI/UIManager.cs
  13. 16
      UOP1_Project/Assets/ScriptableObjects/EventChannels/OnSceneFadeInFinished.asset
  14. 8
      UOP1_Project/Assets/ScriptableObjects/EventChannels/OnSceneFadeInFinished.asset.meta
  15. 14
      UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeCompleteEvent.asset
  16. 8
      UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeCompleteEvent.asset.meta

2
UOP1_Project/Assets/Prefabs/Gameplay/SpawnSystem.prefab


m_Script: {fileID: 11500000, guid: 65dde41d869e66e4d87103c43970a518, type: 3}
m_Name:
m_EditorClassIdentifier:
_defaultSpawnIndex: 0
_inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
_playerPrefab: {fileID: 5557640735889932260, guid: 062b3805bf6784e4d9c599ee60eaa002,
type: 3}
_playerTransformAnchor: {fileID: 11400000, guid: 35fc4039342b6ba458d0d4429e89ee74,

6
UOP1_Project/Assets/Scenes/Managers/PersistentManagers.unity


m_EditorClassIdentifier:
_fadeChannelSO: {fileID: 11400000, guid: b40bb60f3ca40164e9d7acc6992bae10, type: 2}
_imageComponent: {fileID: 6952518526949780777}
_onFadeComplete: {fileID: 11400000, guid: cdcce1df25c2dbe4e80bee7ffe4e017b, type: 2}
--- !u!4 &1122701838
Transform:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
_gameplayScene: {fileID: 11400000, guid: a9c92d087d242344388972b3d1c4aaae, type: 2}
_inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
_loadLocation: {fileID: 11400000, guid: 00e3063edc5902e40832ea618644c597, type: 2}
_loadMenu: {fileID: 11400000, guid: 33cec85652903d245b99985f9cec9841, type: 2}
_coldStartupLocation: {fileID: 11400000, guid: 8ebfc71cf11d0ed48b2207c447690115,

_onSceneReady: {fileID: 11400000, guid: b729e40fc41dd8b4ea7aaf5c857f7186, type: 2}
_fadeRequestChannel: {fileID: 11400000, guid: b40bb60f3ca40164e9d7acc6992bae10,
type: 2}
_newSceneFadedInChannel: {fileID: 11400000, guid: 6e8dd814d5b45bc43bf37a03e1ac9fa8,
type: 2}
--- !u!4 &1416216799
Transform:
m_ObjectHideFlags: 0

6
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/LoadEventChannelSO.cs


[CreateAssetMenu(menuName = "Events/Load Event Channel")]
public class LoadEventChannelSO : EventChannelBaseSO
{
public UnityAction<GameSceneSO, bool> OnLoadingRequested;
public UnityAction<GameSceneSO, bool, bool> OnLoadingRequested;
public void RaiseEvent(GameSceneSO locationToLoad, bool showLoadingScreen = false)
public void RaiseEvent(GameSceneSO locationToLoad, bool showLoadingScreen = false, bool fadeScreen = false)
OnLoadingRequested.Invoke(locationToLoad, showLoadingScreen);
OnLoadingRequested.Invoke(locationToLoad, showLoadingScreen, fadeScreen);
}
else
{

42
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/UI/FadeChannelSO.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using UnityEngine.Events;
[CreateAssetMenu(menuName = "Events/UI/Fade Channel")]

/// Generic fade function. Communicates with <seealso cref="FadeManager.cs"/>.
/// Fade helper function to simplify usage. Fades the screen in to gameplay.
/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
/// <param name="duration">How long it takes to the image to fade in/out.</param>
/// <param name="color">Target color for the image to reach. Disregarded when fading out.</param>
public void Fade(bool fadeIn, float duration, Color color = default)
/// <param name="duration">How long it takes to the image to fade in.</param>
/// <param name="color">Target color for the image to reach.</param>
public void FadeIn(float duration)
if (color == default && fadeIn) // If no fadein color is assigned, black is given as default. If we are supposed to fadeout the rectangle, default is simply passed through.
color = Color.black;
if (OnEventRaised != null)
OnEventRaised.Invoke(fadeIn, duration, color);
Fade(true, duration, Color.clear);
/// Fade helper function to simplify usage. Fades in the rectangle.
/// Fade helper function to simplify usage. Fades the screen out to black.
/// <param name="duration">How long it takes to the image to fade in.</param>
/// <param name="color">Target color for the image to reach.</param>
public void FadeIn(float duration, Color color = default)
/// <param name="duration">How long it takes to the image to fade out.</param>
public void FadeOut(float duration)
if (color == default)
color = Color.black;
Fade(true, duration, color);
Fade(false, duration, Color.black);
/// Fade helper function to simplify usage. Fades out the rectangle.
/// Generic fade function. Communicates with <seealso cref="FadeManager.cs"/>.
/// <param name="duration">How long it takes to the image to fade out.</param>
public void FadeOut(float duration, Color color = default)
/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
/// <param name="duration">How long it takes to the image to fade in/out.</param>
/// <param name="color">Target color for the image to reach. Disregarded when fading out.</param>
private void Fade(bool fadeIn, float duration, Color color)
Fade(false, duration, color);
if (OnEventRaised != null)
OnEventRaised.Invoke(fadeIn, duration, color);
}
}

21
UOP1_Project/Assets/Scripts/Gameplay/SpawnSystem.cs


public class SpawnSystem : MonoBehaviour
{
[Header("Asset References")]
[SerializeField] private InputReader _inputReader = default;
[SerializeField] private Protagonist _playerPrefab = default;
[SerializeField] private TransformAnchor _playerTransformAnchor = default;
[SerializeField] private TransformEventChannelSO _playerInstantiatedChannel = default;

_OnSceneReady.OnEventRaised -= SpawnPlayer;
}
private void SpawnPlayer()
{
Protagonist playerInstance = InstantiatePlayer(_playerPrefab, GetSpawnLocation());
_playerInstantiatedChannel.RaiseEvent(playerInstance.transform); // The CameraSystem will pick this up to frame the player
_playerTransformAnchor.Transform = playerInstance.transform;
}
private Transform GetSpawnLocation()
{
if (_pathTaken == null)

Protagonist playerInstance = Instantiate(playerPrefab, spawnLocation.position, spawnLocation.rotation);
return playerInstance;
}
private void SpawnPlayer()
{
Protagonist playerInstance = InstantiatePlayer(_playerPrefab, GetSpawnLocation());
_playerInstantiatedChannel.RaiseEvent(playerInstance.transform); // The CameraSystem will pick this up to frame the player
_playerTransformAnchor.Transform = playerInstance.transform;
//TODO: Probably move this to the GameManager once it's up and running
_inputReader.EnableGameplayInput();
}
}

11
UOP1_Project/Assets/Scripts/Gameplay/SpawnSystem.cs.meta


MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
defaultReferences:
- _inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
- _playerPrefab: {fileID: 5557640735889932260, guid: 062b3805bf6784e4d9c599ee60eaa002,
type: 3}
- _playerTransformAnchor: {fileID: 11400000, guid: 35fc4039342b6ba458d0d4429e89ee74,
type: 2}
- _playerInstantiatedChannel: {fileID: 11400000, guid: 2723b3f59f7ede3498fe7e385d2bb6ee,
type: 2}
- _pathTaken: {fileID: 11400000, guid: a9ec09853cba047a8a58f5881053cfc6, type: 2}
- _OnSceneReady: {fileID: 11400000, guid: b729e40fc41dd8b4ea7aaf5c857f7186, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:

3
UOP1_Project/Assets/Scripts/Input/InputReader.cs


public event UnityAction<float> TabSwitched = delegate { };
private GameInput gameInput;
private void OnEnable()

gameInput.Gameplay.SetCallbacks(this);
gameInput.Dialogues.SetCallbacks(this);
}
EnableGameplayInput();
}
private void OnDisable()

4
UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs


_loadLocation.OnLoadingRequested -= CacheLoadLocations;
}
private void CacheLoadLocations(GameSceneSO locationsToLoad, bool showLoadingScreen)
private void CacheLoadLocations(GameSceneSO locationToLoad, bool showLoadingScreen, bool fadeScreen)
LocationSO locationSO = locationsToLoad as LocationSO;
LocationSO locationSO = locationToLoad as LocationSO;
if (locationSO)
{
saveData._locationId = locationSO.Guid;

2
UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs


if (_pathStorage != null)
_pathStorage.lastPathTaken = _leadsToPath;
_locationExitLoadChannel.RaiseEvent(_locationToLoad);
_locationExitLoadChannel.RaiseEvent(_locationToLoad, false, true);
}
}
}

30
UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs


public class SceneLoader : MonoBehaviour
{
[SerializeField] private GameSceneSO _gameplayScene = default;
[SerializeField] private InputReader _inputReader = default;
[Header("Load Events")]
[SerializeField] private LoadEventChannelSO _loadLocation = default;

[Header("Broadcasting on")]
[SerializeField] private BoolEventChannelSO _toggleLoadingScreen = default;
[SerializeField] private VoidEventChannelSO _onSceneReady = default;
[SerializeField] private FadeChannelSO _fadeRequestChannel = default;
private AsyncOperationHandle<SceneInstance> _loadingOperationHandle;
private AsyncOperationHandle<SceneInstance> _gameplayManagerLoadingOpHandle;

private bool _showLoadingScreen;
private SceneInstance _gameplayManagerSceneInstance = new SceneInstance();
private float _fadeDuration = .5f;
private void OnEnable()
{

/// <summary>
/// This special loading function is only used in the editor, when the developer presses Play in a Location scene, without passing by Initialisation.
/// </summary>
private void LocationColdStartup(GameSceneSO currentlyOpenedLocation, bool showLoadingScreen)
private void LocationColdStartup(GameSceneSO currentlyOpenedLocation, bool showLoadingScreen, bool fadeScreen)
if(_currentlyLoadedScene.sceneType == GameSceneSO.GameSceneType.Location)
if (_currentlyLoadedScene.sceneType == GameSceneSO.GameSceneType.Location)
{
//Gameplay managers is loaded synchronously
_gameplayManagerLoadingOpHandle = _gameplayScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true);

/// <summary>
/// This function loads the location scenes passed as array parameter
/// </summary>
private void LoadLocation(GameSceneSO locationToLoad, bool showLoadingScreen)
private void LoadLocation(GameSceneSO locationToLoad, bool showLoadingScreen, bool fadeScreen)
{
_sceneToLoad = locationToLoad;
_showLoadingScreen = showLoadingScreen;

}
else
{
UnloadPreviousScene();
StartCoroutine(UnloadPreviousScene());
}
}

UnloadPreviousScene();
StartCoroutine(UnloadPreviousScene());
private void LoadMenu(GameSceneSO menuToLoad, bool showLoadingScreen)
private void LoadMenu(GameSceneSO menuToLoad, bool showLoadingScreen, bool fadeScreen)
{
_sceneToLoad = menuToLoad;
_showLoadingScreen = showLoadingScreen;

&& _gameplayManagerSceneInstance.Scene.isLoaded)
Addressables.UnloadSceneAsync(_gameplayManagerLoadingOpHandle, true);
UnloadPreviousScene();
StartCoroutine(UnloadPreviousScene());
private void UnloadPreviousScene()
private IEnumerator UnloadPreviousScene()
_inputReader.DisableAllInput();
_fadeRequestChannel.FadeOut(_fadeDuration);
yield return new WaitForSeconds(_fadeDuration);
if (_currentlyLoadedScene != null) //would be null if the game was started in Initialisation
{
if (_currentlyLoadedScene.sceneReference.OperationHandle.IsValid())

}
/// <summary>
/// This function is called when all the scenes have been loaded
/// This function is called when all the scenes have been loaded, to finalise loading and activate the main scene, and rebuild LightProbes as tetrahedrons.
_fadeRequestChannel.FadeIn(_fadeDuration);
_onSceneReady.RaiseEvent(); //Spawn system will spawn the PigChef
_onSceneReady.RaiseEvent(); //Spawn system will spawn the PigChef in a gameplay scene
}
private void ExitGame()

36
UOP1_Project/Assets/Scripts/UI/FadeManager.cs


using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using System;
private bool _isCurrentlyFading = false;
private void OnEnable()
{

}
/// <summary>
/// Enumerator that fades in the canvas's imageComponent to turn the screen to a flat color over time. Fadeins called simeutaneously will only fade in the earliest call and discard any others.
/// </summary>
private IEnumerator FadeCoroutine(bool fadeIn, float duration, Color endColor = default)
{
Color startColor = _imageComponent.color;
if (fadeIn)
endColor = Color.clear;
float totalTime = 0f;
while (totalTime <= duration)
{
totalTime += Time.deltaTime;
_imageComponent.color = Color.Lerp(startColor, endColor, totalTime / duration);
yield return null;
}
_imageComponent.color = endColor; //Force to end result
_isCurrentlyFading = false;
}
/// <summary>
/// <param name="fadeIn">If true, rectangle fades out and gameplay is visible. If false, the screen becomes black.</param>
/// <param name="fadeIn">If false, the screen becomes black. If true, rectangle fades out and gameplay is visible.</param>
if (!_isCurrentlyFading) // Makes sure multiple fade-ins or outs don't happen at the same time. Note this will mean fadeouts called at the same time will be discarded.
{
_isCurrentlyFading = true;
StartCoroutine(FadeCoroutine(fadeIn, duration, desiredColor));
}
_imageComponent.DOBlendableColor(desiredColor, duration);
}
}

2
UOP1_Project/Assets/Scripts/UI/UIManager.cs


_interactionPanel.gameObject.SetActive(false);
_inputReader.EnableGameplayInput();
Time.timeScale = 1;
}

16
UOP1_Project/Assets/ScriptableObjects/EventChannels/OnSceneFadeInFinished.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7fafac715ff920c4383fed91a38a351e, type: 3}
m_Name: OnSceneFadeInFinished
m_EditorClassIdentifier:
description: Raised when a new scene has been loaded, and the fade in animation
is complete

8
UOP1_Project/Assets/ScriptableObjects/EventChannels/OnSceneFadeInFinished.asset.meta


fileFormatVersion: 2
guid: 6e8dd814d5b45bc43bf37a03e1ac9fa8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

14
UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeCompleteEvent.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3177d113f09ae42448cde1e1a5067d4f, type: 3}
m_Name: FadeCompleteEvent
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeCompleteEvent.asset.meta


fileFormatVersion: 2
guid: cdcce1df25c2dbe4e80bee7ffe4e017b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存