浏览代码

Remove old files

/main
Unknown 4 年前
当前提交
09bb47ff
共有 9 个文件被更改,包括 0 次插入336 次删除
  1. 14
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevel.asset
  2. 14
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevelWithProgress.asset
  3. 22
      UOP1_Project/Assets/Scriptable Objects/sceneDB.asset
  4. 8
      UOP1_Project/Assets/Scriptable Objects/sceneDB.asset.meta
  5. 21
      UOP1_Project/Assets/Scripts/Scriptable Objects/Events/GameEvent.cs
  6. 142
      UOP1_Project/Assets/Scripts/Scriptable Objects/SceneManagement/ScenesData.cs
  7. 53
      UOP1_Project/Assets/Scripts/LoadingBar.cs
  8. 35
      UOP1_Project/Assets/Scripts/MainMenu.cs
  9. 27
      UOP1_Project/Assets/Scripts/ClearLists.cs

14
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevel.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: 04ea2f19feb15654cb31bb60f7f50855, type: 3}
m_Name: GameEvent_LoadNextLevel
m_EditorClassIdentifier:

14
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevelWithProgress.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: 04ea2f19feb15654cb31bb60f7f50855, type: 3}
m_Name: GameEvent_LoadNextLevelWithProgress
m_EditorClassIdentifier:

22
UOP1_Project/Assets/Scriptable Objects/sceneDB.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: a7fc45397100a9f4d91861b943fccfc5, type: 3}
m_Name: sceneDB
m_EditorClassIdentifier:
levels:
- {fileID: 11400000, guid: 2f386bbc670c05145834a0f9c7d55798, type: 2}
- {fileID: 11400000, guid: d102ba8fe3b291249aeb9de4b95c1904, type: 2}
menus:
- {fileID: 11400000, guid: 431ff81b74b48fb4d9301fb76ca633dd, type: 2}
CurrentLevelIndex: 1
scenesToLoadNames: []
scenesToUnLoadNames: []

8
UOP1_Project/Assets/Scriptable Objects/sceneDB.asset.meta


fileFormatVersion: 2
guid: 3cbb90f50a82e01409b7c5fc69f1d429
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

21
UOP1_Project/Assets/Scripts/Scriptable Objects/Events/GameEvent.cs


using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class GameEvent : ScriptableObject
{
private List<GameEventListener> listeners =
new List<GameEventListener>();
public void Raise()
{
for (int i = listeners.Count - 1; i >= 0; i--)
listeners[i].OnEventRaised();
}
public void RegisterListener(GameEventListener listener)
{ listeners.Add(listener); }
public void UnregisterListener(GameEventListener listener)
{ listeners.Remove(listener); }
}

142
UOP1_Project/Assets/Scripts/Scriptable Objects/SceneManagement/ScenesData.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[CreateAssetMenu(fileName = "sceneDB", menuName = "Scene Data/Database")]
public class ScenesData : ScriptableObject
{
public List<Level> levels = new List<Level>();
public List<Menu> menus = new List<Menu>();
public int CurrentLevelIndex=-1;
//List of the scenes to load and track progress
public List<AsyncOperation> scenesToLoad = new List<AsyncOperation>();
//List of the scenes names to load and unload
//Scenes to load and unload should be added/Removed to/from the list before calling load and unload methods
public List<string> scenesToLoadNames = new List<string>();
public List<string> scenesToUnLoadNames = new List<string>();
/*
* Clear
*/
//Clear Scenes to load and unload list
public void ClearScenesLists()
{
scenesToLoadNames.Clear();
scenesToUnLoadNames.Clear();
//Reset index
CurrentLevelIndex = -1;
}
/*
* Levels
*/
//Load a scene with a given index
public void LoadLevelWithIndex(int index)
{
//reset the level index if we have no more levels
if (index >= levels.Count)
{
index = 1;
CurrentLevelIndex = index;
}
//Load level
scenesToLoadNames.Add(levels[index].sceneName);
LoadScenes();
//Add previous level to scenes to unload
if (index > 0)
{
scenesToUnLoadNames.Add(levels[index - 1].sceneName);
}
//Unload previous level if it exists
if(scenesToUnLoadNames.Count == 0)
{
return;
}
else
{
UnloadScenes();
}
}
public void LoadScenes()
{
for (int i = 0; i < scenesToLoadNames.Count; ++i)
{
if (!CheckLoadState(scenesToLoadNames[i]))
{
//Add the scene to the list of scenes to load asynchronously in the background
scenesToLoad.Add(SceneManager.LoadSceneAsync(scenesToLoadNames[i], LoadSceneMode.Additive));
//Remove scene from list of scenes to load
scenesToLoadNames.Remove(scenesToLoadNames[i]);
}
}
}
public void UnloadScenes()
{
for (int i = 0; i < scenesToUnLoadNames.Count; ++i)
{
//Unload the scene asynchronously in the background
SceneManager.UnloadSceneAsync(scenesToUnLoadNames[i]);
//Remove scene from list of scenes to unload
scenesToUnLoadNames.Remove(scenesToUnLoadNames[i]);
}
}
//Check if a scene is already loaded
public bool CheckLoadState(String sceneName)
{
if (SceneManager.sceneCount > 0)
{
for (int i = 0; i < SceneManager.sceneCount; ++i)
{
Scene scene = SceneManager.GetSceneAt(i);
if (scene.name == sceneName)
{
return true;
}
}
}
return false;
}
//Start next level
public void NextLevel()
{
CurrentLevelIndex++;
LoadLevelWithIndex(CurrentLevelIndex);
}
//Restart current level
public void RestartLevel()
{
LoadLevelWithIndex(CurrentLevelIndex);
}
/*
* Menus
*/
//Load main Menu
public void LoadMainMenu()
{
//scenesToLoadNames.Add("MainMenu");
scenesToLoadNames.Add(menus[(int)Type.Main_Menu].sceneName);
LoadScenes();
}
//Load Pause Menu
public void LoadPauseMenu()
{
//Add later if needed
}
}

