Beispiel #1
0
        /// <summary>
        /// Load special defined scene with specified Load Type and Mode.
        /// </summary>
        /// <param name="sceneName">Special scene.</param>
        /// <param name="sceneLoadType">Load Type.</param>
        /// <param name="loadSceneMode">Load Mode.</param>
        /// <param name="fireEvent">Should <see cref="EventManager.BaseEvents"/> event be called during loading?</param>
        /// <returns>Returns AsyncOperation, if Load Type is Async.</returns>
        private AsyncOperation LoadSceneInternal(EntryPoint sceneName, SceneLoadType sceneLoadType, LoadSceneMode loadSceneMode, bool fireEvent = true)
        {
            //var currentSceneNameEnum = (EntryPoint)Enum.Parse(typeof(EntryPoint), SceneManager.GetActiveScene().name);
            var sceneNameParsed = sceneName.ToString();

            try
            {
                if (loadSceneMode == LoadSceneMode.Single && fireEvent)
                {
                    EventManager.BaseEvents.OnSceneWillBeLoaded.Invoke(sceneName, loadSceneMode);
                }

                EventManager.BaseEvents.OnSceneWillBeLoadedNow.Invoke(sceneName, loadSceneMode);

                switch (sceneLoadType)
                {
                case SceneLoadType.Async:
                    return(SceneManager.LoadSceneAsync(sceneNameParsed, loadSceneMode));

                case SceneLoadType.Default:
                    SceneManager.LoadScene(sceneNameParsed, loadSceneMode);
                    return(null);

                default:
                    SceneManager.LoadScene(sceneNameParsed, loadSceneMode);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("LevelManager.LoadScene: Exception!\n" + ex.Message);
            }

            return(null);
        }
Beispiel #2
0
    public void LoadScene(SceneLoadType type)
    {
        if (IsLoadingScene)
        {
            Debug.LogError("FATAL ERROR: A SCENE IS ALREADY LOADING!");
            return;
        }

        IsLoadingScene = true;

        Debug.Log("Loading scene with type = " + type.ToString());

        switch (type)
        {
        case SceneLoadType.FIRST_LOAD:
            SceneLoadCoroutine = FirstLoadScenesCoroutine();
            break;

        case SceneLoadType.MAIN_MENU:
            SceneLoadCoroutine = LoadMainMenuSceneCoroutine();
            break;

        case SceneLoadType.GAME:
            SceneLoadCoroutine = LoadGameSceneCoroutine();
            break;

        default:
            Debug.LogError("FATAL ERROR: SCENE TYPE IS NOT VALID!");
            return;
        }

        StartCoroutine(SceneLoadCoroutine);
    }
Beispiel #3
0
    private void OnSceneLoadHandler(SceneLoadType type)
    {
        // Initialize the Google Mobile Ads SDK.

        if (type != SceneLoadType.FIRST_LOAD)
        {
            if (bannerView == null || Time.time > NextBannerRequest)
            {
                RequestBanner();
            }
        }
    }
Beispiel #4
0
    void SceneLoadHandle(SceneLoadType load)
    {
        if (load == SceneLoadType.FIRST_LOAD)
        {
            Debug.LogError("Initializing Settings due to FIRST_LOAD done");
            RefreshUI();
            ApplySettings();
        }

        if (load == SceneLoadType.GAME)
        {
            ApplySensitivity();
        }
    }
Beispiel #5
0
    private static async Task LoadSceneAsync(string _scenePath, string _nextGuid, SceneLoadType _type)
    {
#if UNITY_EDITOR
        //SceneAsset _sceneToLoad = AssetDatabase.LoadAssetAtPath<SceneAsset>(_scenePath);
        string _sceneToLoad = Path.GetFileNameWithoutExtension(_scenePath);
#else
        string _sceneToLoad = Path.GetFileNameWithoutExtension(_scenePath);
#endif

        if (SceneManager.GetSceneByPath(_scenePath).isLoaded || loadingScene == _scenePath)
        {
            Debug.Log(_sceneToLoad + "  is Loaded");
            return;
        }
        loadingScene = _scenePath;

        Debug.Log("Load Scene -name: " + _sceneToLoad);
        if (_type == SceneLoadType.Additive)
        {
            SceneManager.LoadSceneAsync(_sceneToLoad, LoadSceneMode.Additive);

            /*
             * await WaitForAsyncScene(
             *      _sceneToLoad.name,
             *      LoadSceneMode.Additive,
             *      async delegate { InvokeEnterPoint(_nextGuid); }
             *      );*/
        }
        else if (_type == SceneLoadType.Single)
        {
            //[TODO]:有基本場景
            //To keep the main scene, use fake single mode

            if (flowData.mainSceneName != "")
            {
                await AsyncUnloadAllScenesExcept(flowData.mainSceneName, _sceneToLoad);

                SceneManager.LoadSceneAsync(_sceneToLoad, LoadSceneMode.Additive);
            }
            else
            {
                SceneManager.LoadSceneAsync(_sceneToLoad, LoadSceneMode.Single);
            }
        }
        InvokeEnterPoint(_nextGuid);
    }
    void _OnSceneLoadedHandler(SceneLoadType loaded)
    {
        try
        {
            GameSceneManager.Instance.GameState.OnEnergyStateActivate   -= EnergyActivatedHandler;
            GameSceneManager.Instance.GameState.OnEnergyStateDeactivate -= EnergyDeactivatedHandler;
            EnvironmentController.Instance.OnEnvironmentExplosion       -= EnvironmentExplosionHandler;
        }
        catch
        {
        }

        if (loaded == SceneLoadType.GAME)
        {
            GameSceneManager.Instance.GameState.OnEnergyStateActivate   += EnergyActivatedHandler;
            GameSceneManager.Instance.GameState.OnEnergyStateDeactivate += EnergyDeactivatedHandler;
            EnvironmentController.Instance.OnEnvironmentExplosion       += EnvironmentExplosionHandler;
        }
    }
Beispiel #7
0
    private static async void LoadSceneSync(string _scenePath, string _nextGuid, SceneLoadType _type)
    {
#if UNITY_EDITOR
        //SceneAsset _sceneToLoad = AssetDatabase.LoadAssetAtPath<SceneAsset>(_scenePath);
        string _sceneToLoad = Path.GetFileNameWithoutExtension(_scenePath);
#else
        string _sceneToLoad = Path.GetFileNameWithoutExtension(_scenePath);
#endif
        if (SceneManager.GetSceneByPath(_scenePath).isLoaded || _scenePath == loadingScene)
        {
            Debug.Log(_sceneToLoad + "  is Loaded");
            return;
        }


        Debug.Log("Sync Load Scene -name: " + _sceneToLoad);
        if (_type == SceneLoadType.Additive)
        {
            SceneManager.LoadScene(_sceneToLoad, LoadSceneMode.Additive);
            InvokeEnterPoint(_nextGuid);
        }
        else if (_type == SceneLoadType.Single)
        {
            //有固定場景時

            if (flowData.mainSceneName != "")
            {
                AsyncUnloadAllScenesExcept(flowData.mainSceneName, _sceneToLoad);
                SceneManager.LoadScene(_sceneToLoad, LoadSceneMode.Additive);
            }
            else
            {
                SceneManager.LoadScene(_sceneToLoad, LoadSceneMode.Single);
            }

            InvokeEnterPoint(_nextGuid);
        }
    }
Beispiel #8
0
    public LevelNode(Vector2 _position, LevelEditorWindow _editorWindow, LevelFlowGraphView _graphView)
    {
        SetPosition(new Rect(_position, defaultNodeSize));

        CreateSubGraphView();

        //Scene Object field
        sceneField = new ObjectField
        {
            objectType        = typeof(Scene),
            allowSceneObjects = false
        };

        sceneField.RegisterValueChangedCallback(ValueTuple =>
        {
            scene         = ValueTuple.newValue;
            title         = ValueTuple.newValue.name;
            scenAssetGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(ValueTuple.newValue as SceneAsset));
            scenePath     = AssetDatabase.GetAssetPath(ValueTuple.newValue as SceneAsset);
            //SetScenePath();
        });
        mainContainer.Add(sceneField);


        //Async? Enum field
        asyncTypeField = new EnumField()
        {
            value = asyncType
        };
        asyncTypeField.Init(asyncType);

        asyncTypeField.RegisterValueChangedCallback((value) =>
        {
            //賦予新value
            asyncType = (AsyncLoadType)value.newValue;
        });

        asyncTypeField.SetValueWithoutNotify(asyncType);

        mainContainer.Add(asyncTypeField);

        //Load Type Enum field
        loadTypeField = new EnumField()
        {
            value = loadType
        };
        loadTypeField.Init(loadType);

        loadTypeField.RegisterValueChangedCallback((value) =>
        {
            //賦予新value
            loadType = (SceneLoadType)value.newValue;
        });

        loadTypeField.SetValueWithoutNotify(loadType);

        mainContainer.Add(loadTypeField);



        //新增節點須refresh
        RefreshExpandedState();
        RefreshPorts();
    }
Beispiel #9
0
 public BaseScene(SceneType scenetype, SceneLoadType loadtype, SceneLoadMode loadmode)
 {
     SceneName     = scenetype.sceneName;
     this.loadtype = loadtype;
     this.loadmode = loadmode;
 }