Вместо JsonUtility
Unity я использую Newtonsoft.Json
, потому что первый мне не подходит. В редакторе все работает нормально, но после сборки и запуска игры у меня появляется исключение PlatformNotSupportedException в том месте, где я читал Json. Код:
string json = "";
HeroData data;
if (start)
{
json = File.ReadAllText (Application.dataPath + $ @ "\ Hero \ Default.json");
File.WriteAllText (Application.dataPath + $ @ "\ Hero \ Hero.json", json);
}
else
{
json = File.ReadAllText (Application.dataPath + $ @ "\ Hero \ Hero.json");
File.WriteAllText (Application.dataPath + $ @ "\ Hero \ Hero.json", json);
}
JsonSerializerSettings settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
};
data = JsonConvert.DeserializeObject <HeroData> (json, settings);
Журнал:
Mono path[0] = 'C:/Users/Asus/Desktop/__maze__/MAZE_Data/Managed'
Mono config path = 'C:/Users/Asus/Desktop/__maze__/MonoBleedingEdge/etc'
PlayerConnection initialized from C:/Users/Asus/Desktop/__maze__/MAZE_Data (debug = 0)
PlayerConnection initialized network socket : 0.0.0.0 55366
Multi-casting "[IP] 192.168.1.3 [Port] 55366 [Flags] 2 [Guid] 2986208522 [EditorId] 2200394781 [Version] 1048832 [Id] WindowsPlayer(AsusPC) [Debug] 0 [PackageName] WindowsPlayer" to [225.0.0.222:54997]...
Started listening to [0.0.0.0:55366]
PlayerConnection already initialized - listening to [0.0.0.0:55366]
Initialize engine version: 2018.4.9f1 (ca372476eaba)
GfxDevice: creating device client; threaded=1
Direct3D:
Version: Direct3D 11.0 [level 11.0]
Renderer: NVIDIA GeForce GT 720M (ID=0x1140)
Vendor:
VRAM: 2000 MB
Driver: 23.21.13.8857
Begin MonoManager ReloadAssembly
- Completed reload, in 1.712 seconds
<RI> Initializing input.
<RI> Input initialized.
<RI> Initialized touch support.
UnloadTime: 1.872300 ms
PlatformNotSupportedException: Operation is not supported on this platform.
at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner) [0x00018] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T] (System.Type type) [0x00010] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System.Type createdType) [0x00005] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00093] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00007] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x0010f] in <2676a2da6edc420e890ed28aa4572ee5>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00034] in <791f603facc4473dab4bf640d012ebda>:0
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[TKey,TValue].Get (TKey key) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x0000b] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContract (System.Type type) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe (System.Type type) [0x0000b] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x0000e] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0
at StartAction.StartContinue () [0x00080] in C:\Users\Asus\Desktop\MAZE\Assets\Scripts\OtherScripts\System\StartAction.cs:148
at UnityEngine.Events.InvokableCall.Invoke () [0x00011] in <5f0c93d889f64fa59e8f9853314c2958>:0
at UnityEngine.Events.UnityEvent.Invoke () [0x00023] in <5f0c93d889f64fa59e8f9853314c2958>:0
at UnityEngine.UI.Button.Press () [0x0002d] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\Button.cs:66
at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00012] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\Button.cs:108
at UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00008] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:50
at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00073] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:261
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:265)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress(MouseButtonEventData) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:613)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent(Int32) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:510)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:490)
UnityEngine.EventSystems.StandaloneInputModule:Process() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:254)
UnityEngine.EventSystems.EventSystem:Update() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\EventSystem.cs:377)
(Filename: <2676a2da6edc420e890ed28aa4572ee5> Line: 0)