Sfoglia il codice sorgente

additional C# signal information

Kelly thomas 7 anni fa
parent
commit
189f312c10

+ 1 - 0
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 <https://github.com/godotengine/godot/issues/12917>`_)
 - As explained above, the C# project isn't always kept in sync automatically when things are deleted, renamed or moved in Godot (`#12917 <https://github.com/godotengine/godot/issues/12917>`_)
 - Writing editor plugins and tool scripts in C# is not yet supported
 - Writing editor plugins and tool scripts in C# is not yet supported
 - Exporting a project may not yet work (`#15615 <https://github.com/godotengine/godot/issues/15615>`_)
 - Exporting a project may not yet work (`#15615 <https://github.com/godotengine/godot/issues/15615>`_)
+- Signals with parameters are broken in 3.0.2-stable (`#17553 <https://github.com/godotengine/godot/issues/17553>`_)
 
 
 Performance of C# in Godot
 Performance of C# in Godot
 --------------------------
 --------------------------

+ 2 - 0
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]
     [Signal]
     delegate void MySignal(string willSendsAString);
     delegate void MySignal(string willSendsAString);
 
 
+See also: :ref:`c_sharp_signals`
+
 Singletons
 Singletons
 ----------
 ----------
 
 

+ 36 - 2
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 <https://docs.microsoft.com/en-us/dotnet/csharp/pattern-matching>`_.
 For more advanced type checking, you can look into `Pattern Matching <https://docs.microsoft.com/en-us/dotnet/csharp/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.
 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).
 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 <https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table>`_ and Classes derived from :ref:`Godot.Object <class_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``).
 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
 .. code-block:: csharp