Skip to content

Commit

Permalink
Fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EiTaNBaRiBoA committed Jun 28, 2024
1 parent bed1594 commit ffe848f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
25 changes: 15 additions & 10 deletions addons/AsyncSceneManager/AsyncScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func ChangeScene() -> void:
if not isCompleted:
printerr("Scene hasn't been loaded yet")
return
Engine.get_main_loop().root.get_tree().change_scene_to_packed(myRes)
currentSceneNode = Engine.get_main_loop().root.get_tree().current_scene
_changeImmediate()

func GetStatus() -> String:
return status_names.get(_getStatus())
Expand All @@ -50,13 +49,19 @@ func _additiveScene() -> void:
currentSceneNode = myRes.instantiate()
Engine.get_main_loop().root.call_deferred("add_child",currentSceneNode)

func _changeImmediate() -> void:
currentSceneNode = Engine.get_main_loop().root.get_tree().current_scene
currentSceneNode.queue_free()
_additiveScene()


## Unloading
func UnloadScene() -> void:
if not isCompleted:
printerr("Scene hasn't been loaded yet")
return
currentSceneNode.queue_free()
if currentSceneNode:
currentSceneNode.queue_free()
queue_free()


Expand All @@ -78,24 +83,24 @@ func _check_status() -> void:
if _getStatus() == ResourceLoader.THREAD_LOAD_LOADED:
myRes = ResourceLoader.load_threaded_get(packedScenePath)
if typeOperation == LoadingSceneOperation.ReplaceImmediate:
ChangeScene()
_changeImmediate()
elif typeOperation == LoadingSceneOperation.Additive:
_additiveScene()
_complete()
_complete(false)
elif _getStatus() == ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
_complete()
_complete(true)
elif _getStatus() == ResourceLoader.THREAD_LOAD_FAILED:
_complete()
_complete(true)
elif _getStatus() == ResourceLoader.THREAD_LOAD_IN_PROGRESS:
var progressArr : Array = []
ResourceLoader.load_threaded_get_status(packedScenePath,progressArr)
progress = progressArr.front() * 100



func _complete() -> void:
func _complete(isFailed : bool) -> void:
isCompleted = !isFailed
progress = 100
timer.queue_free()
OnComplete.emit()
isCompleted = true
progress = 100
#endregion
10 changes: 5 additions & 5 deletions addons/AsyncSceneManager/Examples/SceneChanging.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ var scene : AsyncScene = null


func _ready() -> void:
#scene = AsyncScene.new(scenePath,AsyncScene.LoadingSceneOperation.Replace) loading and later changing using scene.ChangeScene()
#scene = AsyncScene.new(scenePath,AsyncScene.LoadingSceneOperation.ReplaceImmediate) Immediately changing the scene after loading
scene = AsyncScene.new(scenePath,AsyncScene.LoadingSceneOperation.Additive) #Loading Scene additively to another scene
scene = AsyncScene.new(scenePath,AsyncScene.LoadingSceneOperation.Replace) #loading and later changing using scene.ChangeScene()
#scene = AsyncScene.new(scenePath,AsyncScene.LoadingSceneOperation.ReplaceImmediate) #Immediately changing the scene after loading
#scene = AsyncScene.new(scenePath,AsyncScene.LoadingSceneOperation.Additive) #Loading Scene additively to another scene
scene.OnComplete.connect(complete) #Binding to signal after complete loading

func complete() -> void:
#scene.UnloadScene() Unloading scene
#scene.ChangeScene() Changing the main scene manually
scene.ChangeScene() #Changing the main scene manually
#scene.UnloadScene() #Unloading scene
print("Loading complete")
pass

Expand Down

0 comments on commit ffe848f

Please sign in to comment.