浏览代码

Changes before switching to simpler loading approach

/AdsTesting
Arturo Nereu 4 年前
当前提交
baccf45d
共有 8 个文件被更改,包括 300 次插入85 次删除
  1. 60
      Assets/Scenes/MainMenu.unity
  2. 68
      Assets/Scripts/GameManager.cs
  3. 25
      Assets/Scripts/Loading.cs
  4. 2
      Assets/Scripts/PlayerController.cs
  5. 192
      Assets/Scenes/Bootstrap.unity
  6. 7
      Assets/Scenes/Bootstrap.unity.meta
  7. 20
      Assets/Scripts/UISetup.cs
  8. 11
      Assets/Scripts/UISetup.cs.meta

60
Assets/Scenes/MainMenu.unity


- component: {fileID: 1140220494}
- component: {fileID: 1140220493}
- component: {fileID: 1140220492}
- component: {fileID: 1140220496}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged

m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1140220496
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1140220491}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c2b2588ea3013ce4bba037f2ce4b22fe, type: 3}
m_Name:
m_EditorClassIdentifier:
m_StartButton: {fileID: 1893815542}
--- !u!1 &1265336762
GameObject:
m_ObjectHideFlags: 0

m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1421386030
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1421386032}
- component: {fileID: 1421386031}
m_Layer: 0
m_Name: Game Manager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1421386031
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1421386030}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9a82635b139e4af468b5fec0e262a853, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MaxAvailableLevel: 0
--- !u!4 &1421386032
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1421386030}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 386.46088, y: 809.9503, z: -3533}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1893815540
GameObject:
m_ObjectHideFlags: 0

m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1421386031}
- m_Target: {fileID: 0}
m_MethodName: StartGameplay
m_Mode: 1
m_Arguments:

68
Assets/Scripts/GameManager.cs


public class GameManager : MonoBehaviour
{
public static int m_CurrentLevel = 0;
public static int s_CurrentLevel = 0;
// TODO: Maybe just have it inside the Start method and not class-wide
private static AsyncOperationHandle<SceneInstance> m_GameplaySceneHandle;
public static AsyncOperationHandle<SceneInstance> s_GameplaySceneHandle;
private static AsyncOperationHandle<SceneInstance> m_LoadingSceneHandle;
public static AsyncOperationHandle<SceneInstance> s_MainMenuSceneHandle;
public static AsyncOperationHandle<SceneInstance> s_LoadingSceneHandle;
//private void OnDestroy()
//{
// // TODO: Check for null
// //m_SceneHandle.Completed -= OnSceneLoaded;
//}
private void Start()
{
//TODO: subscribe and release handle
s_MainMenuSceneHandle = Addressables.LoadSceneAsync("MainMenu", UnityEngine.SceneManagement.LoadSceneMode.Additive, true);
}
public void StartGameplay()
public static void StartGameplay()
{
LoadLoadingScene();
}

// TODO: Add handle
m_LoadingSceneHandle = Addressables.LoadSceneAsync("LoadingScene", UnityEngine.SceneManagement.LoadSceneMode.Additive, false);
s_LoadingSceneHandle = Addressables.LoadSceneAsync("LoadingScene", UnityEngine.SceneManagement.LoadSceneMode.Additive, false);
m_LoadingSceneHandle.Completed += OnLoadingSceneLoaded;
s_LoadingSceneHandle.Completed += OnLoadingSceneLoaded;
m_GameplaySceneHandle = Addressables.LoadSceneAsync("Level_0" + m_CurrentLevel, UnityEngine.SceneManagement.LoadSceneMode.Additive, false);
s_GameplaySceneHandle = Addressables.LoadSceneAsync("Level_0" + s_CurrentLevel, UnityEngine.SceneManagement.LoadSceneMode.Additive, false);
m_CurrentLevel++;
s_CurrentLevel++;
m_GameplaySceneHandle.Completed += OnGameplayLevelLoaded;
s_GameplaySceneHandle.Completed += OnGameplayLevelLoaded;
m_CurrentLevel = 0;
s_CurrentLevel = 0;
public void LevelCompleted()
public static void LevelCompleted()
{
//TODO: Add handle
LoadLoadingScene();

{
sceneHandle.Result.ActivateAsync();
s_LoadingSceneHandle.Result.ActivateAsync();
if (s_GameplaySceneHandle.IsValid())
{
Debug.Log("Unloaded gameplay scene");
Addressables.UnloadSceneAsync(s_GameplaySceneHandle, true);
}
//if (m_GameplaySceneHandle.IsValid())
//{
// Addressables.UnloadSceneAsync(m_GameplaySceneHandle);
//}
m_LoadingSceneHandle.Completed -= OnLoadingSceneLoaded;
if(s_MainMenuSceneHandle.IsValid())
{
Debug.Log("Unloaded mainmenu scene");
Addressables.UnloadSceneAsync(s_MainMenuSceneHandle, true);
}
s_LoadingSceneHandle.Completed -= OnLoadingSceneLoaded;
sceneHandle.Result.ActivateAsync();
s_GameplaySceneHandle.Completed -= OnGameplayLevelLoaded;
}
public static void ActivateGameplayScene()
{
s_GameplaySceneHandle.Result.ActivateAsync();
if (m_GameplaySceneHandle.IsValid())
if (s_GameplaySceneHandle.IsValid())
Addressables.UnloadSceneAsync(m_LoadingSceneHandle);
Addressables.UnloadSceneAsync(s_LoadingSceneHandle);
//m_GameplaySceneHandle.Completed -= OnGameplayLevelLoaded;
}
}

25
Assets/Scripts/Loading.cs


using UnityEngine;
using UnityEngine.UI;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using System;

AsyncOperationHandle<SceneInstance> m_SceneHandle;
// Start is called before the first frame update
void Start()
void OnEnable()
m_SceneHandle = GameManager.s_GameplaySceneHandle;
m_SceneHandle.Completed += OnSceneLoaded;
//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);
m_SceneHandle.Completed -= OnSceneLoaded;
}
//public void LoadNextLevel()
//{

// }
//}
//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
GameManager.LoadLoadingScene();
GameManager.LevelCompleted();
}
}
}

192
Assets/Scenes/Bootstrap.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1001 &1874710524
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622123, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7356380717090622125, guid: d8e9e493da0735346a9e17cf1b363eab,
type: 3}
propertyPath: m_Name
value: GameManager
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d8e9e493da0735346a9e17cf1b363eab, type: 3}

7
Assets/Scenes/Bootstrap.unity.meta


fileFormatVersion: 2
guid: 53c12bb6be8617f48893c94bdd01382e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

20
Assets/Scripts/UISetup.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISetup : MonoBehaviour
{
public Button m_StartButton;
// Start is called before the first frame update
private void Start()
{
m_StartButton.onClick.AddListener(GameManager.StartGameplay);
}
private void OnDisable()
{
m_StartButton.onClick.RemoveListener(GameManager.StartGameplay);
}
}

11
Assets/Scripts/UISetup.cs.meta


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