c_sharp_basics.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .. _doc_c_sharp:
  2. C#
  3. ===
  4. Introduction
  5. --------------
  6. C# is a high-level programming language developed by Microsoft. In Godot it is implemented with the Mono 5.2 .NET framework including full support for C# 7.0.
  7. .. note:: This is **not** a full-scale tutorial on the C# language as a whole.
  8. If you aren't already familiar with its syntax or features,
  9. see the `Microsoft C# guide <https://docs.microsoft.com/en-us/dotnet/csharp/index>`_.
  10. Necessary Downloads
  11. -------------------------
  12. To use C# in Godot you must have `Mono <http://www.mono-project.com/download/>`_
  13. installed (at least version 5.2), and use a Godot version with Mono enabled, which adds C# support next to the existing options of GDScript, visual scripting and C++.
  14. Windows users also need MS Build 15.0, which comes bundled with Visual Studio 2017,
  15. or can be downloaded separately with `build tools for Visual Studio 2017 <https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15#>`_.
  16. History
  17. --------
  18. Back in 2016 the Godot team reached out to Microsoft, with Miguel de Icaza's
  19. support, to see if they would consider funding C# support being added to
  20. Godot. Microsoft agreed and gave the team a $24,000 donation to work on adding
  21. C# support. Thanks to that donation, Juan Lineietsky and Ignacio Roldán
  22. Etcheverry were able to work on bringing C# support to Godot using the Mono
  23. .NET framework. Support was added to Godot version 3.0 using mono 5.2, giving users
  24. the power of C# in their game making.
  25. Example
  26. -------
  27. Here's a blank C# script with some comments to demonstate how it works.
  28. .. code-block:: csharp
  29. using Godot;
  30. using System;
  31. public class Path : Path
  32. {
  33. // Member variables here, example:
  34. private int a = 2;
  35. private string b = "textvar";
  36. public override void _Ready()
  37. {
  38. // Called every time the node is added to the scene.
  39. // Initialization here
  40. }
  41. public override void _Process(float delta)
  42. {
  43. // Called every frame. Delta is time since last frame.
  44. // Update game logic here.
  45. }
  46. }
  47. Configuring an external editor
  48. -----------------------------------
  49. While Godot does have its own scripting editor, its support for C# is kept
  50. minimal, and it's reccomended that you use an external IDE or editor, such as
  51. Microsoft Visual Studio Code, or MonoDevelop, which provide auto-completion,
  52. debugging and other features useful when working with C#.
  53. To set it up, in Godot click on ``Editor``, then ``Editor Settings``. Scroll
  54. down to the bottom, to the ``Mono`` settings. Under Mono click on ``Editor``,
  55. and on that page choose your external editor of choice.