c# - 如何从另一个类启用 void bool?
问题描述
我尝试使用另一个类的 saveLevel (this.saveLevel(true);) ,但没有找到方法。
public void saveLevel(bool binary = true)
{
List<LevelEditor.ObjectsSource> list = new List<LevelEditor.ObjectsSource>();
if (this.validationResult.hasTDSotMObjects)
{
list.Add(LevelEditor.ObjectsSource.DLC1);
}
this.levelData.objectSources = list.ToArray();
LevelEditor.levelDirPath = LevelEditor.createLevelDirIfNotExists(LevelEditor.levelDirPath);
string text = System.IO.Path.Combine(LevelEditor.levelDirPath, "Content");
Directory.CreateDirectory(text);
string path = "Level" + ((!binary) ? ".json" : ".sap");
string path2 = System.IO.Path.Combine(text, path);
LevelEditor.saveLevelData(this.levelData, path2, binary);
这是来自 LevelEditor 类,我试图在 Game 类中使用它,但不起作用
谢谢
谢谢
解决方案
您要么必须创建LevelEditor
first 的实例,要么将其设为静态方法。查看static 关键字。
var levelEditor = new LevelEditor();
// Methods should be CamelCased
levelEditor.SaveLevel(true);
或者
public class LevelEditor
{
// Marked this method 'static'
public static void SaveLevel(bool binary = true)
{
// implementation
}
}
// call like this:
LevelEditor.SaveLevel(true);
推荐阅读
- java - 连接 GATT 服务时应用程序不断崩溃
- html - 如何使用 XML 和 XSL 创建样式表以转换为 HTML 内容?
- c# - 声明变量而不覆盖变量的问题
- javascript - Express 和 Webpack 问题:“Uncaught SyntaxError: Unexpected token <”
- vue.js - TypeError:尝试记录我的 $refs 时无法读取未定义的属性“0”
- c++ - 在 Win32 应用程序中,如何检索应用程序类别信息
- katalon-studio - 如果 sql 查询返回正确的值,katalon 测试用例
- java - How to return the value of an asynchronous callback?
- javascript - Handling errors from forms - Node / Express
- java - Interface null pointer exception in Network Callback onAvailable method