### Broadcast Video Stream with SpoutSender Source: https://context7.com/keijiro/klakspout/llms.txt Captures frames and publishes them as a named Spout source. Supports different capture methods (GameView, Camera, Texture) and alpha channel preservation. Runtime instances require `SetResources` to be called. ```csharp using UnityEngine; using Klak.Spout; // --- Inspector-based setup (drag-and-drop in the Unity Editor) --- // Add Component → Klak → Spout → Spout Sender // Set "Spout Name", "Capture Method", and optionally "Source Camera" / "Source Texture". // --- Runtime scripting setup --- public class RuntimeSenderExample : MonoBehaviour { [SerializeField] SpoutResources _resources; // assign the SpoutResources asset [SerializeField] Camera _mainCam; [SerializeField] RenderTexture _renderTex; SpoutSender _camSender; SpoutSender _texSender; void Start() { // --- Camera sender (URP / HDRP only) --- var goA = new GameObject("CameraSender"); _camSender = goA.AddComponent(); _camSender.SetResources(_resources); // required for runtime instances _camSender.spoutName = "Unity Camera Feed"; _camSender.captureMethod = CaptureMethod.Camera; _camSender.sourceCamera = _mainCam; _camSender.keepAlpha = false; // --- Texture sender (all render pipelines) --- var goB = new GameObject("TextureSender"); _texSender = goB.AddComponent(); _texSender.SetResources(_resources); _texSender.spoutName = "Unity Render Texture"; _texSender.captureMethod = CaptureMethod.Texture; _texSender.sourceTexture = _renderTex; // Rename a live sender on the fly — reinitialises the native sender _camSender.spoutName = "Unity Camera Feed v2"; } void OnDestroy() { Destroy(_camSender.gameObject); Destroy(_texSender.gameObject); } } ``` -------------------------------- ### Dynamic Spout Source Selection with UI Toolkit Source: https://context7.com/keijiro/klakspout/llms.txt This C# script binds a UI Toolkit DropdownField to the list of available Spout sources. It automatically updates the SpoutReceiver's sourceName when a new selection is made, triggering a reconnect. ```csharp using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UIElements; using Unity.Properties; using Klak.Spout; public sealed class SourceSelector : MonoBehaviour { [SerializeField] SpoutReceiver _receiver; // Data-bound property: UI Toolkit reads this list to populate the dropdown [CreateProperty] public List SourceList => SpoutManager.GetSourceNames().ToList(); VisualElement UIRoot => GetComponent().rootVisualElement; DropdownField UISelector => UIRoot.Q("source-selector"); void Start() { // Bind the dropdown's choices to SourceList UISelector.dataSource = this; // When the user picks a new source, reconnect the receiver UISelector.RegisterValueChangedCallback(evt => { _receiver.sourceName = evt.newValue; Debug.Log($"Switched to Spout source: {evt.newValue}"); }); } } ``` -------------------------------- ### Receive Spout Video Stream with SpoutReceiver Source: https://context7.com/keijiro/klakspout/llms.txt Use SpoutReceiver to subscribe to a named Spout source. Frames can be written to a target texture or renderer property. Access the current frame via receivedTexture. ```csharp using UnityEngine; using Klak.Spout; public class RuntimeReceiverExample : MonoBehaviour { [SerializeField] SpoutResources _resources; // assign SpoutResources asset [SerializeField] Renderer _quad; // mesh to display the stream SpoutReceiver _receiver; void Start() { var go = new GameObject("SpoutReceiver"); _receiver = go.AddComponent(); _receiver.SetResources(_resources); // required for runtime instances // Connect to a sender named "TouchDesigner" _receiver.sourceName = "TouchDesigner"; // Option A: override a material property automatically _receiver.targetRenderer = _quad; _receiver.targetMaterialProperty = "_BaseMap"; // Option B: write into a specific RenderTexture instead // _receiver.targetTexture = myRenderTexture; } void Update() { // Access the live texture directly (null until first frame arrives) var tex = _receiver.receivedTexture; if (tex != null) Debug.Log($"Received frame: {tex.width}x{tex.height} sRGB={tex.isDataSRGB}"); } void OnDestroy() => Destroy(_receiver.gameObject); } ``` -------------------------------- ### SpoutSender component — Broadcast a video stream Source: https://context7.com/keijiro/klakspout/llms.txt The SpoutSender MonoBehaviour captures frames and publishes them as a named Spout source. It supports capturing from the Game View, a Camera, or a Texture, and allows configuration of the Spout name and alpha channel preservation. ```APIDOC ## SpoutSender Component ### Description Broadcasts a video stream from Unity to other Spout-compatible applications. ### Usage Add the `SpoutSender` component to a GameObject in your Unity scene. Configure its properties in the Inspector or via script. ### Properties - **spoutName** (string): The name of the Spout source that will be visible to other applications. - **captureMethod** (CaptureMethod): Specifies the source of the video feed. Options include `GameView`, `Camera`, and `Texture`. - **sourceCamera** (Camera): Assign a Camera component if `captureMethod` is set to `Camera`. (SRP only) - **sourceTexture** (RenderTexture): Assign a RenderTexture or Texture if `captureMethod` is set to `Texture`. - **keepAlpha** (bool): Set to `true` to preserve the alpha channel of the video feed. ### Methods - **SetResources(SpoutResources resources)**: Required for runtime instances to set up Spout resources. ### Example (Runtime Scripting) ```csharp using UnityEngine; using Klak.Spout; public class RuntimeSenderExample : MonoBehaviour { [SerializeField] SpoutResources _resources; // assign the SpoutResources asset [SerializeField] Camera _mainCam; [SerializeField] RenderTexture _renderTex; SpoutSender _camSender; SpoutSender _texSender; void Start() { // --- Camera sender (URP / HDRP only) --- var goA = new GameObject("CameraSender"); _camSender = goA.AddComponent(); _camSender.SetResources(_resources); // required for runtime instances _camSender.spoutName = "Unity Camera Feed"; _camSender.captureMethod = CaptureMethod.Camera; _camSender.sourceCamera = _mainCam; _camSender.keepAlpha = false; // --- Texture sender (all render pipelines) --- var goB = new GameObject("TextureSender"); _texSender = goB.AddComponent(); _texSender.SetResources(_resources); _texSender.spoutName = "Unity Render Texture"; _texSender.captureMethod = CaptureMethod.Texture; _texSender.sourceTexture = _renderTex; // Rename a live sender on the fly — reinitialises the native sender _camSender.spoutName = "Unity Camera Feed v2"; } void OnDestroy() { Destroy(_camSender.gameObject); Destroy(_texSender.gameObject); } } ``` ``` -------------------------------- ### Assign SpoutResources for Runtime SpoutSender/Receiver Source: https://context7.com/keijiro/klakspout/llms.txt When SpoutSender or SpoutReceiver are added at runtime, explicitly assign the SpoutResources asset using SetResources() before the component activates. ```csharp using UnityEngine; using Klak.Spout; public class ResourceAssignment : MonoBehaviour { // Load SpoutResources from the package's Editor folder, or expose via Inspector [SerializeField] SpoutResources _spoutResources; void Start() { // Sender var sender = gameObject.AddComponent(); sender.SetResources(_spoutResources); sender.spoutName = "My Sender"; sender.captureMethod = CaptureMethod.GameView; // Receiver var recv = new GameObject("Recv").AddComponent(); recv.SetResources(_spoutResources); recv.sourceName = "My Sender"; } } ``` -------------------------------- ### SpoutManager.GetSourceNames — Enumerate available Spout senders Source: https://context7.com/keijiro/klakspout/llms.txt Returns a string array of all Spout sender names currently active on the system. It's recommended to cache the results when called frequently to avoid per-frame allocation and native interop overhead. ```APIDOC ## SpoutManager.GetSourceNames ### Description Enumerates available Spout senders on the system. ### Method `SpoutManager.GetSourceNames()` ### Returns - `string[]`: An array of strings, where each string is the name of an active Spout sender. ### Example ```csharp using System.Collections; using UnityEngine; using Klak.Spout; public class SourceLister : MonoBehaviour { private string[] _cachedSources = System.Array.Empty(); private float _refreshInterval = 2f; IEnumerator Start() { while (true) { _cachedSources = SpoutManager.GetSourceNames(); if (_cachedSources.Length == 0) Debug.Log("No Spout senders found."); else foreach (var name in _cachedSources) Debug.Log($"Available sender: {name}"); yield return new WaitForSeconds(_refreshInterval); } } } ``` ``` -------------------------------- ### Enumerate Spout Senders with SpoutManager Source: https://context7.com/keijiro/klakspout/llms.txt Retrieves a list of active Spout sender names. Cache results when called frequently to avoid per-frame allocation and native interop overhead. Useful for populating UI elements like dropdowns. ```csharp using System.Collections; using UnityEngine; using Klak.Spout; public class SourceLister : MonoBehaviour { // Cache to avoid per-frame allocation private string[] _cachedSources = System.Array.Empty(); private float _refreshInterval = 2f; IEnumerator Start() { while (true) { _cachedSources = SpoutManager.GetSourceNames(); if (_cachedSources.Length == 0) Debug.Log("No Spout senders found."); else foreach (var name in _cachedSources) Debug.Log($"Available sender: {name}"); yield return new WaitForSeconds(_refreshInterval); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.