Пример #1
0
    public static AsyncOperation LoadSceneOnEditor(string guid, bool bAsync, bool bAdditive)
    {
        string scenePath = AssetDatabase.GUIDToAssetPath(guid);

        if (bAsync)
        {
            if (bAdditive)
            {
                return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(scenePath));
            }
            else
            {
                return(EditorApplication.LoadLevelAsyncInPlayMode(scenePath));
            }
        }
        else
        {
            if (bAdditive)
            {
                EditorApplication.LoadLevelAdditiveInPlayMode(scenePath);
            }
            else
            {
                EditorApplication.LoadLevelInPlayMode(scenePath);
            }

            return(null);
        }
    }
Пример #2
0
	// Load level from the given assetBundle.
	static public AssetBundleLoadOperation LoadLevelAsync (string assetBundleName, string levelName, bool isAdditive)
	{
		AssetBundleLoadOperation operation = null;
#if UNITY_EDITOR
		if (SimulateAssetBundleInEditor)
		{
			string[] levelPaths = 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 null;
			}

			if (isAdditive)
				EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
			else
				EditorApplication.LoadLevelInPlayMode(levelPaths[0]);

			operation = new AssetBundleLoadLevelSimulationOperation();
		}
		else
#endif
		{
			LoadAssetBundle (assetBundleName);
			operation = new AssetBundleLoadLevelOperation (assetBundleName, levelName, isAdditive);

			m_InProgressOperations.Add (operation);
		}

		return operation;
	}
Пример #3
0
 public void Update()
 {
     if (doQuickStart)
     {
         if (EditorApplication.isPlaying)
         {
             Debug.Log("Quickstart!");
             EditorApplication.LoadLevelInPlayMode(@"Assets/Resources/Scenes/NewMenu/Menu.unity");
             doQuickStart = false;
         }
     }
 }
    // Load level from the given assetBundle.
    public AssetBundleLoadOperation LoadLevelAsync(string a_assetBundleName, string a_levelName, bool a_isAdditive, bool a_allowSceneActivation)
    {
        AssetBundleLoadOperation operation = null;

#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            var levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(a_assetBundleName, a_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 \"" + a_levelName + "\" in " + a_assetBundleName);
                return(null);
            }

            if (a_isAdditive)
            {
                EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
            }
            else
            {
                EditorApplication.LoadLevelInPlayMode(levelPaths[0]);
            }

            operation = new AssetBundleLoadLevelSimulationOperation();
        }
        else
#endif
        {
            var key = AssetToKey(a_assetBundleName, a_levelName);

            AssetBundleLoadOperation inProgressOperation;
            if (m_inProgressOperationsByName.TryGetValue(key, out inProgressOperation))
            {
                var loadLevelOperation = inProgressOperation as AssetBundleLoadLevelOperation;
                if (loadLevelOperation != null)
                {
                    return(loadLevelOperation);
                }
            }

            LoadAssetBundle(a_assetBundleName);
            operation = new AssetBundleLoadLevelOperation(a_assetBundleName, a_levelName, a_isAdditive, a_allowSceneActivation);

            m_inProgressOperationsByName.Add(key, operation);
            m_inProgressOperations.Add(new KeyValuePair <string, AssetBundleLoadOperation>(key, operation));
        }

        return(operation);
    }
Пример #5
0
        private static void RunInEditor(List <string> testScenes, List <string> otherBuildScenes)
        {
            CheckActiveBuildTarget();

            NetworkResultsReceiver.StopReceiver();
            if (testScenes == null || testScenes.Count == 0)
            {
                Debug.Log("No test scenes on the list");
                EditorApplication.Exit(returnCodeRunError);
                return;
            }

            string previousScenesXml = "";
            var    serializer        = new System.Xml.Serialization.XmlSerializer(typeof(EditorBuildSettingsScene[]));

            using (StringWriter textWriter = new StringWriter())
            {
                serializer.Serialize(textWriter, EditorBuildSettings.scenes);
                previousScenesXml = textWriter.ToString();
            }

            EditorBuildSettings.scenes = (testScenes.Concat(otherBuildScenes).ToList()).Select(s => new EditorBuildSettingsScene(s, true)).ToArray();

#if UNITY_5_3_OR_NEWER
            EditorSceneManager.OpenScene(testScenes.First());
#else
            EditorApplication.LoadLevelInPlayMode(testScenes.First());
#endif
            GuiHelper.SetConsoleErrorPause(false);

            var config = new PlatformRunnerConfiguration
            {
                resultsDir  = GetParameterArgument(k_ResultFileDirParam),
                ipList      = TestRunnerConfigurator.GetAvailableNetworkIPs(),
                port        = PlatformRunnerConfiguration.TryToGetFreePort(),
                runInEditor = true
            };

            var settings = new PlayerSettingConfigurator(true);
            settings.AddConfigurationFile(TestRunnerConfigurator.integrationTestsNetwork, string.Join("\n", config.GetConnectionIPs()));
            settings.AddConfigurationFile(TestRunnerConfigurator.testScenesToRun, string.Join("\n", testScenes.ToArray()));
            settings.AddConfigurationFile(TestRunnerConfigurator.previousScenes, previousScenesXml);

            NetworkResultsReceiver.StartReceiver(config);

            EditorApplication.isPlaying = true;
        }
        /// <summary>
        /// 场景名字大小写敏感,坑~
        /// </summary>
        /// <param name="scenePath"></param>
        /// <param name="mode"></param>
        public void LoadScene(string scenePath, LoadSceneMode mode = LoadSceneMode.Single)
        {
#if UNITY_EDITOR
            if (AssetBundleUtility.SimulateAssetBundleInEditor)
            {
                string path = Path.Combine(AssetBundleUtility.AssetBundleResourcesPath, scenePath) + ".unity";
                if (mode == LoadSceneMode.Single)
                {
                    EditorApplication.LoadLevelInPlayMode(path);
                }
                else
                {
                    EditorApplication.LoadLevelAdditiveInPlayMode(path);
                }
                return;
            }
#endif
            LoadAssetBundleWithDependencies(scenePath + AssetBundleUtility.AssetBundleExtension);
            SceneManager.LoadScene(Path.GetFileName(scenePath), mode);
        }
Пример #7
0
    // Load level from the given assetBundle.
    static public void LoadLevel(string assetBundleName, string levelName, bool isAdditive)
    {
#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor == LoadMode.AssetBundleName)
        {
            //GetAssetPathsFromAssetBundleAndAssetName接口对大小写敏感
            assetBundleName = assetBundleName.ToLower();
            levelName = levelName.ToLower();

            string[] levelPaths = 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);
            }

            if (isAdditive)
                EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
            else
                EditorApplication.LoadLevelInPlayMode(levelPaths[0]);

        }
        else
#endif
        {
            AssetBundle assetbundle = LoadAssetBundleImmediately(assetBundleName);
            string m_DownloadingError;
            LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(assetbundle.name, out m_DownloadingError);
            if (bundle != null)
            {
                if (isAdditive)
                    SceneManager.LoadScene(levelName,LoadSceneMode.Additive);
                else
                    SceneManager.LoadScene(levelName,LoadSceneMode.Single);
            }
        }

    }
Пример #8
0
        public void LoadScene(string assetBundleName, string levelName, bool isAdditive, LoadSceneCallback callback, object[] param)
        {
            AssetBundleLoadLevelOperation operation = null;

#if UNITY_EDITOR
            if (AssetLoader2.m_SimulateAssetBundleInEditor)
            {
                string[] levelPaths = 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);
                    callback(false, param);
                    return;
                }

                if (isAdditive)
                {
                    EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
                }
                else
                {
                    EditorApplication.LoadLevelInPlayMode(levelPaths[0]);
                }
            }
            else
#endif
            {
                LoadAssetBundle(assetBundleName);
                operation          = new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive, callback, param);
                operation.callback = callback;
                operation.loader   = this;
                m_InProgressOperations.Add(operation);
            }
        }