Unify C# naming notes and comments

(cherry picked from commit 8916cbd4b2)
This commit is contained in:
skyace65
2024-03-10 11:30:30 -04:00
committed by Max Hilbrunner
parent 20c41b8486
commit ba30c3de73
9 changed files with 37 additions and 5 deletions

View File

@@ -407,6 +407,7 @@ Next, add this code to the function:
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window.
private void OnBodyEntered(Node2D body)
{
Hide(); // Player disappears after being hit.

View File

@@ -117,6 +117,7 @@ to the ``Mob`` and add this code:
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window.
private void OnVisibleOnScreenNotifier2DScreenExited()
{
QueueFree();

View File

@@ -168,11 +168,13 @@ the other two timers. ``ScoreTimer`` will increment the score by 1.
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window.
private void OnScoreTimerTimeout()
{
_score++;
}
// We also specified this function name in PascalCase in the editor's connection window.
private void OnStartTimerTimeout()
{
GetNode<Timer>("MobTimer").Start();
@@ -219,6 +221,7 @@ Note that a new instance must be added to the scene using ``add_child()``.
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window.
private void OnMobTimerTimeout()
{
// Note: Normally it is best to use explicit types rather than the `var`

View File

@@ -199,12 +199,14 @@ signal of ``MessageTimer``, and add the following code to the new functions:
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window.
private void OnStartButtonPressed()
{
GetNode<Button>("StartButton").Hide();
EmitSignal(SignalName.StartGame);
}
// We also specified this function name in PascalCase in the editor's connection window.
private void OnMessageTimerTimeout()
{
GetNode<Label>("Message").Hide();

View File

@@ -8,6 +8,17 @@ Moving the player with code
It's time to code! We're going to use the input actions we created in the last
part to move the character.
.. note:: For this project, we will be following the Godot naming conventions.
- **GDScript**: Classes (nodes) use PascalCase, variables and
functions use snake_case, and constants use ALL_CAPS (See
:ref:`doc_gdscript_styleguide`).
- **C#**: Classes, export variables and methods use PascalCase,
private fields use _camelCase, local variables and parameters use
camelCase (See :ref:`doc_c_sharp_styleguide`). Be careful to type
the method names precisely when connecting signals.
Right-click the ``Player`` node and select *Attach Script* to add a new script to
it. In the popup, set the *Template* to *Empty* before pressing the *Create*
button.

View File

@@ -241,7 +241,7 @@ method. This function destroys the instance it's called on.
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnVisibilityNotifierScreenExited()
{
QueueFree();
@@ -323,7 +323,7 @@ Here is the complete ``Mob.gd`` script for reference.
Velocity = Velocity.Rotated(Vector3.Up, Rotation.Y);
}
// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnVisibilityNotifierScreenExited()
{
QueueFree();

View File

@@ -244,7 +244,7 @@ Let's code the mob spawning logic. We're going to:
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnMobTimerTimeout()
{
// Create a new instance of the Mob scene.

View File

@@ -96,7 +96,7 @@ a ``die()`` function that helps us put a descriptive label on the code.
QueueFree();
}
// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnMobDetectorBodyEntered(Node3D body)
{
Die();
@@ -143,7 +143,7 @@ Get the timer, and stop it, in the ``_on_player_hit()`` function.
.. code-tab:: csharp
// We also specified this function name in PascalCase in the editor's connection window
// We also specified this function name in PascalCase in the editor's connection window.
private void OnPlayerHit()
{
GetNode<Timer>("MobTimer").Stop();

View File

@@ -32,6 +32,17 @@ the bar to reflect the change. To do so, in Godot, you would use signals.
We will now use a signal to make our Godot icon from the previous lesson
(:ref:`doc_scripting_player_input`) move and stop by pressing a button.
.. note:: For this project, we will be following the Godot naming conventions.
- **GDScript**: Classes (nodes) use PascalCase, variables and
functions use snake_case, and constants use ALL_CAPS (See
:ref:`doc_gdscript_styleguide`).
- **C#**: Classes, export variables and methods use PascalCase,
private fields use _camelCase, local variables and parameters use
camelCase (See :ref:`doc_c_sharp_styleguide`). Be careful to type
the method names precisely when connecting signals.
.. Example
Scene setup
@@ -156,6 +167,7 @@ the ``not`` keyword to invert the value.
.. code-tab:: csharp C#
// We also specified this function name in PascalCase in the editor's connection window.
private void OnButtonPressed()
{
SetProcess(!IsProcessing());
@@ -221,6 +233,7 @@ Your complete ``sprite_2d.gd`` code should look like the following.
Position += velocity * (float)delta;
}
// We also specified this function name in PascalCase in the editor's connection window.
private void OnButtonPressed()
{
SetProcess(!IsProcessing());
@@ -393,6 +406,7 @@ Here is the complete ``sprite_2d.gd`` file for reference.
Position += velocity * (float)delta;
}
// We also specified this function name in PascalCase in the editor's connection window.
private void OnButtonPressed()
{
SetProcess(!IsProcessing());