protected override void InitializeCore() { base.InitializeCore(); // Create a slot manager var sceneInstance = SceneInstance.GetCurrent(Context); if (sceneInstance == null) { // If we don't have a scene instance (unlikely, but possible) slotManager = new RenderModelEffectSlotManager(); } else { // If we have a scene instance, we can store our state there, as we expect to share render models slotManager = sceneInstance.Tags.Get(RenderModelManagerKey); if (slotManager == null) { slotManager = new RenderModelEffectSlotManager(); sceneInstance.Tags.Set(RenderModelManagerKey, slotManager); } } if (dynamicEffectCompiler == null) { dynamicEffectCompiler = new DynamicEffectCompiler(Services, effectName); // Allocate (or reuse) a slot for the pass of this processor // Note: The slot is passed as out, so that when ModelRendererState.ModelSlotAdded callback is fired, // ModelRenderer.modelRenderSlot is valid (it might call PrepareRenderMeshes recursively). modelRenderSlot = slotManager.AllocateSlot(EffectName); } }
private void UpdateScene(SceneInstance newSceneInstance) { if (currentSceneInstance != null) { if (processor != null) { currentSceneInstance.Processors.Remove(processor); processor.ColliderAdded -= ProcessorOnColliderAdded; processor.ColliderRemoved -= ProcessorOnColliderRemoved; } // Clear builder builder = new NavigationMeshBuilder(); } // Set the currect scene currentSceneInstance = newSceneInstance; if (currentSceneInstance != null) { // Scan for components processor = new StaticColliderProcessor(); processor.ColliderAdded += ProcessorOnColliderAdded; processor.ColliderRemoved += ProcessorOnColliderRemoved; currentSceneInstance.Processors.Add(processor); pendingRebuild = true; } }
private void LoadSceneCompleted(AsyncOperationHandle <SceneInstance> LoadResult) { if (IsAsyncSucceded(LoadResult)) { _currentScene = LoadResult.Result; } }
public bool Initialize(Recorder recorder, SceneInstance scene_instance) { recorder_ = recorder; scene_instance_ = scene_instance; GrpcEnvironment.SetThreadPoolSize(workers_count_); GrpcEnvironment.SetCompletionQueueCount(queues_count_); render_service_ = new RenderServiceImpl(this); // Port reuse is turned off, it was a frequent cause of hard // to debug complications. server_ = new Server( new[] { new ChannelOption(ChannelOptions.SoReuseport, 0), new ChannelOption(ChannelOptions.MaxConcurrentStreams, streams_count_) }) { Services = { Orrb.RenderService.BindService(render_service_) }, Ports = { new ServerPort(host_, port_, ServerCredentials.Insecure) } }; try { server_.Start(); } catch (IOException e) { Logger.Error("RenderServer::Initialize::Failed to initialize render server on: {0}:{1} ({2})", host_, port_, e.Message); return(false); } Logger.Info("RenderServer::Initialize::Initialized render server on: {0}:{1}", host_, port_); return(true); }
//------------------------------------------------------------------------------------------------------------------------------ protected IEnumerator loadSceneCoroutine(string name, LoadSceneMode mode, bool active, SceneLoadCallback callback, object userData) { SceneInstance scene = new SceneInstance(); scene.mState = LOAD_STATE.LS_LOADING; scene.mOperation = SceneManager.LoadSceneAsync(name, mode); scene.mOperation.allowSceneActivation = true; mSceneList.Add(name, scene); while (true) { if (callback != null) { callback(scene.mOperation, false, userData); } // 当allowSceneActivation为true时,加载到progress为1时停止,并且isDone为true // 当allowSceneActivation为false时,加载到progress为0.9时就停止,并且isDone为false,当场景被激活时isDone变为true,progress也为1 if (scene.mOperation.isDone && scene.mOperation.progress >= 1.0f) { break; } yield return(null); } scene.mRoot = UnityUtility.getGameObject(null, name + "_Root"); if (scene.mRoot == null) { UnityUtility.logError(name + " scene must have a root node with name : " + name + "_Root"); } activeScene(name, active); scene.mState = LOAD_STATE.LS_LOADED; scene.mScene = SceneManager.GetSceneByName(name); if (callback != null) { callback(scene.mOperation, true, userData); } }
public static IPromise UnloadSceneAsync(SceneInstance scene) { string name = scene.Scene.name; var request = Addressables.UnloadSceneAsync(scene); return(WaitForRequest(request, "Unloaded addressable scene: " + name)); }
protected override void onInit(SceneProcedure lastProcedure, string intent) { LayoutTools.LOAD_NGUI_SHOW(LAYOUT_TYPE.LT_LOADING, 1); mSceneSystem.loadSceneAsync(mRaceSystem.getTrackName(), true, onSceneLoad); mSceneInstance = mSceneSystem.getScene <SceneInstance>(mRaceSystem.getTrackName()); }
public static AsyncOperationHandle <SceneInstance> UnloadSceneAsync(SceneInstance pScene, Action <float> pProgress = null, Action <bool> pOnCompleted = null) { var operation = Addressables.UnloadSceneAsync(pScene); WaitUnloadTask(operation, pProgress, pOnCompleted); return(operation); }
//------------------------------------------------------------------------------------------------------------------------------ protected IEnumerator loadSceneCoroutine(SceneInstance scene, bool active, SceneLoadCallback callback, object userData = null) { // 所有场景都只能使用叠加的方式来加载,方便场景管理器来管理所有场景的加载和卸载 scene.mOperation = SceneManager.LoadSceneAsync(scene.mName, LoadSceneMode.Additive); // allowSceneActivation指定了加载场景时是否需要调用场景中所有脚本的Awake和Start,以及贴图材质的引用等等 scene.mOperation.allowSceneActivation = true; while (true) { if (callback != null) { callback(scene.mOperation.progress, false, userData); } // 当allowSceneActivation为true时,加载到progress为1时停止,并且isDone为true,scene.isLoaded为true // 当allowSceneActivation为false时,加载到progress为0.9时就停止,并且isDone为false, scene.isLoaded为false // 当场景被激活时isDone变为true,progress也为1,scene.isLoaded为true if (scene.mOperation.isDone || scene.mOperation.progress >= 1.0f) { break; } yield return(null); } // 首先获得场景 scene.mScene = SceneManager.GetSceneByName(scene.mName); // 获得了场景根节点才能使场景显示或隐藏 scene.mRoot = UnityUtility.getGameObject(null, scene.mName + "_Root", true); activeScene(scene.mName, active); scene.mState = LOAD_STATE.LS_LOADED; if (callback != null) { callback(1.0f, true, userData); } }
public static bool TryGetScene(AssetReference reference, out SceneInstance scene) { scene = default; if (!GuardKey(reference, out var key)) { if (ExceptionHandle == ExceptionHandleType.Throw) { throw Exceptions.InvalidReference; } if (ExceptionHandle == ExceptionHandleType.Log) { Debug.LogException(new InvalidKeyException(key)); } return(false); } if (_scenes.TryGetValue(key, out var value)) { scene = value; return(true); } return(false); }
public static bool TryGetScene(string key, out SceneInstance scene) { scene = default; if (!GuardKey(key, out key)) { if (ExceptionHandle == ExceptionHandleType.Throw) { throw new InvalidKeyException(key); } if (ExceptionHandle == ExceptionHandleType.Log) { Debug.LogException(new InvalidKeyException(key)); } return(false); } if (_scenes.TryGetValue(key, out var value)) { scene = value; return(true); } if (!SuppressWarningLogs) { Debug.LogWarning($"No scene with key={key} has been loaded through {nameof(AddressablesManager)}."); } return(false); }
protected override void InitializeCore() { base.InitializeCore(); Services = Context.Services; EffectSystem = Services.GetSafeServiceAs <EffectSystem>(); SceneInstance = SceneInstance.GetCurrent(Context); SceneCameraRenderer = Context.Tags.Get(SceneCameraRenderer.Current); }
public void FadeIn(SceneInstance sceneInstance) { OnFinishFadeIn.AddListener(_ => { sceneInstance.ActivateAsync(); }); OnFadeIn.Invoke(this); }
public SceneInstance CreateSceneInstance() { SceneInstance scene_instance = Instantiate <SceneInstance>(scene_instance_prefab_); scene_instance.SetId(next_id_); scene_instances_.Add(next_id_, scene_instance); return(scene_instance); }
/// <summary> /// 卸载场景 /// </summary> /// <param name="sceneName"></param> /// <param name="completed"></param> /// <returns></returns> public static AsyncOperationHandle <SceneInstance> UnloadSceneAsync(SceneInstance sceneName, Action <AsyncOperationHandle <SceneInstance> > completed = null) { var operation = Addressables.UnloadSceneAsync(sceneName); operation.Completed += completed; return(operation); }
protected override void PrepareCore(RenderContext context, RenderItemCollection opaqueList, RenderItemCollection transparentList) { skyboxProcessor = SceneInstance.GetProcessor <SkyboxProcessor>(); if (skyboxProcessor == null) { return; } var skybox = skyboxProcessor.ActiveSkyboxBackground; // do not draw if no active skybox or the skybox is not included in the current entity group if (skybox == null || !CurrentCullingMask.Contains(skybox.Entity.Group)) { return; } // Copy camera/pass parameters context.Parameters.CopySharedTo(skyboxEffect.Parameters); // Show irradiance in the background if (skybox.Background == SkyboxBackground.Irradiance) { foreach (var parameterKeyValue in skybox.Skybox.DiffuseLightingParameters) { if (parameterKeyValue.Key == SkyboxKeys.Shader) { skyboxEffect.Parameters.Set(SkyboxKeys.Shader, (ShaderSource)parameterKeyValue.Value); } else { skyboxEffect.Parameters.SetObject(parameterKeyValue.Key.ComposeWith("skyboxColor"), parameterKeyValue.Value); } } } else { // TODO: Should we better use composition on "skyboxColor" for parameters? // Copy Skybox parameters if (skybox.Skybox != null) { foreach (var parameterKeyValue in skybox.Skybox.Parameters) { if (parameterKeyValue.Key == SkyboxKeys.Shader) { skyboxEffect.Parameters.Set(SkyboxKeys.Shader, (ShaderSource)parameterKeyValue.Value); } else { skyboxEffect.Parameters.SetObject(parameterKeyValue.Key, parameterKeyValue.Value); } } } } // Fake as the skybox was in front of all others (as opaque are rendered back to front) opaqueList.Add(new RenderItem(this, skybox, float.NegativeInfinity)); }
private static IEnumerator ActiveExistsSceneAsync(SceneInstance sceneInstance, System.Action <SceneInstance, object> onComplete, object userData = null) { yield return(sceneInstance.ActivateAsync()); if (onComplete != null) { onComplete(sceneInstance, userData); } }
static void UnloadAddressable(string sceneName, Action unloadCompleted = null) { AddressablesLogger.Log($"[ADDRESSABLES] UnloadAddressable call: {sceneName}"); if (!s_UnloadSceneCallbacks.ContainsKey(sceneName)) { AddressablesLogger.Log($"[ADDRESSABLES] UnloadAddressable unload start: {sceneName}"); var callbacks = new List <Action>(); if (unloadCompleted != null) { callbacks.Add(unloadCompleted); } s_UnloadSceneCallbacks.Add(sceneName, callbacks); SceneInstance sceneInstance = default; bool sceneFound = false; for (var i = 0; i < s_AdditiveScenesInstances.Count; i++) { AddressablesLogger.Log($"[ADDRESSABLES] UnloadAddressable searching Scene: {s_AdditiveScenesInstances[i].Scene.name}"); if (s_AdditiveScenesInstances[i].Scene.name == sceneName) { AddressablesLogger.Log($"[ADDRESSABLES] UnloadAddressable Scene found: {s_AdditiveScenesInstances[i].Scene.name}"); sceneFound = true; sceneInstance = s_AdditiveScenesInstances[i]; s_AdditiveScenesInstances.Remove(sceneInstance); s_AdditiveScenes.Remove(sceneInstance.Scene); break; } } AddressablesLogger.Log("[ADDRESSABLES] UnloadAddressable Addressables.UnloadSceneAsync Scene: " + (sceneInstance.Scene.name ?? "NULL")); if (sceneFound) { var addressableSceneUnloader = new AddressableSceneUnloader(sceneInstance); addressableSceneUnloader.Unload(AddressableSceneUnloaded); } else { AddressablesLogger.LogWarning(s_LoadSceneOperations.ContainsKey(sceneName) ? $"You are trying to unload {sceneName} scene, but it's loading is not complete yet!" : $"You are trying to unload {sceneName} scene, but it wasn't loaded!"); } } else { AddressablesLogger.Log($"[ADDRESSABLES] UnloadAddressable unload already started: {sceneName}"); var callbacks = s_UnloadSceneCallbacks[sceneName]; if (unloadCompleted != null) { if (callbacks == null) { callbacks = new List <Action>(); } callbacks.Add(unloadCompleted); } } }
private void OnSceneLoad(SceneInstance instance) { if (instance == null) { return; } _initWorld = true; _gameWorld.Init(); }
private ConstructionSystem SetupMock(Scene scene = null) { scene = scene ?? new Scene(); var mockServiceRegistry = new Mock <Xenko.Core.IServiceRegistry>(); var sceneInstance = new SceneInstance(mockServiceRegistry.Object, scene); var actorRefFactoryMock = new Mock <IActorRefFactory>(); actorRefFactoryMock.Setup(f => f.ActorOf(It.IsAny <Props>(), It.IsAny <string>())).Returns((Props props, string name) => ActorOfAsTestActorRef <SystemActor>(props, TestActor, name)); return(new ConstructionSystem(sceneInstance, actorRefFactoryMock.Object)); }
public void loadScene(string name, LoadSceneMode mode) { SceneManager.LoadScene(name, mode); SceneInstance scene = new SceneInstance(); scene.mState = LOAD_STATE.LS_LOADED; scene.mOperation = null; scene.mScene = SceneManager.GetSceneByName(name); mSceneList.Add(name, scene); }
protected override void LoadContent() { // TODO: Need to suppress SceneSystem.LoadContent() because it loads graphics related objects var content = Services.GetSafeServiceAs <ContentManager>(); // Preload the scene if it exists if (InitialSceneUrl != null && content.Exists(InitialSceneUrl)) { SceneInstance = new SceneInstance(Services, content.Load <Scene>(InitialSceneUrl)); } }
public void TestDefaultUpdate() { var scene = new Scene(); var mockServiceRegistry = new Mock <Xenko.Core.IServiceRegistry>(); var sceneInstance = new SceneInstance(mockServiceRegistry.Object, scene); var mockSystem = new Mock <TestSystem>(sceneInstance); IActorRef testSystemActor = Sys.ActorOf(TestSystemActor.Props(mockSystem.Object)); testSystemActor.Tell(new Update(new GameTime())); ExpectMsg <TestUpdateRespondMessage>(); }
public bool GetLoadedScene(SceneLookupEnum requestScene, ref Scene scene) { if (!IsSceneLoaded(requestScene)) { return(false); } SceneInstance sceneInstance = m_scene[requestScene]; scene = sceneInstance.Scene; return(true); }
private IEnumerator ProcessGameplaySceneLoading(GameSceneSO[] levelsToLoad, bool showLoadingScreen) { _gameplayLoadingHandle = _gameplayScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true); while (_gameplayLoadingHandle.Status != AsyncOperationStatus.Succeeded) { yield return(null); } _gameplaySceneInstance = _gameplayLoadingHandle.Result; UnloadPreviousScenes(); }
public void DrawScene(SceneInstance scene) { InstanceCollection instances = scene.Instances; //instances.SortByDepth(); //draw sprites foreach (Instance inst in instances) { DrawSprite(inst.Sprite, inst.Position, inst.ImageAngle, inst.ScaleX, inst.ScaleY, inst.ImageIndex); } }
protected SceneInstance createScene(string sceneName) { if (!mSceneRegisteList.TryGetValue(sceneName, out SceneRegisteInfo info)) { logError("scene :" + sceneName + " is not registed!"); return(null); } SceneInstance scene = createInstance <SceneInstance>(info.mSceneType); scene.setName(sceneName); return(scene); }
void OnSceneUnloaded(AsyncOperationHandle <SceneInstance> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { textArea.text = "Reload " + addressToAdd; m_ReadyToLoad = true; m_LoadedScene = new SceneInstance(); } else { Debug.LogError("Failed to unload scene at address: " + addressToAdd); } }
void OnSceneLoaded(AsyncOperationHandle <SceneInstance> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { textArea.text = "Unload " + addressToAdd; m_LoadedScene = obj.Result; m_ReadyToLoad = false; } else { Debug.LogError("Failed to load scene at address: " + addressToAdd); } }
public AsyncOperationHandle <SceneInstance> UnloadSceneAsync(SceneInstance scene, bool autoReleaseHandle = true) { AsyncOperationHandle handle; if (!m_resultToHandle.TryGetValue(scene, out handle)) { var msg = string.Format("Addressables.UnloadSceneAsync() - Cannot find handle for scene {0}", scene); LogWarning(msg); return(ResourceManager.CreateCompletedOperation <SceneInstance>(scene, msg)); } return(UnloadSceneAsync(handle, autoReleaseHandle)); }