コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.LogError("LoadSceneParameters是一个结构体,创建一个LoadScene参数");

        LoadSceneParameters loadSceneParameters = new LoadSceneParameters(LoadSceneMode.Single);

        LoadSceneParameters loadSceneParameters2 = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.None);
    }
コード例 #2
0
        public static void LoadLevelAdditiveInPlayMode(string path)
        {
            LoadSceneParameters parameters = new LoadSceneParameters {
                loadSceneMode = LoadSceneMode.Additive
            };

            EditorSceneManager.LoadSceneInPlayMode(path, parameters);
        }
コード例 #3
0
        public static AsyncOperation LoadLevelAdditiveAsyncInPlayMode(string path)
        {
            LoadSceneParameters parameters = new LoadSceneParameters {
                loadSceneMode = LoadSceneMode.Additive
            };

            return(EditorSceneManager.LoadSceneAsyncInPlayMode(path, parameters));
        }
        //-------------------------------------------------------------------------------------------------------------
        public static AsyncOperation LoadSceneAsync(int sSceneBuildIndex, LoadSceneParameters sParameters, string sSceneIntermission = null, STSTransitionData sDatas = null)
        {
            LoadSceneMode tLoadSceneMode = sParameters.loadSceneMode;
            string        tSceneName     = SceneManager.GetSceneByBuildIndex(sSceneBuildIndex).name;

            INTERNAL_LoadScene(tSceneName, tLoadSceneMode, sSceneIntermission, sDatas);
            return(null);
        }
コード例 #5
0
ファイル: MoveScene.cs プロジェクト: LEPPEDIAZ/AdminGame
 void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         var parameters = new LoadSceneParameters(LoadSceneMode.Additive);
         SceneManager.LoadScene(loadLevel);
         Debug.Log("COLISIONO");
     }
 }
コード例 #6
0
    private void Start()
    {
        //Load the scene to place in a local physics scene.
        LoadSceneParameters param = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D);
        Scene scene = SceneManager.LoadScene(physicsSceneName, param);

        //Get the scene's physics scene.
        physicsScene = scene.GetPhysicsScene();
    }
コード例 #7
0
 static void BeforeSceneLoad()
 {
     if (!sceneLoaded)
     {
         var sceneParams = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.None);
         GameManager.Instance.SetAsyncEssentialsScene(SceneManager.LoadScene("AsyncEssentials", sceneParams));
         sceneLoaded = true;
     }
 }
コード例 #8
0
        public override void Update()
        {
#if UNITY_EDITOR
            if (IsDone)
            {
                return;
            }

            if (Status == EStatus.None)
            {
                Status = EStatus.Loading;
            }

            // 1. 加载资源对象
            if (Status == EStatus.Loading)
            {
                LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
                loadSceneParameters.loadSceneMode = SceneMode;
                _asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
                if (_asyncOp != null)
                {
                    _asyncOp.allowSceneActivation = true;
                    _asyncOp.priority             = _priority;
                    Status = EStatus.Checking;
                }
                else
                {
                    Status    = EStatus.Fail;
                    LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}";
                    YooLogger.Error(LastError);
                    InvokeCompletion();
                }
            }

            // 2. 检测加载结果
            if (Status == EStatus.Checking)
            {
                if (_asyncOp.isDone)
                {
                    SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
                    if (SceneObject.IsValid() && _activateOnLoad)
                    {
                        SceneManager.SetActiveScene(SceneObject);
                    }

                    Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
                    if (Status == EStatus.Fail)
                    {
                        LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
                        YooLogger.Error(LastError);
                    }
                    InvokeCompletion();
                }
            }
#endif
        }
コード例 #9
0
ファイル: SceneController.cs プロジェクト: teneen/evolution
        public static IEnumerator LoadSimulationScene(SimulationSceneLoadConfig config, SimulationSceneLoadContext context, ISceneContext sceneContext)
        {
            // Load Scene
            var sceneName = NameForScene(config.SceneType);
            var options   = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D);

            SceneManager.LoadScene(sceneName, options);
            var scene = SceneManager.GetSceneByName(sceneName);

            context.PhysicsScene = scene.GetPhysicsScene();
            context.Scene        = scene;
            // We need to wait two frames before the scene and its GameObjects
            // are fully loaded
            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            // Find setup script in the new scene
            var prevActiveScene = SceneManager.GetActiveScene();

            SceneManager.SetActiveScene(scene);

            SimulationSceneSetup sceneSetup = null;
            var rootObjects = scene.GetRootGameObjects();

            for (int i = 0; i < rootObjects.Length; i++)
            {
                sceneSetup = rootObjects[i].GetComponent <SimulationSceneSetup>();
                if (sceneSetup != null)
                {
                    break;
                }
            }

            // Create the structures
            sceneSetup.BuildScene(config.SceneDescription, sceneContext);

            SceneManager.SetActiveScene(prevActiveScene);
            yield return(new WaitForFixedUpdate());

            SceneManager.SetActiveScene(scene);

            // Spawn Creatures
            var spawnOptions = new SimulationSpawnConfig(
                config.CreatureDesign,
                config.CreatureSpawnCount,
                context.PhysicsScene,
                sceneContext,
                config.LegacyOptions,
                config.SceneDescription
                );
            var creatures = sceneSetup.SpawnBatch(spawnOptions);

            SceneManager.SetActiveScene(prevActiveScene);
            context.Creatures = creatures;
        }
コード例 #10
0
ファイル: Teleport.cs プロジェクト: seal23/Immunity-Game
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (isEnter && collision.GetComponent <PlayerController>() != null)
     {
         playerGameObj = collision.gameObject;
         var parameters = new LoadSceneParameters(LoadSceneMode.Single);
         SceneManager.sceneLoaded += OnSceneLoaded;
         SceneManager.LoadScene(DestinationSceneName);
     }
 }
コード例 #11
0
    void LoadSceneAdditivelyAndSetActive(int buildIndex)
    {
        var parameters = new LoadSceneParameters();

        parameters.loadSceneMode = LoadSceneMode.Additive;

        SceneManager.LoadScene(buildIndex, parameters);

        SceneManager.sceneLoaded += SetActiveScene;
    }
コード例 #12
0
 public static void LoadPreviousScene(LoadSceneParameters parameters)
 {
     if (history.Count > 0)
     {
         SceneManager.LoadScene(history.Pop(), parameters);
     }
     else
     {
         SceneManager.LoadScene(0, parameters);
     }
 }
コード例 #13
0
ファイル: EditorLoader.cs プロジェクト: weixinxin/CodeLib
        public IEnumerator LoadSceneAsync(string scenePath, bool isAdditive)
        {
            scenePath = FormatScenePath(scenePath);
            LoadSceneParameters param     = new LoadSceneParameters(isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single);
            AsyncOperation      operation = EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, param);

            while (!operation.isDone)
            {
                yield return(null);
            }
        }
コード例 #14
0
 /// <summary>
 /// Shortcut to load the Scene asynchronously in the background.
 /// </summary>
 /// <param name="parameters">Struct that collects the various parameters into a single place except for the name and index.</param>
 /// <returns>Use the AsyncOperation to determine if the operation has completed.</returns>
 public AsyncOperation LoadAsync(LoadSceneParameters parameters)
 {
     if (sceneIndex >= 0)
     {
         return(LoadAsyncFromBuildIndex(parameters));
     }
     else
     {
         return(LoadAsyncFromPath(parameters));
     }
 }
コード例 #15
0
        public static Scene LoadSceneInPlayMode(string path, LoadSceneParameters parameters)
        {
            AsyncOperation op = LoadSceneInPlayModeInternal(path, parameters, true);

            if (op != null)
            {
                return(GetSceneAt(sceneCount - 1));
            }

            return(new Scene());
        }
コード例 #16
0
    public void Setup()
    {
        GameManager.InitializeTestingEnvironment(true, true, true, false, false);

        loadSceneParameters = new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.None);

        Object asteroidsScene = ((GameObject)Resources.Load("TestsReferences")).GetComponent <TestsReferences>().asteroidsScene;

        asteroidsScenePath = AssetDatabase.GetAssetPath(asteroidsScene);

        cameraPrefab = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().cameraPrefab;
    }
コード例 #17
0
 private void Update()
 {
     foreach (var entity in GetEntities <LoadScene, OnEnableEvent>())
     {
         var parameters = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D);
         var scenes     = entity.Item1.scenes;
         foreach (var scene in scenes)
         {
             SceneManager.LoadScene(scene, parameters);
         }
     }
 }
    public void Setup()
    {
        loadSceneParameters = new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.None);

        Object asteroidsScene = ((GameObject)Resources.Load("TestsReferences")).GetComponent <TestsReferences>().asteroidsScene;

        asteroidsScenePath = AssetDatabase.GetAssetPath(asteroidsScene);

        gameManagerPrefab = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().gameManagerPrefab;
        asteroidPrefab    = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().asteroidPrefab;
        cameraPrefab      = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().cameraPrefab;
    }
コード例 #19
0
        public void LoadScene(string sceneName, LoadSceneMode mode)
        {
            Log.Trace("[ilib-abloader] EditorContainer {0}, LoadScene {1}. mode{2}", m_Name, sceneName, mode);
            var paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_Name, sceneName);

            if (paths.Length == 0)
            {
                return;
            }
            LoadSceneParameters parameters = new LoadSceneParameters(mode);

            EditorSceneManager.LoadSceneInPlayMode(paths[0], parameters);
        }
