Exemplo n.º 1
0
    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));
            }
        }
    }
Exemplo n.º 2
0
        public void SetCurrentScene(SceneName sceneName)
        {
            var scene = UnitySceneManager.GetSceneByName(sceneName.ToString());

            UnitySceneManager.SetActiveScene(scene);
            loadedSceneNames.Add(sceneName.ToString());
        }
Exemplo n.º 3
0
    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);
        }
    }
Exemplo n.º 4
0
        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}");
        }
Exemplo n.º 5
0
        public async Task Unload(SceneName sceneName)
        {
            Debug.Log($"Prepare to unLoad scene: {sceneName}");
            await SceneManager.UnloadSceneAsync(sceneName.ToString());

            Debug.Log($"Unloading scene done: {sceneName}");
        }
Exemplo n.º 6
0
    public void ShowAds(SceneName sceneName)
    {
        showAds        = true;
        Time.timeScale = 1f;

        Application.LoadLevel(sceneName.ToString());
    }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 void backtoMain()
 {
     if (Input.GetKey(KeyCode.Escape))
     {
         Application.LoadLevel(myScene.ToString());
     }
 }
Exemplo n.º 9
0
 public void LoadScene(SceneName sceneName, int level = 0)
 {
     _zenjectSceneLoader.LoadScene(sceneName.ToString(), LoadSceneMode.Single, container =>
     {
         container.BindInstance(level);
     });
 }
Exemplo n.º 10
0
    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()));
        }
    }
Exemplo n.º 11
0
    // 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);
    }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
    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);
    }
Exemplo n.º 14
0
    IEnumerator LoadSceneWithTransition(SceneName scene)
    {
        isLoading = true;

        yield return(StartCoroutine(AnimTransition(0, 1)));

        SceneManager.LoadScene(scene.ToString());
    }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
    /// <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);
    }
Exemplo n.º 18
0
    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);
        }
Exemplo n.º 20
0
    private static IEnumerator LoadSceneAsync(SceneName name)
    {
        yield return(new WaitForSeconds(.5f));

        async = SceneManager.LoadSceneAsync(name.ToString());
        while (!async.isDone)
        {
            yield return(null);
        }
    }
Exemplo n.º 21
0
 // 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()));
     }
 }
Exemplo n.º 22
0
        public void FadeLoadScene(SceneName sceneName, int level, float fadeTime)
        {
            if (_isTransition)
            {
                return;
            }

            _transitionDuration = fadeTime;
            FadeLoadAsync(sceneName.ToString(), level, _tokenSource.Token).Forget();
        }
Exemplo n.º 23
0
    public static IEnumerator LoadCoorutine(SceneName scene)
    {
        yield return(null);

        asyncOperation = SceneManager.LoadSceneAsync(scene.ToString());
        while (!asyncOperation.isDone)
        {
            yield return(null);
        }
    }
Exemplo n.º 24
0
    private static IEnumerator LoadSceneAsync(SceneName name)
    {
        yield return(null);

        asyncOperation = SceneManager.LoadSceneAsync(name.ToString());
        while (!asyncOperation.isDone)
        {
            yield return(null);
        }
    }
Exemplo n.º 25
0
 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());
 }
Exemplo n.º 26
0
    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);
    }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
 public void Update()
 {
     if (gameClear == true)
     {
         if (Input.GetMouseButtonDown(0))
         {
             //登録しているシーンへ遷移
             SceneManager.LoadScene(nextSceneName.ToString());
             Time.timeScale = 1.0f;
         }
     }
 }
Exemplo n.º 29
0
 private void OnDoorOpen()
 {
     if (open)
     {
         Player.Instance.currentSpawnPointName = spawnName;
         SceneController.Instance.FadeAndLoadScene(targetRoom.ToString());
     }
     else
     {
         EventHandler.PopupCloseEvent += OnPopupClosed;
     }
 }
Exemplo n.º 30
0
    /// <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);
    }
Exemplo n.º 31
0
 public void SceneChange(SceneName sceneName, Color fadeColor, float fadeSpeed = 0.05f)
 {
     if(isLock == false)
     {
         speed  = fadeSpeed;
         col    = fadeColor;
         StartCoroutine(FadeIn(sceneName.ToString(), fadeSpeed, fadeColor));
     }
 }
Exemplo n.º 32
0
    public void AddScene(SceneName sceneName)
    {
		SceneManager.LoadScene(sceneName.ToString(), LoadSceneMode.Additive);
    }
Exemplo n.º 33
0
 /// <summary>
 /// 切換到場景
 /// </summary>
 public static void ChangeScene(SceneName _name)
 {
     AsyncOperation async = Application.LoadLevelAsync(_name.ToString());
 }