### C# Basics - Example Script Source: https://docs.godotengine.org/en/stable/getting_started/introduction/godot_design_philosophy.html A simple C# script example demonstrating basic node setup and printing a message when the node is ready. This serves as a starting point for C# development in Godot. ```csharp using Godot; public partial class MyCsharpScript : Node { public override void _Ready() { GD.Print("C# script is ready!"); } } ``` -------------------------------- ### Complete Shader Example Source: https://docs.godotengine.org/en/stable/tutorials/shaders/shaders_style_guide.html A full shader example demonstrating the style guide conventions for a 2D screen-space effect. ```glsl shader_type canvas_item; // Screen-space shader to adjust a 2D scene's brightness, contrast // and saturation. Taken from // https://github.com/godotengine/godot-demo-projects/blob/master/2d/screen_space_shaders/shaders/BCS.gdshader uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap; uniform float brightness = 0.8; uniform float contrast = 1.5; uniform float saturation = 1.8; void fragment() { vec3 c = textureLod(screen_texture, SCREEN_UV, 0.0).rgb; c.rgb = mix(vec3(0.0), c.rgb, brightness); c.rgb = mix(vec3(0.5), c.rgb, contrast); c.rgb = mix(vec3(dot(vec3(1.0), c.rgb) * 0.33333), c.rgb, saturation); COLOR.rgb = c; } ``` -------------------------------- ### HTTP Client Example Source: https://docs.godotengine.org/en/stable/tutorials/networking/http_client_class.html This example demonstrates how to use the HTTPClient class to connect to a host, send a GET request, and process the response. Remember to poll the client regularly to handle connection and data transfer. ```csharp using Godot; using System; using System.Collections.Generic; using System.Text; public partial class HTTPTest : SceneTree { // HTTPClient demo. // This simple class can make HTTP requests; it will not block, but it needs to be polled. public override async void _Initialize() { Error err; HTTPClient http = new HTTPClient(); // Create the client. err = http.ConnectToHost("www.php.net", 80); // Connect to host/port. Debug.Assert(err == Error.Ok); // Make sure the connection is OK. // Wait until resolved and connected. while (http.GetStatus() == HTTPClient.Status.Connecting || http.GetStatus() == HTTPClient.Status.Resolving) { http.Poll(); GD.Print("Connecting..."); OS.DelayMsec(500); } Debug.Assert(http.GetStatus() == HTTPClient.Status.Connected); // Check if the connection was made successfully. // Some headers. string[] headers = [ "User-Agent: Pirulo/1.0 (Godot)", "Accept: */*", ]; err = http.Request(HTTPClient.Method.Get, "/ChangeLog-5.php", headers); // Request a page from the site. Debug.Assert(err == Error.Ok); // Make sure all is OK. // Keep polling for as long as the request is being processed. while (http.GetStatus() == HTTPClient.Status.Requesting) { http.Poll(); GD.Print("Requesting..."); if (OS.HasFeature("web")) { // Synchronous HTTP requests are not supported on the web, // so wait for the next main loop iteration. await ToSignal(Engine.GetMainLoop(), "idle_frame"); } else { OS.DelayMsec(500); } } Debug.Assert(http.GetStatus() == HTTPClient.Status.Body || http.GetStatus() == HTTPClient.Status.Connected); // Make sure the request finished well. GD.Print("Response? ", http.HasResponse()); // The site might not have a response. // If there is a response... if (http.HasResponse()) { headers = http.GetResponseHeaders(); // Get response headers. GD.Print("Code: ", http.GetResponseCode()); // Show response code. GD.Print("Headers:"); foreach (string header in headers) { // Show headers. GD.Print(header); } if (http.IsResponseChunked()) { // Does it use chunks? GD.Print("Response is Chunked!"); } else { // Or just Content-Length. GD.Print("Response Length: ", http.GetResponseBodyLength()); } // This method works for both anyways. List rb = new List(); // List that will hold the data. // While there is data left to be read... while (http.GetStatus() == HTTPClient.Status.Body) { http.Poll(); byte[] chunk = http.ReadResponseBodyChunk(); // Read a chunk. if (chunk.Length == 0) { // If nothing was read, wait for the buffer to fill. OS.DelayMsec(500); } else { // Append the chunk to the read buffer. rb.AddRange(chunk); } } // Done! GD.Print("Bytes Downloaded: ", rb.Count); string text = Encoding.ASCII.GetString(rb.ToArray()); GD.Print(text); } Quit(); } } ``` -------------------------------- ### Hello, world! in C# Source: https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/index.html A basic 'Hello, world!' script to demonstrate C# setup in Godot. Ensure you have the .NET SDK installed and a C# project configured in Godot. ```csharp using Godot; public partial class HelloWorld : Node { public override void _Ready() { GD.Print("Hello, world!"); } } ``` -------------------------------- ### Minimal WebSocket Server Example Source: https://docs.godotengine.org/en/stable/tutorials/networking/index.html A basic example demonstrating how to set up a WebSocket server. This server listens for incoming connections and handles basic data reception. ```gdscript var ws = WebSocket.new() ws.listen(8080) func _ready(): ws.connect("connection_established", self, "_on_connection_established") ws.connect("connection_closed", self, "_on_connection_closed") ws.connect("data_received", self, "_on_data_received") func _on_connection_established(): print("Connection established") func _on_connection_closed(): print("Connection closed") func _on_data_received(data): print("Data received: ", data) ``` -------------------------------- ### Minimal WebSocket Client Example Source: https://docs.godotengine.org/en/stable/tutorials/networking/index.html A basic example demonstrating how to establish a WebSocket connection as a client. Ensure the WebSocketPeer is properly initialized before use. ```gdscript var ws = WebSocket.new() ws.connect("ws://127.0.0.1:8080") func _ready(): ws.connect("connection_established", self, "_on_connection_established") ws.connect("connection_closed", self, "_on_connection_closed") ws.connect("data_received", self, "_on_data_received") func _on_connection_established(): print("Connection established") func _on_connection_closed(): print("Connection closed") func _on_data_received(data): print("Data received: ", data) ``` -------------------------------- ### Get ID Path Source: https://docs.godotengine.org/en/stable/classes/class_astar3d.html Retrieves the sequence of point IDs forming a path between two points. Handles cases where the start point is disabled or a partial path is allowed. The example sets up a simple grid for pathfinding. ```GDScript var astar = AStar3D.new() astar.add_point(1, Vector3(0, 0, 0)) astar.add_point(2, Vector3(0, 1, 0), 1) # Default weight is 1 astar.add_point(3, Vector3(1, 1, 0)) astar.add_point(4, Vector3(2, 0, 0)) astar.connect_points(1, 2, false) ``` -------------------------------- ### Initialize and Use AStar3D Source: https://docs.godotengine.org/en/stable/classes/class_astar3d.html Demonstrates the basic setup and usage of AStar3D, including adding points, connecting them, and retrieving a path. Note that the weight of point 2 influences the pathfinding result. ```GDScript var astar = new AStar3D(); astar.AddPoint(1, new Vector3(0, 0, 0)); astar.AddPoint(2, new Vector3(0, 1, 0), 1); // Default weight is 1 astar.AddPoint(3, new Vector3(1, 1, 0)); astar.AddPoint(4, new Vector3(2, 0, 0)); astar.ConnectPoints(1, 2, false); astar.ConnectPoints(2, 3, false); astar.ConnectPoints(4, 3, false); astar.ConnectPoints(1, 4, false); long[] res = astar.GetIdPath(1, 3); // Returns [1, 2, 3] ``` -------------------------------- ### C# Script Example Source: https://docs.godotengine.org/en/stable/getting_started/step_by_step/scripting_first_script.html A basic example of a C# script in Godot, showing setup and basic node interaction. ```csharp using Godot; public partial class MyNode : Node2D { private int speed = 200; private Vector2 direction = Vector2.Zero; public override void _Ready() { GD.Print("Hello, world!"); } public override void _Process(double delta) { direction.X = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left"); direction.Y = Input.GetActionStrength("move_down") - Input.GetActionStrength("move_up"); direction = direction.Normalized(); Position += direction * (float)speed * (float)delta; } } ``` -------------------------------- ### C-style For Loop Examples Source: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_advanced.html Provides examples of C-style for loops with different starting points and increments. These are translated into GDScript equivalents. ```c for (int i = 0; i < 10; i++) {} ``` ```c for (int i = 5; i < 10; i++) {} ``` ```c for (int i = 5; i < 10; i += 2) {} ``` ```c for (int i = 10; i > 0; i--) {} ``` -------------------------------- ### Run C# HTTP Client Example Source: https://docs.godotengine.org/en/stable/tutorials/networking/http_client_class.html Command to execute the C# HTTP client example. ```bash c:\godot> godot -s HTTPTest.cs ``` -------------------------------- ### C# Hello World Example Source: https://docs.godotengine.org/en/stable/about/introduction.html A basic C# example demonstrating how to print 'Hello world!' to the console when the node enters the scene tree. ```csharp public override void _Ready() { GD.Print("Hello world!"); } ``` -------------------------------- ### start_position Source: https://docs.godotengine.org/en/stable/classes/class_navigationpathqueryparameters2d.html Sets or gets the pathfinding start position in global coordinates. ```APIDOC ## start_position ### Description The pathfinding start position in global coordinates. ### Method - `set_start_position(value: Vector2)`: Sets the start position. - `get_start_position()`: Returns the start position. ### Parameters #### Request Body (for set_start_position) - **value** (Vector2) - Required - The new start position in global coordinates. #### Response (for get_start_position) - **start_position** (Vector2) - The current start position in global coordinates. ```