diff --git a/getting_started/scripting/c_sharp/c_sharp_basics.rst b/getting_started/scripting/c_sharp/c_sharp_basics.rst index 275496bca..f6f2c5434 100644 --- a/getting_started/scripting/c_sharp/c_sharp_basics.rst +++ b/getting_started/scripting/c_sharp/c_sharp_basics.rst @@ -131,6 +131,7 @@ Below is a list of the most important issues you should be aware of when diving - As explained above, the C# project isn't always kept in sync automatically when things are deleted, renamed or moved in Godot (`#12917 `_) - Writing editor plugins and tool scripts in C# is not yet supported - Exporting a project may not yet work (`#15615 `_) +- Signals with parameters are broken in 3.0.2-stable (`#17553 `_) Performance of C# in Godot -------------------------- diff --git a/getting_started/scripting/c_sharp/c_sharp_differences.rst b/getting_started/scripting/c_sharp/c_sharp_differences.rst index 2ca593abc..44ffad464 100644 --- a/getting_started/scripting/c_sharp/c_sharp_differences.rst +++ b/getting_started/scripting/c_sharp/c_sharp_differences.rst @@ -51,6 +51,8 @@ This attribute should be used on a `delegate`, whose name signature will be used [Signal] delegate void MySignal(string willSendsAString); +See also: :ref:`c_sharp_signals` + Singletons ---------- diff --git a/getting_started/scripting/c_sharp/c_sharp_features.rst b/getting_started/scripting/c_sharp/c_sharp_features.rst index 93d74c99a..5b8239d04 100644 --- a/getting_started/scripting/c_sharp/c_sharp_features.rst +++ b/getting_started/scripting/c_sharp/c_sharp_features.rst @@ -57,8 +57,10 @@ otherwise it returns true. For more advanced type checking, you can look into `Pattern Matching `_. -Signals -------- +.. _c_sharp_signals: + +C# Signals +---------- For a complete C# example, see the **Handling a signal** section in the step by step :ref:`doc_scripting` tutorial. @@ -104,6 +106,38 @@ Emitting signals is done with the ``EmitSignal`` method. Notice that you can always reference a signal name with the ``nameof`` keyword (applied on the delegate itself). +It is possible to bind values when establishing a connection by passing an object array. + +.. code-block:: csharp + + public int Value { get; private set; } = 0; + + private void ModifyValue(int modifier) + { + Value += modifier; + } + + public void SomeFunction() + { + var plusButton = (Button)GetNode("PlusButton"); + var minusButton = (Button)GetNode("MunusButton"); + + plusButton.Connect("pressed", this, "ModifyValue", new object[] { 1 }) + minusButton.Connect("pressed", this, "ModifyValue", new object[] { -1 }) + } + +Signals support parameters and bound values of all the `built-in types `_ and Classes derived from :ref:`Godot.Object `. +Consequently any ``Node`` or ``Reference`` will be compatible automatically but custom data objects will need to extend from `Godot.Object` or one of its subclasses. + +.. code-block:: csharp + + public class DataObject : Godot.Object + { + public string Field1 { get; set; } + public string Field2 { get; set; } + } + + Finally, signals can be created by calling ``AddUserSignal``, but be aware that it should be executed before any use of said signals (with ``Connect`` or ``EmitSignal``). .. code-block:: csharp