コード例 #20
0
        public new bool Update()
        {
            if (m_Request != null)
            {
                CRequest.SetProgress(request, m_Request.progress);
                if (!allowSceneActivation && LoaderType.Typeof_ABScene.Equals(request.assetType) && m_Request.progress >= 0.9f)//加载场景的时候如果allowSceneActivation = false 只能通过progress判断完成
                {
                    return(false);
                }
                else
                {
                    return(!m_Request.isDone);
                }
            }

            string assetName       = request.assetName;
            string assetBundleName = request.assetBundleName;

            if (LoaderType.Typeof_ABScene.Equals(request.assetType)) //加载场景
            {
                var levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);

                if (levelPaths.Length == 0)
                {
                    CRequest.SetError(request, string.Format("There is no scene with name \"" + assetName + "\" in " + assetBundleName));
                    Debug.LogError(request.error);
                }
                else
                {
                    LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
                    loadSceneParameters.loadSceneMode = loadSceneMode;
                    m_Request = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], loadSceneParameters);
                    m_Request.allowSceneActivation = allowSceneActivation;
                    CRequest.SetData(request, m_Request);
                    CRequest.SetProgress(request, m_Request.progress);
                    CacheManager.AddScene(request.assetName, request.assetBundleName);//缓存场景
                    if (!allowSceneActivation)
                    {
                        CacheManager.AddLoadingScene(request.assetName, m_Request);
                    }
                }
            }
            else //加载资源
            {
                StartSync();
                m_isDone = true;//标记完成
                return(false);
            }

            return(false);
        }
コード例 #21
0
        private AsyncOperation LoadSceneAsync(string name)
        {
            var loadParams = new LoadSceneParameters
            {
                loadSceneMode    = LoadSceneMode.Additive,
                localPhysicsMode = LocalPhysicsMode.None
            };

#if UNITY_EDITOR
            var path = $"Assets/{name}.unity";
            return(EditorSceneManager.LoadSceneAsyncInPlayMode(path, loadParams));
#else
            return(SceneManager.LoadSceneAsync(name, loadParams));
#endif // UNITY_EDITOR
        }
コード例 #22
0
ファイル: UITest.cs プロジェクト: ayutaz/unity-uitest
        IEnumerator LoadSceneInternal(string name)
        {
#if UNITY_EDITOR
            if (name.Contains(".unity"))
            {
                // UnityEditor.EditorApplication.LoadLevelInPlayMode(name);
                var parameter = new LoadSceneParameters(LoadSceneMode.Single);
                EditorSceneManager.LoadSceneInPlayMode(name, parameter);
                yield return(WaitFor(new SceneLoaded(Path.GetFileNameWithoutExtension(name))));

                yield break;
            }
#endif
            SceneManager.LoadScene(name);
            yield return(WaitFor(new SceneLoaded(name)));
        }
コード例 #23
0
        public AssetBundleLoadLevelSimulationOperation(string assetBundleName, string levelName, bool isAdditive)
        {
            string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName);
            if (levelPaths.Length == 0)
            {
                ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist
                //        from that there right scene does not exist in the asset bundle...

                Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName);
                return;
            }

            LoadSceneParameters parms = new LoadSceneParameters(isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single);

            m_Operation = EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], parms);
        }
コード例 #24
0
    IEnumerator endScene(string scene, LoadSceneParameters loadSceneParameters)
    {
        asource.loop = false;
        shouldLoop   = false;

        yield return(new WaitUntil(() => asource.isPlaying == false));

        asource.clip = end;
        asource.loop = false;
        asource.Play();

        yield return(new WaitUntil(() => asource.isPlaying == false));

        Destroy(asource);
        SceneManager.LoadScene(scene, loadSceneParameters);
    }
コード例 #25
0
        protected override Scene OnLoad(string id, ISceneInfo info, ISceneLoadParameters parameters, IContext context)
        {
            LogSceneLoading(id, info, parameters);

            var options = new LoadSceneParameters(parameters.AddMode, parameters.PhysicsMode);

            Scene scene = SceneManager.LoadScene(info.Address, options);

            if (RegisterApplication)
            {
                OnRegisterApplication(scene, context);
            }

            LogSceneLoaded(id, info, parameters, scene);

            return(scene);
        }
コード例 #26
0
        public AssetBundleLoadSceneRequestSimulate(string assetBundleName, string sceneName, LoadSceneMode loadSceneMode)
        {
            m_assetBundleName = assetBundleName;
            m_sceneName       = sceneName;
            m_loadSceneMode   = loadSceneMode;

            string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_assetBundleName, m_sceneName);
            if (levelPaths.Length == 0)
            {
                return;
            }

            LoadSceneParameters loadSceneParameters = new LoadSceneParameters();

            loadSceneParameters.loadSceneMode = m_loadSceneMode;
            m_request = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], loadSceneParameters);
        }
