Update some C# examples for 4.0 (#6693)

* Update some C# examples

- Rename members that have been renamed in Godot's C# API for 4.0.
- Change `delta` parameter type to `double`.
- Ensure parameters match base declaration.
- Other minor code fixes.

---------

Co-authored-by: Paul Joannon <437025+paulloz@users.noreply.github.com>
This commit is contained in:
Raul Santos
2023-02-04 17:03:03 +01:00
committed by GitHub
parent d6b4fe8ab9
commit b319da3f07
30 changed files with 236 additions and 219 deletions

View File

@@ -327,7 +327,7 @@ the performance of C# in Godot — while generally in the same order of magnitud
a little faster; the specifics are going to vary according to your use case.
GDScript is likely fast enough for most general scripting workloads.
Most properties of Godot C# objects that are based on ``Godot.Object``
Most properties of Godot C# objects that are based on ``GodotObject``
(e.g. any ``Node`` like ``Control`` or ``Node3D`` like ``Camera3D``) require native (interop) calls as they talk to
Godot's C++ core.
Consider assigning values of such properties into a local variable if you need to modify or read them multiple times at

View File

@@ -74,8 +74,8 @@ Exceptions:
=========================== =======================================================
GDScript C#
=========================== =======================================================
``weakref(obj)`` ``Object.WeakRef(obj)``
``is_instance_valid(obj)`` ``Object.IsInstanceValid(obj)``
``weakref(obj)`` ``GodotObject.WeakRef(obj)``
``is_instance_valid(obj)`` ``GodotObject.IsInstanceValid(obj)``
=========================== =======================================================
Tips
@@ -177,9 +177,9 @@ Example:
Input.IsActionPressed("ui_down")
However, in some very rare cases this is not enough. For example, you may want
to access a member from the base class ``Godot.Object``, like ``Connect``.
to access a member from the base class ``GodotObject``, like ``Connect``.
For such use cases we provide a static property named ``Singleton`` that returns
the singleton instance. The type of this instance is ``Godot.Object``.
the singleton instance. The type of this instance is ``GodotObject``.
Example:
@@ -586,7 +586,7 @@ An expression ``t`` is awaitable if one of the following holds:
.. _ValueTask<TResult>: https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask-1
An equivalent of awaiting a signal in GDScript can be achieved with the ``await`` keyword and
``Godot.Object.ToSignal``.
``GodotObject.ToSignal``.
Example:

View File

@@ -332,14 +332,14 @@ Export annotations are also provided for the physics and render layers defined i
.. code-block:: csharp
[Export(PropertyHint.Layers2dPhysics)]
private int Layers2dPhysics;
[Export(PropertyHint.Layers2dRender)]
private int Layers2dRender;
[Export(PropertyHint.Layers3dPhysics)]
private int layers3dPhysics;
[Export(PropertyHint.Layers3dRender)]
private int layers3dRender;
[Export(PropertyHint.Layers2DPhysics)]
private int Layers2DPhysics;
[Export(PropertyHint.Layers2DRender)]
private int Layers2DRender;
[Export(PropertyHint.Layers3DPhysics)]
private int layers3DPhysics;
[Export(PropertyHint.Layers3DRender)]
private int layers3DRender;
Using bit flags requires some understanding of bitwise operations.
If in doubt, use boolean variables instead.

View File

@@ -92,15 +92,17 @@ Signals support arguments of:
* All the `built-in value types <https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table>`_,
except ``decimal``, ``nint`` and ``nuint``
* ``string``
* Classes derived from :ref:`Godot.Object <class_Object>`
* Classes derived from :ref:`GodotObject <class_Object>`
* Collections types defined in the ``Godot.Collections`` namespace
Consequently, any ``Node`` or ``Reference`` will be compatible automatically, but custom data objects will need
to inherit from ``Godot.Object`` or one of its subclasses.
to inherit from ``GodotObject`` or one of its subclasses.
.. code-block:: csharp
public partial class DataObject : Godot.Object
using Godot;
public partial class DataObject : GodotObject
{
public string MyFirstString { get; set; }
public string MySecondString { get; set; }