浏览代码

Updated addressables package, changed scene loading logic

/AdsTesting
Arturo Nereu 4 年前
当前提交
c1a20622
共有 9 个文件被更改,包括 289 次插入59 次删除
  1. 2
      Assets/Prefabs/Player.prefab
  2. 215
      Assets/Scenes/Level_00.unity
  3. 4
      Assets/Scenes/LoadingScene.unity
  4. 1
      Assets/Scenes/MainMenu.unity
  5. 73
      Assets/Scripts/GameManager.cs
  6. 43
      Assets/Scripts/Loading.cs
  7. 2
      Assets/Scripts/PlayerController.cs
  8. 2
      Packages/manifest.json
  9. 6
      Packages/packages-lock.json

2
Assets/Prefabs/Player.prefab


m_Script: {fileID: 11500000, guid: 3a698c89160b64541b11228f3098737b, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MovementSpeed: 5
m_MovementSpeed: 10
--- !u!1 &4494805130408427599
GameObject:
m_ObjectHideFlags: 0

215
Assets/Scenes/Level_00.unity


m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &132965559
GameObject:

m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &329427703
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3885950393804571643, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_Name
value: Chest
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalPosition.x
value: 4.111226
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.31
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalPosition.z
value: 0.46950468
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3885950393804571647, guid: a49919fd62cf3f44b9ba4444a5be522e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a49919fd62cf3f44b9ba4444a5be522e, type: 3}
--- !u!1 &525691375
GameObject:
m_ObjectHideFlags: 0

m_Children:
- {fileID: 1674584037}
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}

--- !u!1001 &947877972
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalPosition.x
value: -0.5469064
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.9
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalPosition.z
value: -2.3055155
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759893, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4494805130079759894, guid: 67db914bd437a69468c6d966454659b0,
type: 3}
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 67db914bd437a69468c6d966454659b0, type: 3}
--- !u!1 &977978634
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &988604871
GameObject:

- {fileID: 1182208737}
- {fileID: 525691376}
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 5
--- !u!1001 &1015844850
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalPosition.x
value: 0.15579855
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.9268
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalPosition.z
value: 4.3154144
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759978, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5495074216500759982, guid: 2be31233ae02d3441993b4ff8846e96f,
type: 3}
propertyPath: m_Name
value: Door
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2be31233ae02d3441993b4ff8846e96f, type: 3}
--- !u!1 &1182208736
GameObject:
m_ObjectHideFlags: 0

4
Assets/Scenes/LoadingScene.unity


m_HandleRect: {fileID: 0}
m_Direction: 0
m_MinValue: 0
m_MaxValue: 1
m_MaxValue: 100
m_Value: 0.524
m_Value: 0
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []

1
Assets/Scenes/MainMenu.unity


