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 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}"); } }