首先来说明一下,我写这个章节本身也是对学习过程的记录,主要参考了http://canimod.com/guides/creating-a-smapi-mod中的内容。也推荐大家看看。

*这些是我的开发环境*

  操作系统:

    macOS

  SDK:

       1 MonoFramework-MDK-4.6.2.16.macos10.xamarin.universal.pkg (貌似是.net平台)

     2 XamarinStudio-6.1.2.44.dmg (这个应该是IDE)

  ps:具体的版本依照实际的操作系统来定,或者安装vs。同时你也可以向上面那个英文教程学习~ 

*正式*

  然而在正式配置环境之前,是的,你得保证游戏正常运行。然后依次安装上面两个软件(我相信这是一个很容易的过程,谢谢)。

*创建一个项目*

  &恩,详细过程我还是直接借用过来翻译一下算了~

 

  1. 打开 Visual Studio 或者 MonoDevelop.
  2. 创建一个新的 solution with a library project.
    • 在 Visual Studio中, 选择 Visual C# » Class Library. (确保你选择的是 “Class Library”, 而不是 “Class Library (.NET Core)” 或者 “Class Library (Portable)”.)
    • 在 MonoDevelop中, 选择 Other » .NET » Library.
  3. 改变 the target framework to .NET 4.5 (for compatibility with Linux).
    • 在 Visual Studio中: 右键 project, 选择 Properties, 单击Application 标签, 并且将 Target framework dropdown 选成 .NET Framework 4.5.
    • 在 MonoDevelop中: 右键 project, 选择 Options, 单击 the Build » General 标签, 并且将Target framework dropdown 选成 Mono / .NET 4.5.
  4. 删除项目中的 Class1.cs 或者 MyClass.cs 文件.

  ps:按照上面步骤,我这里新建了一个solution和project名称都为firstMod的项目。需要注意后面的一些配置信息要与这里对应

 

*配置项目*

  项目需要引用这个包 Pathoschild.Stardew.ModBuildConfig NuGet package. 它能够自动配置你的项目,针对当前的平台,正确加载合适的依赖库。

  1.双击下图画圈的部分

  Stardew Valley(星露谷物语)Mod开发之路  1环境配置

  2.弹出了如下界面,然后在搜索框中“Pathoschild.Stardew.ModBuildConfig”,安装并等待完成。

  Stardew Valley(星露谷物语)Mod开发之路  1环境配置

      3.添加一个cs文件,名称 “ModEntry”

  Stardew Valley(星露谷物语)Mod开发之路  1环境配置

  4.将如下内容复制进ModEntry.cs

 1 using System;
 2 using Microsoft.Xna.Framework;
 3 using StardewModdingAPI;
 4 using StardewModdingAPI.Events;
 5 using StardewValley;
 6 
 7 namespace firstMod
 8 {
 9     /// <summary>The mod entry point.</summary>
10     public class ModEntry : Mod
11     {
12         /// <summary>Initialise the mod.</summary>
13         /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
14         public override void Entry(IModHelper helper)
15         {
16             ControlEvents.KeyPressed += this.ReceiveKeyPress;
17         }
18 
19         /*********
20         ** Private methods
21         *********/
22         /// <summary>The method invoked when the player presses a keyboard button.</summary>
23         /// <param name="sender">The event sender.</param>
24         /// <param name="e">The event data.</param>
25         private void ReceiveKeyPress(object sender, EventArgsKeyPressed e)
26         {
27             this.Monitor.Log($"Player pressed {e.KeyPressed}.");
28         }
29     }
30 }
View Code

相关文章:

  • 2021-09-26
  • 2021-06-02
  • 2022-12-23
  • 2021-09-03
  • 2021-07-01
  • 2022-12-23
  • 2021-05-11
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2021-06-23
  • 2021-04-28
  • 2022-12-23
  • 2021-11-02
相关资源
相似解决方案