- UID
- 63011
- UCC
-
- 声望
-
- 好评
-
- 贡献
-
- 最后登录
- 1970-1-1
|
本帖最后由 Showchen 于 2014-12-13 20:27 编辑
C#代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KSP.IO;
using UnityEngine;
namespace TestConfig
{
class TestModule :PartModule
{
[KSPField(isPersistant=true)]
private int TestInt1 = 0;
//出错
//[KSPField(isPersistant = true)]
//private List<int> TestList1= new List<int>();
//未保存
[KSPField(isPersistant = true)]
private string[] testStringArray = { "", "", "", "" };
[KSPField(isPersistant = true)]
private string TestString1 = "Test";
[KSPField]
private ConfigNode TestCFG;
/// <param name="node">A ConfigNode containing the module's parameters from part.cfg or persistent.sfs</param>
public override void OnLoad(ConfigNode node)
{
if (TestCFG == null && node != null)
{
TestCFG = node;
}
if (File.Exists<TestModule>("Test.cfg", new Vessel()))
{
try
{
TestCFG = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "Test.cfg", new Vessel()));
}
catch (Exception e)
{
Debug.LogError("TestModule.OnLoad caught an exception trying to load Test.cfg: " + e);
}
}
}
public override void OnSave(ConfigNode node)
{
try
{
if (TestCFG != null) ConfigNode.CreateConfigFromObject(this);
}
catch (Exception e)
{
Debug.Log("TestModule caught exception in OnSave for " + this.GetType().Name + ": " + e);
}
}
}
}
保存的结果:
MODULE
{
name = TestModule
isEnabled = True
TestInt1 = 0
TestString1 = Test
EVENTS
{
}
ACTIONS
{
}
}
怎么利用API保存下面这些参数?数组、List和Dictionary都不行,难道得自己写?这样好麻烦啊
//未保存
[KSPField(isPersistant = true)]
private List<int> TestList1 = new List<int>();
//未保存
[KSPField(isPersistant = true)]
private string[] testStringArray = { "", "", "", "" };
|
|