private void OnTriggerStay2D(Collider2D collision) { Player player = collision.GetComponent <Player>(); if (player != null) { // Calculate the players new position // This is a ternary operator, so if the goto x/y position is ~ 0, set the x/y Position as the players x/y position. // If it's not, return the goto position // Basically, if you didn't specify a goto x/y position in particular (the goto vector3 has default values of 0), go to the players current x/y position. // If you DID specify one, go to that instead float xPosition = Mathf.Approximately(scenePositionGoto.x, 0f) ? player.transform.position.x : scenePositionGoto.x; float yPosition = Mathf.Approximately(scenePositionGoto.y, 0f) ? player.transform.position.y : scenePositionGoto.y; float zPosition = 0f; // Teleport to the new scene if (needsClick) // I added this check, so that if you want it to be a click-to-teleport (like entering house doors!), in addition to being in the collider trigger, you also need to click 'E' to enter { if (Input.GetKey(KeyCode.E)) { SceneControllerManager.Instance.FadeAndLoadScene(sceneNameGoto.ToString(), new Vector3(xPosition, yPosition, zPosition)); } } else { SceneControllerManager.Instance.FadeAndLoadScene(sceneNameGoto.ToString(), new Vector3(xPosition, yPosition, zPosition)); } } }
public void SetCurrentScene(SceneName sceneName) { var scene = UnitySceneManager.GetSceneByName(sceneName.ToString()); UnitySceneManager.SetActiveScene(scene); loadedSceneNames.Add(sceneName.ToString()); }
IEnumerator GoToScene(SceneName scene) { yield return(new WaitForSeconds(0.25f)); Debug.Log("GO TO SCENE : " + scene.ToString()); AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scene.ToString()); // Wait until the asynchronous scene fully loads while (!asyncLoad.isDone) { yield return(null); } }
public async Task Load(SceneName sceneName, bool additive = false) { Debug.Log($"Prepare to loading scene: {sceneName}"); await SceneManager.LoadSceneAsync(sceneName.ToString(), additive?LoadSceneMode.Additive : LoadSceneMode.Single); Debug.Log($"Loading scene done: {sceneName}"); }
public async Task Unload(SceneName sceneName) { Debug.Log($"Prepare to unLoad scene: {sceneName}"); await SceneManager.UnloadSceneAsync(sceneName.ToString()); Debug.Log($"Unloading scene done: {sceneName}"); }
public void ShowAds(SceneName sceneName) { showAds = true; Time.timeScale = 1f; Application.LoadLevel(sceneName.ToString()); }
IEnumerator LoadAsyncScene(SceneName sceneName) { LoadSceneResult result; AsyncOperation asyncLoad; try { asyncLoad = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName.ToString()); } catch (Exception e) { Debug.LogError(e); result = LoadSceneResult.Failed; OnSceneLoadEndedEvent?.Invoke(result, sceneName); yield break; } // Wait until the asynchronous scene fully loads. while (!asyncLoad.isDone) { OnSceneLoadPercentChangedEvent?.Invoke(asyncLoad.progress); yield return(null); } result = LoadSceneResult.Success; OnSceneLoadEndedEvent?.Invoke(result, sceneName); }
void backtoMain() { if (Input.GetKey(KeyCode.Escape)) { Application.LoadLevel(myScene.ToString()); } }
public void LoadScene(SceneName sceneName, int level = 0) { _zenjectSceneLoader.LoadScene(sceneName.ToString(), LoadSceneMode.Single, container => { container.BindInstance(level); }); }
private IEnumerator LoadSceneCor(SceneName sceneName, bool isFade, float waitTime) { // フェード指定があったらアニメーションする if (isFade) { yield return(StartCoroutine(FadeIn())); } doOnceSceneChange = false; var async = SceneManager.LoadSceneAsync(sceneName.ToString()); async.allowSceneActivation = false; // 時が止まっていることも考慮し、とりあえず戻す Time.timeScale = 1; yield return(new WaitForSecondsRealtime(waitTime)); doOnceSceneChange = true; async.allowSceneActivation = true; if (isFade) { yield return(StartCoroutine(FadeOut())); } }
// Initializes the NPC if it is in the currently active scene, by activating its SpriteRenderer and BoxCollider, and setting the npcActiveInScene bool. // If it's not in the correct scene, disable the same members private void InitializeNPC() { // If the NPC's current scene is the same as the active scene, set thae NPC to active. Else, set it to inactive if (npcCurrentScene.ToString() == SceneManager.GetActiveScene().name) { // This method enables the spriteRenderer and boxCollider of the NPC in the scene SetNPCActiveInScene(); } else { // This method disables the spriteRenderer and boxCollider of the NPC in the scene SetNPCInactiveInScene(); } // Make sure the NPCs current scene is correct because it can be changing npcPreviousMovementStepScene = npcCurrentScene; // Get the NPC's current grid position npcCurrentGridPosition = GetGridPosition(transform.position); // Set the next Grid position and the target grid position to the current grid position npcNextGridPosition = npcCurrentGridPosition; npcTargetGridPosition = npcCurrentGridPosition; npcTargetWorldPosition = GetWorldPosition(npcTargetGridPosition); // Get the NPC's next world position npcNextWorldPosition = GetWorldPosition(npcCurrentGridPosition); }
private async UniTaskVoid LoadSceneAsync(GameType gameType, SceneName sceneName, int level, CancellationToken token) { // シーン遷移中にボタンを押下させない _buttonContainerUseCase.ActivateButton(false); _buttonContainerUseCase.ClearAllButton(); OnBeginTransition(gameType, sceneName); await _transitionMaskView.FadeInAsync(token); await _zenjectSceneLoader.LoadSceneAsync(sceneName.ToString(), LoadSceneMode.Single, container => { container.BindInstance(level); container.BindInstance(gameType); }); // トランジションが完了するまでボタンを押下させない _buttonContainerUseCase.ActivateButton(false); await UniTask.Delay(TimeSpan.FromSeconds(CommonViewConfig.LOAD_INTERVAL), cancellationToken : token); await OnEndTransitionAsync(gameType, sceneName, token); _buttonContainerUseCase.ActivateButton(true); }
private void InitialiseNPC() { // Active in scene if (npcCurrentScene.ToString() == SceneManager.GetActiveScene().name) { SetNPCActiveInScene(); } else { SetNPCInactiveInScene(); } npcPreviousMovementStepScene = npcCurrentScene; // Get NPC Current Grid Position npcCurrentGridPosition = GetGridPosition(transform.position); // Set Next Grid Position and Target Grid Position to current Grid Position npcNextGridPosition = npcCurrentGridPosition; npcTargetGridPosition = npcCurrentGridPosition; npcTargetWorldPosition = GetWorldPosition(npcTargetGridPosition); // Get NPC WorldPosition npcNextWorldPosition = GetWorldPosition(npcCurrentGridPosition); }
IEnumerator LoadSceneWithTransition(SceneName scene) { isLoading = true; yield return(StartCoroutine(AnimTransition(0, 1))); SceneManager.LoadScene(scene.ToString()); }
public virtual void LoadScene(SceneName scene) { Debug.Log("Loading scene: " + scene.ToString()); lock (_sceneLock) { if (_sceneLoader != null) { throw new InvalidOperationException("Only a single scene can be loaded at a time."); } string sceneName = scene.ToString(); RaiseScenePreLoad(EventArgs.Empty); _sceneLoader = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single); } }
public static string GetName(this SceneName sceneName) { var member = sceneName.GetType().GetMember(sceneName.ToString()); var attributes = member[0].GetCustomAttributes(typeof(DescriptionAttribute), false); var description = ((DescriptionAttribute)attributes[0]).Description; return(description); }
/// <summary> /// シーンの非同期読み込み /// </summary> /// <param name="sceneName"></param> /// <returns></returns> private IEnumerator Load() { StartCoroutine(Fade(1, FadeMode.OUT)); yield return(new WaitForSeconds(1)); AsyncOperation async = SceneManager.LoadSceneAsync(sceneName.ToString()); loadingImages[0].SetActive(DoKeyPress); Animator animator = anounceText.GetComponent <Animator>(); async.allowSceneActivation = false; bool DoOnce = false; bool cha = false; while (!async.isDone) { if (DoKeyPress) { if (async.progress >= 0.9f && !DoOnce && fadeEnd) { DoOnce = true; } if (ControllerInput.Instance.buttonDown.circle && fadeEnd && !cha) { async.allowSceneActivation = true; loadingImages[0].GetComponent <LoadImage>().WaveReSet(); loadingImages[0].SetActive(false); cha = true; } } else { if (async.progress >= 0.9f && fadeEnd) { async.allowSceneActivation = true; } } yield return(null); } StartCoroutine(Fade(1, FadeMode.IN)); yield return(new WaitForSeconds(1f)); loadingImages[1].GetComponent <Animator>().SetTrigger("Start"); yield return(new WaitForSeconds(1.5f)); IsLoadScene = false; SceneLoadFlg = false; loadingImages[1].GetComponent <Animator>().SetTrigger("End"); yield return(null); loadingImages[1].SetActive(false); Color c = loadingImages[1].transform.GetChild(1).GetComponent <Image>().color; loadingImages[1].transform.GetChild(1).GetComponent <Image>().color = new Color(c.r, c.g, c.b, 1); loadingImages[1].transform.GetChild(0).GetComponent <LoadEnd>().Up = 1; yield return(null); }
protected IEnumerator Start() { faderImage.color = new Color(0f, 0f, 0f, 1f); faderCanvasGroup.alpha = 1f; yield return(StartCoroutine(LoadSceneAndSetActive(startingScene.ToString()))); EventHandler.CallAfterSceneLoadEvent(); StartCoroutine(Fade(0f)); EventHandler.CallAfterSceneLoadFadeInEvent(); }
private IEnumerator LoadSceneAsync(SceneName sceneName) { var operation = SceneManager.LoadSceneAsync(sceneName.ToString()); while (!operation.isDone) { yield return(null); } OnLoadSceneComplete(sceneName); }
private static IEnumerator LoadSceneAsync(SceneName name) { yield return(new WaitForSeconds(.5f)); async = SceneManager.LoadSceneAsync(name.ToString()); while (!async.isDone) { yield return(null); } }
// Use this for initialization void Start() { if (NextSplashScreen == SceneName.DadiuSplashScreen) { StartCoroutine(LoadSplashScreen(NextSplashScreen.ToString())); } else if (NextSplashScreen == SceneName.UnitySplashScreen) { StartCoroutine(LoadSplashScreen(NextSplashScreen.ToString())); } else if (NextSplashScreen == SceneName.TeamSplashScreen) { StartCoroutine(LoadSplashScreen(NextSplashScreen.ToString())); } else if (NextSplashScreen == SceneName.MainMenu) { StartCoroutine(LoadSplashScreen(NextSplashScreen.ToString())); } }
public void FadeLoadScene(SceneName sceneName, int level, float fadeTime) { if (_isTransition) { return; } _transitionDuration = fadeTime; FadeLoadAsync(sceneName.ToString(), level, _tokenSource.Token).Forget(); }
public static IEnumerator LoadCoorutine(SceneName scene) { yield return(null); asyncOperation = SceneManager.LoadSceneAsync(scene.ToString()); while (!asyncOperation.isDone) { yield return(null); } }
private static IEnumerator LoadSceneAsync(SceneName name) { yield return(null); asyncOperation = SceneManager.LoadSceneAsync(name.ToString()); while (!asyncOperation.isDone) { yield return(null); } }
public static void Load(SceneName scene, Vector3 newPlayerPos) { //Loader.playerPos = playerPos; onLoaderCallback = () => { Player.GetInstance().transform.position = newPlayerPos; SceneManager.LoadScene(scene.ToString()); Player.GetInstance().GetComponent <MovingObject>().EnableMovement(); }; SceneManager.LoadScene(SceneName.Loading.ToString()); }
public void SceneChange(SceneName sceneName, PanelName panelName) { EventParamete eventParamete = new EventParamete(); eventParamete.AddParameter(panelName); EventManager.TriggerEvent(GenericEventEnumType.Message, TransportType.SwitchPanel.ToString(), eventParamete); SceneSwitch data = new SceneSwitch(); data.SceneName = sceneName.ToString(); SendDataToSever(ParmaterCodes.SceneSwitch, data); }
public async UniTask LoadSceneAsync(SceneName scene) { UniTask unload = SceneManager .UnloadSceneAsync(CurrentScene.ToString()) .ToUniTask(); UniTask load = SceneManager .LoadSceneAsync(scene.ToString(), LoadSceneMode.Additive) .ToUniTask(); CurrentScene = scene; await UniTask.WhenAll(unload, load); }
public void Update() { if (gameClear == true) { if (Input.GetMouseButtonDown(0)) { //登録しているシーンへ遷移 SceneManager.LoadScene(nextSceneName.ToString()); Time.timeScale = 1.0f; } } }
private void OnDoorOpen() { if (open) { Player.Instance.currentSpawnPointName = spawnName; SceneController.Instance.FadeAndLoadScene(targetRoom.ToString()); } else { EventHandler.PopupCloseEvent += OnPopupClosed; } }
/// <summary> /// 加载一个场景 /// </summary> /// <param name="sceneName"></param> public void LoadScene(SceneName sceneName) { if (isOnLoad) { Debug.LogWarning("is on loading scene"); return; } loadSceneCount = 1; string resourcesName = sceneName.ToString(); ResourcesManager.Instance.PopResource <GameObject>(resourcesName, OnSceneLoaded); }
public void SceneChange(SceneName sceneName, Color fadeColor, float fadeSpeed = 0.05f) { if(isLock == false) { speed = fadeSpeed; col = fadeColor; StartCoroutine(FadeIn(sceneName.ToString(), fadeSpeed, fadeColor)); } }
public void AddScene(SceneName sceneName) { SceneManager.LoadScene(sceneName.ToString(), LoadSceneMode.Additive); }
/// <summary> /// 切換到場景 /// </summary> public static void ChangeScene(SceneName _name) { AsyncOperation async = Application.LoadLevelAsync(_name.ToString()); }