m_Script: {fileID: 11500000, guid: 9a82635b139e4af468b5fec0e262a853, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MaxAvailableLevel: 0
--- !u!4 &1421386032
Transform:
m_ObjectHideFlags: 0

73
Assets/Scripts/GameManager.cs


using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
private int m_CurrentLevel = 0;
public static int m_CurrentLevel = 0;
private int m_MaxAvailableLevel = 0;
public int m_MaxAvailableLevel = 0;
AsyncOperationHandle<SceneInstance> m_SceneHandle;
private static AsyncOperationHandle<SceneInstance> m_GameplaySceneHandle;
private static AsyncOperationHandle<SceneInstance> m_LoadingSceneHandle;
private void OnDestroy()
//private void OnDestroy()
//{
// // TODO: Check for null
// //m_SceneHandle.Completed -= OnSceneLoaded;
//}
// Instance method to get called from a UI raised event
public void StartGameplay()
{
LoadLoadingScene();
}
public static void LoadLoadingScene()
// TODO: Check for null
//m_SceneHandle.Completed -= OnSceneLoaded;
// TODO: Add handle
m_LoadingSceneHandle = Addressables.LoadSceneAsync("LoadingScene", UnityEngine.SceneManagement.LoadSceneMode.Additive, false);
m_LoadingSceneHandle.Completed += OnLoadingSceneLoaded;
public void StartGameplay()
public static void LoadGameplayScene()
Addressables.LoadSceneAsync("LoadingScene", UnityEngine.SceneManagement.LoadSceneMode.Single, true).Completed += OnSceneLoaded;
m_GameplaySceneHandle = Addressables.LoadSceneAsync("Level_0" + m_CurrentLevel, UnityEngine.SceneManagement.LoadSceneMode.Additive, false);
m_CurrentLevel++;
m_GameplaySceneHandle.Completed += OnGameplayLevelLoaded;
Addressables.LoadSceneAsync("MainMenu", UnityEngine.SceneManagement.LoadSceneMode.Single, true).Completed += OnSceneLoaded;
//Restore the first level to be played
m_CurrentLevel = 0;
Addressables.LoadSceneAsync("MainMenu", UnityEngine.SceneManagement.LoadSceneMode.Single, true).Completed += OnLoadingSceneLoaded;
//TODO: Replace this hardcoded code to increase the level
Debug.Log("Loading next level");
// Load the Loading scene
Addressables.LoadSceneAsync("LoadingScene", UnityEngine.SceneManagement.LoadSceneMode.Single, true);
//Addressables.UnloadSceneAsync(Scenema)
//LoadLevel(++currentLevel);
//TODO: Add handle
LoadLoadingScene();
public void LoadLevel(int levelToLoad)
static void OnLoadingSceneLoaded(AsyncOperationHandle<SceneInstance> sceneHandle)
Debug.Log("Trying to load scene " + levelToLoad);
Addressables.LoadSceneAsync("Level_0"+ levelToLoad, UnityEngine.SceneManagement.LoadSceneMode.Additive, true).Completed += OnSceneLoaded;
sceneHandle.Result.ActivateAsync();
//if (m_GameplaySceneHandle.IsValid())
//{
// Addressables.UnloadSceneAsync(m_GameplaySceneHandle);
//}
m_LoadingSceneHandle.Completed -= OnLoadingSceneLoaded;
void OnSceneLoaded(AsyncOperationHandle<SceneInstance> sceneHandle)
static void OnGameplayLevelLoaded(AsyncOperationHandle<SceneInstance> sceneHandle)
Debug.Log("Scene Loaded");
sceneHandle.Result.ActivateAsync();
if (m_GameplaySceneHandle.IsValid())
{
Addressables.UnloadSceneAsync(m_LoadingSceneHandle);
}
//m_GameplaySceneHandle.Completed -= OnGameplayLevelLoaded;
}
}

43
Assets/Scripts/Loading.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using System;

// Start is called before the first frame update
void Start()
{
//TODO: Change the
m_SceneHandle = Addressables.LoadSceneAsync("Level_00", UnityEngine.SceneManagement.LoadSceneMode.Single, false);
m_SceneHandle.Completed += OnSceneLoaded;
//TODO: Change the
GameManager.LoadGameplayScene();
private void OnSceneLoaded(AsyncOperationHandle<SceneInstance> obj)
{
// The scene is loaded, show the button and now turn the scene on?
m_PlayButton.SetActive(true);
}
//private void OnSceneLoaded(AsyncOperationHandle<SceneInstance> obj)
//{
// // The scene is loaded, show the button and now turn the scene on?
// m_PlayButton.SetActive(true);
//}
public void LoadNextLevel()
{
if(m_SceneHandle.Status == AsyncOperationStatus.Succeeded)
{
m_SceneHandle.Result.ActivateAsync();
}
}
//public void LoadNextLevel()
//{
// if (m_SceneHandle.Status == AsyncOperationStatus.Succeeded)
// {
// m_SceneHandle.Result.ActivateAsync();
// }
//}
private void Update()
{
m_LoadingSlider.value = m_SceneHandle.PercentComplete;
}
//private void Update()
//{
// m_LoadingSlider.value = m_SceneHandle.PercentComplete;
//}
}

2
Assets/Scripts/PlayerController.cs


Debug.Log("Opened the door");
//TODO: Cache this object search
GameObject.FindObjectOfType<GameManager>().LevelCompleted();
GameManager.LoadLoadingScene();
}
}
}

2
Packages/manifest.json


{
"dependencies": {
"com.unity.addressables": "1.16.15",
"com.unity.addressables": "1.16.16",
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.2.3",

6
Packages/packages-lock.json


{
"dependencies": {
"com.unity.addressables": {
"version": "1.16.15",
"version": "1.16.16",
"com.unity.scriptablebuildpipeline": "1.15.1",
"com.unity.scriptablebuildpipeline": "1.15.2",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0"

"url": "https://packages.unity.com"
},
"com.unity.scriptablebuildpipeline": {
"version": "1.15.1",
"version": "1.15.2",
"depth": 1,
"source": "registry",
"dependencies": {},

正在加载...
取消
保存