浏览代码

Main menu and loading bar scripts

/main
Unknown 4 年前
当前提交
082ef4fb
共有 4 个文件被更改,包括 112 次插入0 次删除
  1. 53
      UOP1_Project/Assets/Scripts/LoadingBar.cs
  2. 11
      UOP1_Project/Assets/Scripts/LoadingBar.cs.meta
  3. 37
      UOP1_Project/Assets/Scripts/MainMenu.cs
  4. 11
      UOP1_Project/Assets/Scripts/MainMenu.cs.meta

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();
}
}

11
UOP1_Project/Assets/Scripts/LoadingBar.cs.meta


fileFormatVersion: 2
guid: e72f0bf25bcf9874bbeb271ccae55dde
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

37
UOP1_Project/Assets/Scripts/MainMenu.cs


using System.Collections;
using System.Collections.Generic;
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 space bar in the Scenes Loader scene
//Just for test purpose
if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
onGameStart.Raise();
}
}
public void ExitGame()
{
Application.Quit();
Debug.Log("Exit dude!");
}
}

11
UOP1_Project/Assets/Scripts/MainMenu.cs.meta


fileFormatVersion: 2
guid: 8ade5a748610bf348a549932627f98d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存