本文整理汇总了C#中JsonArray.Put方法的典型用法代码示例。如果您正苦于以下问题:C# JsonArray.Put方法的具体用法?C# JsonArray.Put怎么用?C# JsonArray.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray.Put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateNewLevel
KiiObject GenerateNewLevel(bool createFakeUser = false)
{
KiiObject level = Kii.Bucket("worlds").NewKiiObject();
System.DateTime expiration = FindNext20MinAlign(System.DateTime.UtcNow);
JsonArray objects = new JsonArray();
for (int i = 0; i < NumIslandsSpawned(Prestige); i++) {
JsonObject island = LevelGen.GenerateIsland();
PlaceIsland(island);
objects.Put(island);
}
int prestigeLeft = createFakeUser ? 5 : Prestige;
int numVillages = NumVillagesSpawned(prestigeLeft);
for (int i = 0; i < numVillages; i++) {
JsonObject village = RandomGenVillage();
PlaceVillage(village);
objects.Put(village);
}
string username = createFakeUser
? ("NOBODY" + Mathf.FloorToInt(1000f * Random.value).ToString())
: Login.User.Username;
JsonObject helloSign = CreateSign(FindSuitableSpawn(),
username,
"Welcome to " + username
+ " Island!");
PlaceSign(helloSign);
objects.Put(helloSign);
while (prestigeLeft > 0) {
JsonObject item = RandomGenItem(prestigeLeft);
prestigeLeft -= item.GetInt("initValue");
PlaceItem(item);
objects.Put(item);
}
level["owner"] = username;
level["expires"] = expiration.Ticks;
level["objects"] = objects;
Village.RecalculateAll();
level["worldPrestige"] = CountWorldPrestige();
level.Save(false, SaveWorldCallback);
return level;
}
示例2: AddObjectRefreshSave
void AddObjectRefreshSave(JsonObject newObj, bool tryReplace = false)
{
World.Refresh();
JsonArray ja = World.GetJsonArray("objects");
JsonArray newJA = new JsonArray();
if (tryReplace) {
Vector3 currentPos = new Vector3((float) newObj.GetDouble("x"),
(float) newObj.GetDouble("y"),
(float) newObj.GetDouble("z"));
for (int i = 0; i < ja.Length(); i++) {
JsonObject o = ja.GetJsonObject(i);
if (o.GetString("type") != "item"
&& o.GetString("type") != "sign") {
newJA.Put(o);
continue;
}
Vector3 pos = new Vector3((float) o.GetDouble("x"),
(float) o.GetDouble("y"),
(float) o.GetDouble("z"));
if ((pos - currentPos).sqrMagnitude < EPSILON
&& newObj.GetString("type") == o.GetString("type")) {
// Skip if position and type are equal
continue;
}
newJA.Put(o);
}
} else {
newJA = ja;
}
newJA.Put(newObj);
World["objects"] = newJA;
ClearSpawnedObjects();
PopulateWorld(World.GetJsonArray("objects"));
Village.RecalculateAll();
World["worldPrestige"] = CountWorldPrestige();
World.Save();
RecalcPlayerPrestige();
}