更改

跳到导航 跳到搜索
添加226字节 、 2021年4月12日 (一) 15:24
第74行: 第74行:  
# 安装完包之后重新启动 Visual Studio 或者 MonoDevelop
 
# 安装完包之后重新启动 Visual Studio 或者 MonoDevelop
   −
===Add the code===
+
=== 添加代码===
Next let's add some code SMAPI will run.
+
接下来让我们添加一些将运行的 SMAPI 代码
    
<ol>
 
<ol>
<li>Delete the <tt>Class1.cs</tt> or <tt>MyClass.cs</tt> file (see [[Modding:IDE reference#delete-file|how to delete a file]]).</li>
+
<li> 删除 <tt>Class1.cs</tt> 或者 <tt>MyClass.cs</tt> 文件 ( 参阅 [[ 模组:IDE 参考# 删除文件| 如何删除文件]]).</li>
<li>Add a C# class file called <tt>ModEntry.cs</tt> to your project (see [[Modding:IDE reference#Add a file|how to add a file]]).</li>
+
<li> 在项目中添加一个 C# 类文件,取名为 <tt>ModEntry.cs</tt> ( 参阅 [[ 模组:IDE 参考# 添加文件| 如何添加]]).</li>
<li>Put this code in the file (replace <tt>YourProjectName</tt> with the name of your project):
+
<li> 在此文件中输入代码 ( <tt>YourProjectName</tt> 换成你的解决方案的名字):
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
using System;
 
using System;
第91行: 第91行:  
namespace YourProjectName
 
namespace YourProjectName
 
{
 
{
    /// <summary>The mod entry point.</summary>
+
    /// <summary> 模组入口点</summary>
 
    public class ModEntry : Mod
 
    public class ModEntry : Mod
 
    {
 
    {
 
      /*********
 
      /*********
      ** Public methods
+
      ** 公共方法
 
      *********/
 
      *********/
      /// <summary>The mod entry point, called after the mod is first loaded.</summary>
+
      /// <summary> 模组的入口点,在首次加载模组后自动调用</summary>
      /// <param name="helper">Provides simplified APIs for writing mods.</param>
+
      /// <param name="helper"> 对象名:helper 提供用于编写模组的简化接口</param>
 
      public override void Entry(IModHelper helper)
 
      public override void Entry(IModHelper helper)
 
      {
 
      {
 
        helper.Events.Input.ButtonPressed += this.OnButtonPressed;
 
        helper.Events.Input.ButtonPressed += this.OnButtonPressed;
 +
       //意思是将 OnButtonPressed 方法绑定到 SMAPI 的 ButtonPressed 按钮按下事件
 +
       //this 表示本对象,也就是当前的 ModEntry 类
 
      }
 
      }
       
      /*********
 
      /*********
      ** Private methods
+
      ** 私有方法
 
      *********/
 
      *********/
      /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
+
      /// <summary> 在玩家按下键盘、控制器或鼠标上的按钮后引发</summary>
      /// <param name="sender">The event sender.</param>
+
      /// <param name="sender"> 对象 sender 表示调用此方法的对象</param>
      /// <param name="e">The event data.</param>
+
      /// <param name="e"> 对象 e 表示事件数据</param>
 
      private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
 
      private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
 
      {
 
      {
        // ignore if player hasn't loaded a save yet
+
        // 如果玩家还没有进入存档,则取消执行
 
        if (!Context.IsWorldReady)
 
        if (!Context.IsWorldReady)
 
          return;
 
          return;
   −
        // print button presses to the console window
+
        // 向控制台输出按下了什么按钮
 
        this.Monitor.Log($"{Game1.player.Name} pressed {e.Button}.", LogLevel.Debug);
 
        this.Monitor.Log($"{Game1.player.Name} pressed {e.Button}.", LogLevel.Debug);
 
      }
 
      }
203

个编辑

导航菜单