如何启用另一个类的void bool?

时间:2019-08-10 12:40:38

标签: c# unity3d

我尝试使用另一个类中的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类的 我正在尝试在游戏类上使用它,但无法正常工作

谢谢

谢谢

1 个答案:

答案 0 :(得分:0)

您要么必须先创建LevelEditor的实例,要么使其成为静态方法。查看static keyword

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);