public IEnumerator OpenFile(DataModels.DataSet dataSet, bool updateCache = false, Action <bool> callback = null) { string url = Path.Combine(CachePath, dataSet.Name); if (ConnectionManager.Instance.ApiReachable) { if (File.Exists($"{url}.xml") == false || updateCache) { yield return(DownloadFile(dataSet, true)); } if (File.Exists($"{url}.dat") == false || updateCache) { yield return(DownloadFile(dataSet, false)); } } var success = LoadInFile(dataSet); if (success) { InitFile(dataSet); } callback?.Invoke(success); }
public void OpenDataset(DataModels.DataSet model, Action <bool> callback = null) { var success = LoadInFile(model); if (success) { InitFile(model); } callback?.Invoke(success); }
private void InitFile(DataModels.DataSet model) { var trackables = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour trackable in trackables) { if (trackable.name == "New Game Object") { trackable.gameObject.name = trackable.TrackableName; trackable.gameObject.AddComponent <DefaultTrackableEventHandler>(); var contentHandler = trackable.gameObject.AddComponent <ContentHandler>(); StartCoroutine(contentHandler.Initialize()); ConsoleGUI.Instance.WriteLn($"Loading Trackable '{ trackable.TrackableName }' succeded.", Color.green); } } ConsoleGUI.Instance.WriteLn($"Initializing of trackables for dataset({ model.Name}) succesful.", Color.green); }
private IEnumerator DownloadFile(DataModels.DataSet model, bool isXml) { var url = $"{ ConnectionManager.Instance.ApiUrl }/api/DataSet/{ model.Id }/File?isXml={ isXml }"; var request = UnityWebRequest.Get(url); yield return(request.SendWebRequest()); if (request.downloadHandler.data.Length > 0) { var extension = isXml ? ".xml" : ".dat"; var path = Path.Combine(CachePath, model.Name + extension); File.WriteAllBytes(path, request.downloadHandler.data); repository.Cache(model); dataSetInfos[model.Id].Cache = model; ConsoleGUI.Instance.WriteLn($"Downloading of dataset file({ model.Name + extension}) succesful.", Color.green); } }
private bool LoadInFile(DataModels.DataSet model) { var success = false; if (dataSetInfos.TryGetValue(model.Id, out var info) && info.Loaded != null) { return(success); } ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); info.Loaded = objectTracker.CreateDataSet(); var path = Path.Combine(CachePath, model.Name + ".xml"); if (info.Loaded.Load(path, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { objectTracker.Stop(); if (objectTracker.ActivateDataSet(info.Loaded) != false) { ConsoleGUI.Instance.WriteLn($"Activation of dataset({ model.Name}) succesful.", Color.green); success = true; } else { ConsoleGUI.Instance.WriteLn($"Activation of dataset({ model.Name}) failed.", Color.red); } objectTracker.Start(); } else { ConsoleGUI.Instance.WriteLn($"Loading of dataset({ model.Name}) failed.", Color.red); } return(success); }