AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
IOInit.cs
1 using System.Collections;
2 using System;
3 using System.Collections.Generic;
4 using UnityEngine;
5 using System.IO;
6 using Newtonsoft.Json.Linq;
7 using Newtonsoft.Json;
8 using AirControl;
9 using Commons;
10 
11 namespace Communicator
12 {
17  public class IOInit
18  {
19  #region Variables
20  static string persistentDataPath = Application.streamingAssetsPath;
21  static string airControlVersion = CommonFunctions.GET_VERSION();
22  #endregion
23 
24  #region Builtin Methods
25  #endregion
26 
27  #region Custom Methods
28 
35  public static void createSchema<T>( string schemaName) where T : new()
36  {
37  string json = JsonConvert.SerializeObject(new T(),Formatting.Indented, new PrimitiveToStringConverter());
38  string schemaFilePath = System.IO.Path.Combine(persistentDataPath,schemaName);
39  File.WriteAllText(schemaFilePath, json);
40  // Debug.Log("Writting Default schema file to : "+ schemaFilePath);
41  }
42 
47  public static void CreateSchema()
48  {
49  // Write schema to external file for reference
50  createSchema<ControlSchema>("ControlSchema.json");
51  createSchema<OutputSchema>("OutputSchema.json");
52  createSchema<TODSchema>("TOD.json");
53  createSchema<CameraSchema>("CameraSchema.json");
54  createSchema<LevelSchema>("LevelSchema.json");
55  createSchema<WeatherSchema>("WeatherSchema.json");
56  createSchema<UISchema>("UISchema.json");
57  createSchema<AudioSchema>("AudioSchema.json");
58  createSchema<LidarSchema>("LidarSchema.json");
59  createSchema<FuelSchema>("FuelSchema.json");
60  createSchema<PresetSchema>("PresetSchema.json");
61 
62  }
63 
64 
65 
66  #endregion
67 
68  }
72  class PrimitiveToStringConverter : JsonConverter
73  {
74  public override bool CanConvert(Type objectType)
75  {
76  return objectType == typeof(bool);
77  }
78 
79  public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
80  {
81  writer.WriteValue(value.ToString().ToLower());
82  }
83 
84  public override bool CanRead
85  {
86  get { return false; }
87  }
88 
89  public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
90  {
91  throw new NotImplementedException();
92  }
93  }
94 
95 }
Communicator.IOInit
Input Output init Writting schema files to the disk for reference
Definition: IOInit.cs:17
Communicator.IOInit.createSchema< T >
static void createSchema< T >(string schemaName)
Create the schema
Definition: IOInit.cs:35
Communicator.PrimitiveToStringConverter
Converting boolena to string while serializing
Definition: IOInit.cs:72
Communicator.IOInit.CreateSchema
static void CreateSchema()
Create new schem if the *schema.json if it exists or not. These schema can be used for to format pyth...
Definition: IOInit.cs:47
AirControl
Definition: AirplaneSelector.cs:8
Communicator
Definition: InputHandle.cs:10
Commons
Definition: AirplaneProperties.cs:14