using System.Collections; using System.Collections.Generic; using UnityEngine; using Raumgleiter.BaseRGDK; using Raumgleiter.BaseRGDK.JSON; public class JsonLoader : MonoBehaviour { //WorldReference public static JsonLoader WorldReference; //Connections //[Header("Connections")] private ProductManager[] ProductManagers; //Resources //[Header("Resources")] //Attributes //[Header("Attributes")] public const string FileNameJSON = "metadata.json"; //Stats //[Header("Stats")] // protected bool IsSetUp = false; protected bool IsAwoken = false; JSONNode LoadedJSON = JSONNode.Empty(); //Getter public ProductManager[] GetProductManagers() { return ProductManagers; } //Delegates //------------------------------------------------------------------------------------------------------------------ //awake protected void Awake() { //Already Awoken? if (!IsAwoken) { IsAwoken = true; WorldReference = this; } } //------------------------------------------------------------------------------------------------------------------ //start //------------------------------------------------------------------------------------------------------------------ //setup // public void SetUp() // { // Awake(); // IsSetUp = true; // } //------------------------------------------------------------------------------------------------------------------ //destroy //*********************************************************************************************************************** //update //*********************************************************************************************************************** //refresh //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //events //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //private, protected //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //internal //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //public static //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //public public void LoadJSON() { string JSONPath = FileSelection.WorldReference.GetSelectedPath() + "/" + FileNameJSON; LoadedJSON = JSONNode.LoadFromFile(JSONPath); //Load all Products ProductManagers = new ProductManager[LoadedJSON["products"].Count]; for (int i = 0; i < LoadedJSON["products"].Count; i++) { //Create new Manager ProductManagers[i] = new ProductManager(); // SetUp Manager ProductManagers[i].SetUp(LoadedJSON["products"][i]); } } //------------------------------------------------------------------------------------------------------------------ public void SaveJSON() { LoadedJSON["products"] = GetProductsJSON(); string JSONPath = PathsLocal.GetOUT() + "/" + FileNameJSON; LoadedJSON.SaveToFile(JSONPath); } //------------------------------------------------------------------------------------------------------------------ public JSONNode GetProductsJSON() { JSONNode ProductsJSON = new JSONArray(); for (int i = 0; i < ProductManagers.Length; i++) { ProductsJSON[-1] = ProductManagers[i].GetJSON(); } return ProductsJSON; } //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //getter, setter //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ }