using System.IO; using System.Collections.Generic; using UnityEngine; using sam; using exprivia; using exprivia.editor; [RequireComponent(typeof(ProductLoader))] public class PointVariableSubsessionInitializer : MonoBehaviour { //public List satellites; //public PointVariableSubsession subsession; public IProductDataConsumer subsession { get => _subsession as IProductDataConsumer; set => _subsession = value as Object; } [SerializeField] [RequireInterface(typeof(IProductDataConsumer))] private Object _subsession = null; SatelliteDataTypeConfig cfg; ProductLoader loader; string productName; void Start() { loader = GetComponent(); //FindObjectOfType(); cfg = GlobalDictionary.GetValue("SatelliteDataTypeConfig") as SatelliteDataTypeConfig; if (cfg == null) { Debug.LogError($"PointVariableSubsessionInitializer: SatelliteDataTypeConfig not found in GlobalDictionary"); return; } productName = GlobalDictionary.GetValue("ProductName") as string; if (string.IsNullOrEmpty(productName)) { Debug.LogError($"PointVariableSubsessionInitializer: null product name"); return; } string fullpath = Path.Combine(Application.streamingAssetsPath, cfg.GetProfileFilename()); if (!loader.LoadProfile(fullpath)) { Debug.LogError($"Error loading product profile file {fullpath}"); return; } loader.dateExtractor = cfg.dateExtractionFunc; loader.productNameExtractor = cfg.productNameExtractionFunc; DownloadDataFile(); } void DownloadDataFile() { string dataUrl = cfg.url + "/Products/" + productName; loader.Download(dataUrl, // OnSuccess (loader) => { //subsession.initiallySelectedVariableIndex = cfg.initiallySelectedVariableIndex; subsession.SetInitiallySelectedVariableIndex(cfg.initiallySelectedVariableIndex); subsession.SelectProduct(loader.downloadedData); }, // OnError (loader) => { }); } }