using System;
using System.Collections.Generic;
using System.Reflection;
using Fougerite;
using UnityEngine;
using Module = Fougerite.Module;
using Object = UnityEngine.Object;
namespace ClassLibrary2
{
public class Class1 : Module
{
MethodInfo _genericspawnServerload;
public static Dictionary<string, object> SpawnLists = NewSpawnList();
public override void Initialize()
{
Hooks.OnServerLoaded += Hooks_OnServerLoaded;
}
private void Hooks_OnServerLoaded()
{
SpawnLists = JsonHelper.ReadyConfigChecked(NewSpawnList(), "spawn.json");
_genericspawnServerload = typeof(GenericSpawner).GetMethod("OnServerLoad", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
PathResources();
}
public void PathResources()
{
var count = 0;
foreach (var spawner in UnityEngine.Resources.FindObjectsOfTypeAll<GenericSpawner>())
{
Object.Destroy(spawner);
}
foreach (var spawnlist in SpawnLists)
{
var currentSpawnlist = (Dictionary<string, object>)spawnlist.Value;
var newlist = new List<GenericSpawnerSpawnList.GenericSpawnInstance>();
foreach (var pair in (List<object>)currentSpawnlist["spawnList"])
{
var currentspawninstance = (Dictionary<string, object>)pair;
var newspawnlistdata =
new GenericSpawnerSpawnList.GenericSpawnInstance
{
forceStaticInstantiate = false,
numToSpawnPerTick = Convert.ToInt32(currentspawninstance["numToSpawnPerTick"]),
prefabName = currentspawninstance["prefabName"].ToString(),
targetPopulation = Convert.ToInt32(currentspawninstance["targetPopulation"]),
useNavmeshSample = true,
spawned = new List<GameObject>()
};
newlist.Add(newspawnlistdata);
}
var gameobject = new GameObject();
var generic = gameobject.AddComponent<GenericSpawner>();
generic.transform.position = new Vector3(Convert.ToSingle(currentSpawnlist["position_x"]), Convert.ToSingle(currentSpawnlist["position_y"]), Convert.ToSingle(currentSpawnlist["position_z"]));
generic.initialSpawn = true;
generic._spawnList = newlist;
generic.radius = Convert.ToSingle(currentSpawnlist["radius"]);
_genericspawnServerload.Invoke(generic, new object[] { });
generic.SpawnThink();
count++;
}
Logger.Log($"{count} custom resource spawns where loaded!");
}
static Dictionary<string, object> NewSpawnList()
{
var tblspawnlists = new Dictionary<string, object>();
foreach (var spawner in UnityEngine.Resources.FindObjectsOfTypeAll<GenericSpawner>())
{
var genericspawn = new Dictionary<string, object>
{
{"radius", spawner.radius},
{"thinkDelay", spawner.thinkDelay},
{"position_x", spawner.transform.position.x},
{"position_y", spawner.transform.position.y},
{"position_z", spawner.transform.position.z}
};
var genericlist = new List<object>();
foreach (var spawninstance in spawner._spawnList)
{
var spawninstances = new Dictionary<string, object>
{
{"numToSpawnPerTick", spawninstance.numToSpawnPerTick},
{"prefabName", spawninstance.prefabName},
{"targetPopulation", spawninstance.targetPopulation}
};
genericlist.Add(spawninstances);
}
genericspawn.Add("spawnList", genericlist);
tblspawnlists.Add(tblspawnlists.Count.ToString(), genericspawn);
}
return tblspawnlists;
}
}
}
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Есть конфликт приведенного внизу кода скрипта с частью кода из bootstrapmin
Как переписать этот код с onclick на addEventListener?
Есть react приложение, которое должно делать запрос на ip, результат примерно такой: