void OnEnable() // No OnEnable() default init.... delayed only { _CreateAssetResources(); _usingURP = RenderUtils.IsUsingURP(); if (_camera == null) { Fail(nameof(_camera)); } if (_renderFeature == null && _usingURP) { Fail(nameof(_renderFeature)); } _cmd = RenderUtils.GetCommandBuffer(CommandBufferTag); if (_usingURP) { _renderFeature.commandBuffer = _cmd; } else { _camera.AddCommandBuffer(CameraEvent.AfterEverything, _cmd); } ImGuiUn.SetUnityContext(_context); ImGuiIOPtr io = ImGui.GetIO(); _initialConfiguration.ApplyTo(io); _style?.ApplyTo(ImGui.GetStyle()); _context.textures.BuildFontAtlas(io, _fontAtlasConfiguration); _context.textures.Initialize(io); SetPlatform(Platform.Create(_platformType, _cursorShapes, _iniSettings), io); SetRenderer(RenderUtils.Create(_rendererType, _shaders, _context.textures), io); if (_platform == null) { Fail(nameof(_platform)); } if (_renderer == null) { Fail(nameof(_renderer)); } //_AddFonts(); void Fail(string reason) { OnDisable(); enabled = false; throw new System.Exception($"Failed to start: {reason}"); } }
void OnDisable() { ImGuiUn.SetUnityContext(_context); ImGuiIOPtr io = ImGui.GetIO(); SetRenderer(null, io); SetPlatform(null, io); ImGuiUn.SetUnityContext(null); _context.textures.Shutdown(); _context.textures.DestroyFontAtlas(io); #if HAS_HDRP _usingHDRP = RenderUtils.IsUsingHDRP(); if (_usingHDRP) { // I know... I know... using a goto, but in this instance it makes things a lot cleaner // due to the preprocessor directives and how unity has grouped things. goto PostCommandBufferTeardown; } #endif if (_usingURP) { if (_renderFeature != null) { _renderFeature.commandBuffer = null; } } else { if (_camera != null) { _camera.RemoveCommandBuffer(CameraEvent.AfterEverything, _cmd); } } PostCommandBufferTeardown: if (_cmd != null) { RenderUtils.ReleaseCommandBuffer(_cmd); } _cmd = null; }
void OnEnable() { _usingURP = RenderUtils.IsUsingURP(); if (_camera == null) { Fail(nameof(_camera)); } if (_renderFeature == null && _usingURP) { Fail(nameof(_renderFeature)); } _cmd = RenderUtils.GetCommandBuffer(CommandBufferTag); #if HAS_HDRP _usingHDRP = RenderUtils.IsUsingHDRP(); if (_usingHDRP) { // I know... I know... using a goto, but in this instance it makes things a lot cleaner // due to the preprocessor directives and how unity has grouped things. goto PostCommandBufferSetup; } #endif if (_usingURP) { _renderFeature.commandBuffer = _cmd; } else { _camera.AddCommandBuffer(CameraEvent.AfterEverything, _cmd); } PostCommandBufferSetup: ImGuiUn.SetUnityContext(_context); ImGuiIOPtr io = ImGui.GetIO(); _initialConfiguration.ApplyTo(io); _style?.ApplyTo(ImGui.GetStyle()); _context.textures.BuildFontAtlas(io, _fontAtlasConfiguration); _context.textures.Initialize(io); SetPlatform(Platform.Create(_platformType, _cursorShapes, _iniSettings), io); SetRenderer(RenderUtils.Create(_rendererType, _shaders, _context.textures), io); if (_platform == null) { Fail(nameof(_platform)); } if (_renderer == null) { Fail(nameof(_renderer)); } void Fail(string reason) { OnDisable(); enabled = false; throw new System.Exception($"Failed to start: {reason}"); } }