53
UOP1_Project/Assets/Scripts/LoadingBar.cs


using UnityEngine.UI;
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class LoadingBar : MonoBehaviour
{
public GameObject loadingInterface;
public Image loadingProgressBar;
public ScenesData scenesData;
//List of the scenes to load
private List<AsyncOperation> currentScenesToLoad = new List<AsyncOperation>();
public void UpdateProgress()
{
StartCoroutine(LoadingScreen());
}
IEnumerator LoadingScreen()
{
for (int i = 0; i< scenesData.scenesToLoad.Count; ++i)
{
currentScenesToLoad.Add(scenesData.scenesToLoad[i]);
}
float totalProgress = 0, newProgress = 0;
//When the scene reaches 0.9f, it means that it is loaded
//The remaining 0.1f are for the integration
while (totalProgress <= 0.9f)
{
//Get the latest progress value
totalProgress = newProgress;
//Reset the progress for the new values
newProgress = 0;
//Iterate through all the scenes to load
for (int i = 0; i < currentScenesToLoad.Count; ++i)
{
Debug.Log("check loading of scene " + i + " :" + currentScenesToLoad[i].isDone + "progress scene" + currentScenesToLoad[i].progress);
//Adding the scene progress to the total progress
newProgress += currentScenesToLoad[i].progress;
//the fillAmount for all scenes, so we devide the progress by the number of scenes to load
loadingProgressBar.fillAmount = totalProgress / currentScenesToLoad.Count;
Debug.Log("progress bar" + loadingProgressBar.fillAmount + "and value =" + totalProgress / currentScenesToLoad.Count);
}
yield return null;
}
//Hide progress bar when loading is done
loadingInterface.SetActive(false);
currentScenesToLoad.Clear();
}
}

35
UOP1_Project/Assets/Scripts/MainMenu.cs


using UnityEngine;
using UnityEngine.InputSystem;
public class MainMenu : MonoBehaviour
{
//Check the bool to load MM from ScenesLoaders on start
public bool LoadOnStart;
public GameEvent onGameStart;
public void Start()
{
if (LoadOnStart)
{
onGameStart.Raise();
}
}
public void Update()
{
//We can load the main menu by pressing l in the Scenes Loader scene
//Just for test purpose
if (Keyboard.current.lKey.wasPressedThisFrame)
{
onGameStart.Raise();
}
}
public void ExitGame()
{
Application.Quit();
Debug.Log("Exit dude!");
}
}

27
UOP1_Project/Assets/Scripts/ClearLists.cs


using UnityEngine.InputSystem;
using UnityEngine;
public class ClearLists : MonoBehaviour
{
public ScenesData scenesData;
public bool ClearOnStart;
void Awake()
{
if (ClearOnStart)
{
scenesData.ClearScenesLists();
}
}
void Update()
{
//We can clear lists by pressing c
//Just for test purpose
if (Keyboard.current.cKey.wasPressedThisFrame)
{
scenesData.ClearScenesLists();
}
}
}
正在加载...
取消
保存