From 2a252ae70b1b2646fed3d3b633c15a0f0af10feb Mon Sep 17 00:00:00 2001 From: Shawn Hardern <126725649+ShawnHardern@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:55:18 +0100 Subject: [PATCH] Add C# examples to Playing videos Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Co-authored-by: Raul Santos --- tutorials/animation/playing_videos.rst | 67 ++++++++++++++++++++------ 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/tutorials/animation/playing_videos.rst b/tutorials/animation/playing_videos.rst index 9862d8e4282..6938a9253ad 100644 --- a/tutorials/animation/playing_videos.rst +++ b/tutorials/animation/playing_videos.rst @@ -268,7 +268,7 @@ To implement the chroma key effect, follow these steps: 2. In the "ChromaKeyShader.gdshader" file, write the custom shader code as shown below: -.. code-block:: gd +.. code-block:: glsl shader_type canvas_item; @@ -311,25 +311,64 @@ UI Controls To allow users to manipulate the chroma key effect in real-time, we created sliders in the `Control` node. The `Control` node's script contains the following functions: -.. code-block:: gd +.. tabs:: + .. code-tab:: gdscript - extends Control + extends Control - func _on_color_picker_button_color_changed(color): - # Update the "chroma_key_color" shader parameter of the VideoStreamPlayer's material - $VideoStreamPlayer.material.set("shader_parameter/chroma_key_color", color) + func _on_color_picker_button_color_changed(color): + # Update the "chroma_key_color" shader parameter of the VideoStreamPlayer's material. + $VideoStreamPlayer.material.set("shader_parameter/chroma_key_color", color) - func _on_h_slider_value_changed(value): - # Update the "pickup_range" shader parameter of the VideoStreamPlayer's material - $VideoStreamPlayer.material.set("shader_parameter/pickup_range", value) + func _on_h_slider_value_changed(value): + # Update the "pickup_range" shader parameter of the VideoStreamPlayer's material. + $VideoStreamPlayer.material.set("shader_parameter/pickup_range", value) - func _on_h_slider_2_value_changed(value): - # Update the "fade_amount" shader parameter of the VideoStreamPlayer's material - $VideoStreamPlayer.material.set("shader_parameter/fade_amount", value) + func _on_h_slider_2_value_changed(value): + # Update the "fade_amount" shader parameter of the VideoStreamPlayer's material. + $VideoStreamPlayer.material.set("shader_parameter/fade_amount", value) func _on_video_stream_player_finished(): - # Restart the video playback when it's finished - $VideoStreamPlayer.play() + # Restart the video playback when it's finished. + $VideoStreamPlayer.play() + + .. code-tab:: csharp + + using Godot; + + public partial class MyControl : Control + { + private VideoStreamPlayer _videoStreamPlayer; + + public override void _Ready() + { + _videoStreamPlayer = GetNode("VideoStreamPlayer"); + } + + private void OnColorPickerButtonColorChanged(Color color) + { + // Update the "chroma_key_color" shader parameter of the VideoStreamPlayer's material. + _videoStreamPlayer.Material.Set("shader_parameter/chroma_key_color", color); + } + + private void OnHSliderValueChanged(double value) + { + // Update the "pickup_range" shader parameter of the VideoStreamPlayer's material. + _videoStreamPlayer.Material.Set("shader_parameter/pickup_range", value); + } + + private void OnHSlider2ValueChanged(double value) + { + // Update the "fade_amount" shader parameter of the VideoStreamPlayer's material. + _videoStreamPlayer.Material.Set("shader_parameter/fade_amount", value); + } + + private void OnVideoStreamPlayerFinished() + { + // Restart the video playback when it's finished. + _videoStreamPlayer.Play(); + } + } also make sure that the range of the sliders are appropriate, our settings are :