cannot cast from source type to destination type

125
11 марта 2018, 19:57
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;
        }
    }
}
READ ALSO
Конфликт скрипта с bootstrap.min.js

Конфликт скрипта с bootstrap.min.js

Есть конфликт приведенного внизу кода скрипта с частью кода из bootstrapmin

214
Как подключить Cookies к PopUP окну?

Как подключить Cookies к PopUP окну?

Подскажите, пожалуйста, как подключить куки к popup окну?

231
Как переписать код с onclick на addEventListener?

Как переписать код с onclick на addEventListener?

Как переписать этот код с onclick на addEventListener?

198
react fetch Uncaught (in promise) SyntaxError: Unexpected end of input

react fetch Uncaught (in promise) SyntaxError: Unexpected end of input

Есть react приложение, которое должно делать запрос на ip, результат примерно такой:

333