0

所以我有问题。

我正在为我们的最终项目开发一个游戏,并且我正在使用场景加载添加剂来加载所有场景)。所以问题是......当我通过编辑器测试/玩游戏时一切正常,所有场景都按预期加载 SceneManager.LoadSceneAsync(sceneIndex,LoadSceneMode.Additive)。但是当我创建一个构建时,应该用 LoadSceneAsycn 加载的假定场景没有出现......

我将尝试在这里留下一些使用的代码,并尝试解释逻辑

当我加载第一级时,我还将加载下一个场景,为此我创建了一个脚本,它将选择下一个应该加载的场景:

private void Start() {
    switch (goToScene) {
        case GoToScene.LABORATORY:
            GameManager.ForceAsyncLoad(2);
            break;
        case GoToScene.GARAGE:
            GameManager.ForceAsyncLoad(3);
            break;
    }
}

然后它将从我的协程 GameManager 中调用 ForceAsyncLoad 方法:

IEnumerator LoadAsync(int sceneIndex) {
   AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex, LoadSceneMode.Additive);

     while (!operation.isDone) {
         yield return null;
     }

     SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(sceneIndex));

     Debug.Log("Scene Additive Load Completed");

}

好的,到目前为止...这就是我加载场景添加剂所要做的一切,但由于某种原因,在编辑器上这可以按预期工作,但是当我创建构建时它不会加载。

此外,加载场景时几乎所有对象都被禁用,只有一两个游戏对象处于活动状态。其中一个是角色通过时的触发器,它将启用该场景中的对象。

我将在这里留下我的最后一个构建日志:

Mono path[0] = 'D:/UnityFinishedGames/TBA-Master-D/BetaVersion/TBA-MasterD_Data/Managed'
Mono config path = 'D:/UnityFinishedGames/TBA-Master-D/BetaVersion/MonoBleedingEdge/etc'
PlayerConnection initialized from D:/UnityFinishedGames/TBA-Master-D/BetaVersion/TBA-MasterD_Data (debug = 0)
PlayerConnection initialized network socket : 0.0.0.0 55357
Multi-casting "[IP] 192.168.1.67 [Port] 55357 [Flags] 2 [Guid] 839978317 [EditorId] 2132102930 [Version] 1048832 [Id] WindowsPlayer(DESKTOP-H2EGAS4) [Debug] 1 [PackageName] WindowsPlayer [ProjectName] TBA-MasterD" to [225.0.0.222:54997]...
Started listening to [0.0.0.0:55357]
Starting managed debugger on port 56317
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=0.0.0.0:56317
PlayerConnection already initialized - listening to [0.0.0.0:55357]
Initialize engine version: 2019.4.16f1 (e05b6e02d63e)
[Subsystems] Discovering subsystems at path D:/UnityFinishedGames/TBA-Master-D/BetaVersion/TBA-MasterD_Data/UnitySubsystems
GfxDevice: creating device client; threaded=1
Direct3D:
    Version:  Direct3D 11.0 [level 11.1]
    Renderer: NVIDIA GeForce GTX 1070 (ID=0x1b81)
    Vendor:   (null)
    VRAM:     3072 MB
    Driver:   30.0.14.7141
Begin MonoManager ReloadAssembly
- Completed reload, in  0.342 seconds
D3D11 device created for Microsoft Media Foundation video decoding.
<RI> Initializing input.

<RI> Input initialized.

<RI> Initialized touch support.

UnloadTime: 0.657200 ms
Unloading 6 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 52.699800 ms
System memory in use before: 215.6 MB.
System memory in use after: 189.3 MB.

Unloading 29 unused Assets to reduce memory usage. Loaded Objects now: 11007.
Total: 51.210800 ms (FindLiveObjects: 0.710300 ms CreateObjectMapping: 0.140200 ms MarkObjects: 49.202300 ms  DeleteObjects: 1.157200 ms)

The referenced script on this Behaviour (Game Object 'ExitAndTopLevelStairs') is missing! 
(Filename: C:\buildslave\unity\build\Runtime/Mono/ManagedMonoBehaviourRef.cpp Line: 334)

Saving Game...
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
SaveSystemManager:SaveGame(Checkpoint, List`1) (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\SaveSystem\SaveSystemManager.cs:64)
SaveSystemManager:Save(Checkpoint, List`1) (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\SaveSystem\SaveSystemManager.cs:112)
Checkpoint:OnTriggerEnter(Collider) (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\SaveSystem\Checkpoint.cs:29)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/SaveSystem/SaveSystemManager.cs Line: 64)

You can now use the drone by pressing the key: 'Q'
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogWarning(Object)
charController:SetDroneControl(Boolean) (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Tiago\player\charController.cs:381)
ItemGiver:Update() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Jorge\ItemGiver.cs:19)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/Tiago/player/charController.cs Line: 381)

Keys to interact: Space, to go UP and, LeftControl, to go down.
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogWarning(Object)
DroneController:OnEnable() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Fabio\Drone\DroneController.cs:190)
UnityEngine.GameObject:SetActive(Boolean)
charController:DroneControl() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Tiago\player\charController.cs:346)
charController:Update() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Tiago\player\charController.cs:176)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/Fabio/Drone/DroneController.cs Line: 190)

DRONE::: Vent_Exit_Mesh ( View to PIT room ) (2) (VentController)
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
DroneController:Shoot() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Fabio\Drone\DroneController.cs:156)
DroneController:Update() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Fabio\Drone\DroneController.cs:88)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/Fabio/Drone/DroneController.cs Line: 156)

DRONE::: Vent_Exit_Mesh (Entrance From Drone Room) (1) (VentController)
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
DroneController:Shoot() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Fabio\Drone\DroneController.cs:156)
DroneController:Update() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Fabio\Drone\DroneController.cs:88)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/Fabio/Drone/DroneController.cs Line: 156)

DRONE::: ControlMachine (DoorManager)
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
DroneController:Shoot() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Fabio\Drone\DroneController.cs:156)
DroneController:Update() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Fabio\Drone\DroneController.cs:88)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/Fabio/Drone/DroneController.cs Line: 156)

On the next trigger enter is to Disable Objects? False
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
SceneSwitcher:ToogleTypeOfSwitch() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\InGameSceneManager\SceneSwitcher.cs:66)
<DisableAllObjectsAsync>d__5:MoveNext() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\InGameSceneManager\SceneController.cs:91)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/InGameSceneManager/SceneSwitcher.cs Line: 66)

Lista para Parar: 15
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
GameManager:PauseAllAudioSources() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\GameManager.cs:263)
GameManager:_SetPauseGame() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\GameManager.cs:303)
GameManager:SetPause() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\GameManager.cs:107)
charController:Update() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Tiago\player\charController.cs:140)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/GameManager.cs Line: 263)

Game Manager: Game Paused
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
GameManager:_SetPauseGame() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\GameManager.cs:308)
GameManager:SetPause() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\GameManager.cs:107)
charController:Update() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\Tiago\player\charController.cs:140)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/GameManager.cs Line: 308)

Unloading 6 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 36.279700 ms
Loading Game...
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
SaveSystemManager:LoadGameData() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\SaveSystem\SaveSystemManager.cs:80)
SaveSystemManager:LoadData() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\SaveSystem\SaveSystemManager.cs:123)
<LoadAsync>d__51:MoveNext() (at D:\GitHub\MasterD_FinalProject\TBA-MasterD\Assets\Scripts\GameManager.cs:380)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
 
(Filename: D:/GitHub/MasterD_FinalProject/TBA-MasterD/Assets/Scripts/SaveSystem/SaveSystemManager.cs Line: 80)

System memory in use before: 337.6 MB.
System memory in use after: 220.4 MB.

Unloading 559 unused Assets to reduce memory usage. Loaded Objects now: 11042.
Total: 46.406900 ms (FindLiveObjects: 0.465700 ms CreateObjectMapping: 0.138900 ms MarkObjects: 27.467400 ms  DeleteObjects: 18.334200 ms)

The referenced script on this Behaviour (Game Object 'ExitAndTopLevelStairs') is missing! 
(Filename: C:\buildslave\unity\build\Runtime/Mono/ManagedMonoBehaviourRef.cpp Line: 334)

Setting up 4 worker threads for Enlighten.
  Thread -> id: 5130 -> priority: 1 
  Thread -> id: fa0 -> priority: 1 
  Thread -> id: b32c -> priority: 1 
  Thread -> id: 8f30 -> priority: 1 
##utp:{"type":"MemoryLeaks","version":2,"phase":"Immediate","time":1633874119606,"processId":39884,"allocatedMemory":709939,"memoryLabels":[{"Permanent":24},{"NewDelete":220},{"Thread":68},{"Manager":2244},{"GfxThread":24},{"Physics":32},{"Serialization":24},{"String":151},{"DynamicArray":572712},{"HashMap":3072},{"PoolAlloc":32},{"Sprites":32},{"GI":130672},{"VR":1132},{"Subsystems":4294966796}]}

我也将场景添加到 buildIndex 所以

构建设置 | 场景

4

1 回答 1

0

好的,所以我发现了问题所在。所以我使用了一个 For 循环来遍历所有具有特定脚本的对象(yap.. 沉重的 CPU ......)所以,我使用搜索的方式只会找到一个对象并会破坏 for。由于层次结构的设置方式,这在编辑器中正常工作......在构建游戏时没有层次结构副本所以......是的,这就是问题!

于 2021-10-10T19:38:17.467 回答