void CreateNewData() { using (StreamWriter writer = new StreamWriter(File.Create(Application.streamingAssetsPath + "/cargo.txt"))) { Debug.Log("Generate new json file"); GenericCargo[] Cargo = new GenericCargo[3]; Cargo[0] = new GenericCargo(); Cargo[0].ID = 1; Cargo[0].Name = "Sugar"; Cargo[0].Price = 20f; Cargo[1] = new GenericCargo(); Cargo[1].ID = 2; Cargo[1].Name = "Pepper"; Cargo[1].Price = 40f; Cargo[2] = new GenericCargo(); Cargo[2].ID = 3; Cargo[2].Name = "Beer"; Cargo[2].Price = 25f; string json = JsonConvert.SerializeObject(Cargo, Formatting.Indented); writer.Write(json); writer.Close(); _Cargo = new GenericCargo[Cargo.Length]; for (int i = 0; i < Cargo.Length; i++) { _Cargo[i] = Cargo[i]; } } }
void CreateNewCargoData(string path) { using (StreamWriter writer = new StreamWriter(File.Create(path))) { Debug.Log("Generate new json file for Cargo"); GenericCargo[] Cargo = new GenericCargo[3]; Cargo[0] = new GenericCargo(); Cargo[0].ID = 1; Cargo[0].Name = "Sugar"; Cargo[0].Price = 20f; Cargo[1] = new GenericCargo(); Cargo[1].ID = 2; Cargo[1].Name = "Pepper"; Cargo[1].Price = 40f; Cargo[2] = new GenericCargo(); Cargo[2].ID = 3; Cargo[2].Name = "Beer"; Cargo[2].Price = 25f; string json = JsonConvert.SerializeObject(Cargo, Formatting.Indented); writer.Write(json); writer.Close(); for (int i = 0; i < Cargo.Length; i++) { _Cargo.Add(Cargo[i]); } } }
public GenericCargo ReturnCargoWithID(int ID) { GenericCargo Cargo = new GenericCargo(); for (int i = 0; i < _Cargo.Length; i++) { if (_Cargo[i].ID == ID) { Cargo = _Cargo[i]; } } return(Cargo); }