Hi,
is there anything like "On scene end" event in AC ? I can see there is "On Start" event for scene (we can set it through AC game editor) but I cannot find anything like "On End" event in manual or forums.
I need to turn off my game UI when loading screen starts, and turn it on when loading screen ends, I dont know how to efficiently do this without "On end" event. The need for this "on end" event occured in few more cases.
So my question is; is there anything like "On end" event, and if not, what is the best way to turn on game UI when loading screen ends.
Cheers!
Joakim
Comments
I found out that Loading scene is, quote from AC:
"Bypassing regular AC startup because the current scene is the 'Loading' scene."
So on start does not get executed for loading scene.
Now I am trying to achieve menu on/off on loading scene start/end with this script below.
Tryed attaching it to object on Loading scene, on game engine and on separate object which has DontDestroyOnLoad, but nothing seems to work, I am trying to figure it out.
MyOnBeforeChangeScene() and MyOnAfterChangeScene() functins do get executed but it seems they
execute at wrong times.
If it's set to During Gameplay, then it will abide by that rule for when its displayed - as opposed to TurnOn / TurnOff function calls. Instead, you will have to lock the Menu to prevent it from showing when it's appear conditions are met:
inGameMenu.isLocked = true;
Alternatively, if your InGame Menu is rendered with AC's built-in Menu system, then it will not be displayed if the loading scene itself is not an "AC" scene, i.e. one with a GameEngine prefab.
My InGame Menu's Appear type field is set to "During Gameplay".
So if I switch inGameMenu.TurnOff() with inGameMenu.isLocked = true, and inGameMenuTurnOn() with inGameMenu.isLocked = false, my script should do the trick ?
I did switch TurnOff() and TurnOn() with isLocked and it does not seem to work.
Here's my modified script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using AC;
public class SceneChangeHandler : MonoBehaviour
{
public string LoadingScreenName = "LoadingScene";
public string InGameMenuName = "InGame";
void Awake()
{
DontDestroyOnLoad(this.gameObject);
Debug.Log("AWAKE");
// remove listeners binded on last awake (not the best way but should work)
AC.EventManager.OnBeforeChangeScene -= MyOnBeforeChangeScene();
AC.EventManager.OnAfterChangeScene -= MyAfteChangeScene();
// add new listeners
AC.EventManager.OnBeforeChangeScene += MyOnBeforeChangeScene();
AC.EventManager.OnAfterChangeScene += MyAfteChangeScene();
}
private AC.EventManager.Delegate_NoParameters MyOnBeforeChangeScene()
{
string currentSceneName = UnityVersionHandler.GetCurrentSceneName();
AC.Menu inGameMenu = AC.PlayerMenus.GetMenuWithName(InGameMenuName);
if (currentSceneName == LoadingScreenName)
{
inGameMenu.isLocked = true;
Debug.Log("MENU TURN OFF");
}
return null;
}
private AC.EventManager.Delegate_NoParameters MyAfteChangeScene()
{
string currentSceneName = UnityVersionHandler.GetCurrentSceneName();
AC.Menu inGameMenu = AC.PlayerMenus.GetMenuWithName(InGameMenuName);
if (currentSceneName == LoadingScreenName)
{
AC.Menu inGameMenu1 = AC.PlayerMenus.GetMenuWithName(InGameMenuName);
inGameMenu.isLocked = false;
Debug.Log("MENU TURN ON");
}
return null;
}
}
My script is currently attached to empty object on Loading Scene so it gets executed every time loading scene loads.
My Debug Log look's like this:
MENU TURN OFF
MENU TURN ON
MENU TURN OFF
MENU TURN ON
Both functions on each loading scene load get executed twice, I dont know if that is a problem.
Joakim
void OnDestrory ()
{
AC.EventManager.OnBeforeChangeScene -= MyOnBeforeChangeScene();
// etc
}
Calling TurnOn() TurnOff() should be unnecessary - amending the isLocked bool should be enough.
However, the logs don't show the timing of when functions are called. If you check Load scenes asynchronously?, you'll have an option to set a delay before and after loading. If you increase it, it should slow down the process so that you can more clearly see what's going on. Is it the case that "MENU TURN ON" is called at the wrong time, or is it that "MENU TURN OFF" is called but has no effect.