コード例 #27
0
ファイル: SceneLoader.cs プロジェクト: JackeyZ/UIFramework
    /// <summary>
    /// 异步加载场景
    /// </summary>
    /// <param name="abName"></param>
    /// <param name="sceneName"></param>
    /// <param name="loadCompleted"></param>
    /// <param name="loadSceneMode"></param>
    public static void LoadSceneAsync(string abName, string sceneName, Action <AsyncOperation> loadCompleted = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single)
    {
#if UNITY_EDITOR
        // 是否设置了使用assetbundle资源
        if (AssetBundleFramework.DeveloperSetting.GetUseAssetBundleAsset())
        {
            AssetBundleFramework.AssetBundleMgr.Instance.LoadBundle(abName, (succeed, bundleName) =>
            {
                AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
                if (loadCompleted != null)
                {
                    loadCompleted(operation);
                }
            });
        }
        else
        {
            // 根据包名获取资源路径,因为后缀名可能不一样所以获取的是数组
            string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(abName);
            if (paths.Length == 0)
            {
                Debug.LogError("AB包路径有误:" + abName);
                if (loadCompleted != null)
                {
                    loadCompleted(null);
                }
                return;
            }
            LoadSceneParameters param     = new LoadSceneParameters(loadSceneMode);
            AsyncOperation      operation = EditorSceneManager.LoadSceneAsyncInPlayMode(paths[0], param);
            if (loadCompleted != null)
            {
                loadCompleted(operation);
            }
        }
#else
        AssetBundleFramework.AssetBundleMgr.Instance.LoadBundle(abName, (succeed, bundleName) => {
            AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
            if (loadCompleted != null)
            {
                loadCompleted(operation);
            }
        });
#endif
    }
コード例 #28
0
        protected IEnumerator LoadSceneWithDeferredSwitchWorlds(string scenePath)
        {
            // Load the scene asynchronously and defer the SwitchWorlds() call until
            // just before the Scene is activated, to guarantee that GameObject-to-Entity
            // conversion happens at a predictable time.
            LoadSceneParameters loadParameters = new LoadSceneParameters(LoadSceneMode.Single);
            var sceneLoadOp = SceneManager.LoadSceneAsync(scenePath, loadParameters);

            sceneLoadOp.allowSceneActivation = false;
            while (!sceneLoadOp.isDone)
            {
                if (sceneLoadOp.progress >= 0.9f)
                {
                    SwitchWorlds();
                    sceneLoadOp.allowSceneActivation = true;
                }
                yield return(null);
            }
        }
コード例 #29
0
        public AsyncOperation LoadAsync(string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, System.Action listener = null)
        {
            mListener = listener;

            var resSearchRule = ResSearchKeys.Allocate(sceneName);

            if (ResFactory.AssetBundleSceneResCreator.Match(resSearchRule))
            {
                //加载的为场景
                IRes res = ResFactory.AssetBundleSceneResCreator.Create(resSearchRule);
#if UNITY_EDITOR
                if (FromUnityToDll.Setting.SimulationMode)
                {
                    string path = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle((res as AssetBundleSceneRes).AssetBundleName)[0];
                    if (!path.IsNullOrEmpty())
                    {
                        LoadSceneParameters sceneParameters = new LoadSceneParameters();
                        sceneParameters.loadSceneMode = loadSceneMode;
                        tempDepends.Clear();
                        return(UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(path, sceneParameters));
                    }
                }
                else
                {
                    DoLoadAsync();
                    tempDepends.Clear();
                    return(SceneManager.LoadSceneAsync(sceneName, loadSceneMode));
                }
#else
                DoLoadAsync();
                tempDepends.Clear();
                return(SceneManager.LoadSceneAsync(sceneName, loadSceneMode));
#endif
            }
            else
            {
                Log.E("场景名称错误!请检查名称是否正确或资源是否被标记!AssetName:" + sceneName);
            }


            return(null);
        }
コード例 #30
0
        protected override void LoadInternal()
        {
#if UNITY_EDITOR
            if (!EditorApplication.isPlaying)
            {
                var mode     = _mode == LoadSceneMode.Single ? OpenSceneMode.Single : OpenSceneMode.Additive;
                var realPath = PathUtility.RelativeDataPathToRelativeProjectPath(_scenePath) + ".unity";
                Scene = EditorSceneManager.OpenScene(realPath, mode);
                return;
            }
            var param = new LoadSceneParameters {
                loadSceneMode = _mode
            };
            EditorSceneManager.LoadSceneInPlayMode(_path, param);
#else
            SceneManager.LoadScene(_scenePath, _mode);
#endif
            Scene  = SceneManager.GetSceneByPath(_scenePath);
            IsDone = true;
        }