private IEnumerator DownloadStream(string fullPath, System.Action <Stream> onLoadedCallback) { UnityWebRequest www = UnityWebRequest.Get(fullPath); if (www == null) { TimiDebug.LogErrorColor("www object is null for file path: " + fullPath, LogColor.red); yield break; } yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { TimiDebug.LogErrorColor("Error loading " + fullPath + ": " + www.error, LogColor.red); yield break; } MemoryStream stream = new MemoryStream(www.downloadHandler.data); if (stream == null) { TimiDebug.LogErrorColor("MemoryStream is null for file path: " + fullPath, LogColor.red); yield break; } onLoadedCallback.Invoke(stream); }
private IEnumerator InitializeGroup() { if (this._initializableObjects == null) { yield break; } var enumerator = this._initializableObjects.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current == null) { TimiDebug.LogErrorColor("Initializable object list in group " + this._groupName + " has a null object", LogColor.red); continue; } IInitializable initializable = enumerator.Current.GetComponent <IInitializable>(); if (initializable == null) { TimiDebug.LogErrorColor(enumerator.Current.name + " has no " + typeof(IInitializable).Name, LogColor.red); continue; } TimiDebug.LogColor("Initializing " + enumerator.Current.name, LogColor.green); initializable.StartInitialize(); if (this._serialLoad) { while (!initializable.IsFullyInitialized) { yield return(null); } } } }
public void LoadSceneSync(string sceneName, LoadSceneMode mode) { if (!this.CanLoadScene(sceneName)) { TimiDebug.LogErrorColor("Scene name not set", LogColor.red); return; } SceneManager.LoadScene(sceneName, mode); }
// Reads a CSV that is formatted as comma separated values per line // The first line must contain the legend public static CSVResult ReadCSVFile(string filePath) { FileStream fileStream = FileUtils.OpenFileStream(filePath, FileMode.Open, FileAccess.Read); if (fileStream == null) { return(null); } StreamReader streamReader = new StreamReader(fileStream); if (streamReader.Peek() < 0) { TimiDebug.LogErrorColor("Empty file", LogColor.grey); return(null); } CSVResult result = new CSVResult(); // Read the legend from the first line string legendLine = streamReader.ReadLine(); string[] legend = legendLine.Split(','); for (int i = 0; i < legend.Length; ++i) { result.keysPerItem.Add(legend[i]); } int lineNumber = 0; while (streamReader.Peek() >= 0) { ++lineNumber; string line = streamReader.ReadLine(); string[] words = line.Split(','); if (result.keysPerItem.Count != words.Length) { TimiDebug.LogWarningColor("Malformed item on line number: " + lineNumber, LogColor.grey); continue; } CSVItem item = new CSVItem(); for (int i = 0; i < result.keysPerItem.Count; ++i) { item.values[result.keysPerItem[i]] = words[i]; } result.items.Add(item); } fileStream.Close(); return(result); }
private static void CreateNewDialogContainer(System.Action <DialogContainer> callback) { PrefabLoader.Instance.InstantiateAsynchronous(kDialogContainerPrefabPath, UIRootView.Instance.MainCanvas.transform, (loadedGO) => { DialogContainer container = loadedGO.GetComponent <DialogContainer>(); if (container != null) { callback.Invoke(container); } else { TimiDebug.LogErrorColor("Not a container", LogColor.red); } }); }
private void SceneLoadCallback(string sceneName, bool sceneLoadedSuccess) { if (sceneLoadedSuccess) { ++this._scenesLoadedCounter; if (this._scenesLoadedCounter >= this._scenesToLoad.Length) { this.IsFullyInitialized = true; } } else { TimiDebug.LogErrorColor("Failed to load scene: " + sceneName, LogColor.red); } }
private IEnumerator LoadAsyncInternal(string path, System.Action <Object> callback) { ResourceRequest request = Resources.LoadAsync(path); yield return(request); if (request.asset == null) { TimiDebug.LogErrorColor("Failed to load resource at path: " + path, LogColor.red); } if (callback != null) { callback.Invoke(request.asset); } }
private IEnumerator LoadMainSceneAsync(System.Action <bool> callback) { if (string.IsNullOrEmpty(this._mainSceneName)) { TimiDebug.LogErrorColor("Main scene not set", LogColor.red); callback.Invoke(false); yield break; } AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(this._mainSceneName, LoadSceneMode.Additive); while (!asyncOperation.isDone) { yield return(null); } callback.Invoke(true); }
private IEnumerator InitializeAsync() { // Register AppDataModel if (this._appDataModel == null) { TimiDebug.LogErrorColor("No app data model configured", LogColor.red); yield break; } yield return(this._appDataModel.LoadDataAsync()); ServiceLocator.RegisterService <AppDataModel>(this._appDataModel); // yield on more things or initialize other things here this.IsFullyInitialized = true; OnAppInitComplete.Invoke(); }
private IEnumerator LoadDataModels() { // Register SharedDataModel if (this._sharedDataModel == null) { TimiDebug.LogErrorColor("No shared data model configured", LogColor.red); yield break; } yield return(this._sharedDataModel.LoadDataAsync()); ServiceLocator.RegisterService <SharedDataModel>(this._sharedDataModel); // Add more data models here this.IsFullyInitialized = true; }
public static FileStream OpenFileStream(string filePath, FileMode openMode, FileAccess accessType) { if (string.IsNullOrEmpty(filePath)) { TimiDebug.LogErrorColor("File path empty", LogColor.grey); return(null); } if ((openMode != FileMode.Create && openMode != FileMode.CreateNew && openMode != FileMode.OpenOrCreate) && !File.Exists(filePath)) { TimiDebug.LogErrorColor("No such file:" + filePath, LogColor.grey); return(null); } FileStream fileStream = new FileStream(filePath, openMode, accessType); return(fileStream); }
private IEnumerator LoadSceneAsyncInternal(string sceneName, LoadSceneMode mode, System.Action <string, bool> callback) { AsyncOperation asyncOperation = this.CanLoadScene(sceneName) ? SceneManager.LoadSceneAsync(sceneName, mode) : null; if (asyncOperation != null) { while (!asyncOperation.isDone) { yield return(null); } callback.Invoke(sceneName, true); } else { TimiDebug.LogErrorColor("Could not load scene: " + sceneName, LogColor.red); callback.Invoke(sceneName, false); } }
public void StartInitialize() { // Make sure the protobuf library can de/serialize custom data types ProtobufInit.RegisterCustomTypes(); // Register PrefabLoader if (this._prefabloader != null) { ServiceLocator.RegisterService <PrefabLoader>(this._prefabloader); } else { TimiDebug.LogErrorColor("No prefab loader configured", LogColor.red); return; } // Register SceneLoader if (this._sceneLoader != null) { ServiceLocator.RegisterService <SceneLoader>(this._sceneLoader); } else { TimiDebug.LogErrorColor("No scene loader configured", LogColor.red); return; } // Register AssetLoader if (this._assetLoader != null) { ServiceLocator.RegisterService <AssetLoader>(this._assetLoader); } else { TimiDebug.LogErrorColor("No asset loader configured", LogColor.red); return; } this.StartCoroutine(this.LoadDataModels()); }
// Use this for initialization private void Start() { if (AppDataModel.Instance.StarsData == null || AppDataModel.Instance.StarsData.GetAllStars() == null) { TimiDebug.LogErrorColor("No stars loaded", LogColor.red); } TimiDebug.LogColor("Loaded " + AppDataModel.Instance.StarsData.GetAllStars().Count + " stars", LogColor.cyan); var enumerator = AppDataModel.Instance.StarsData.GetAllStars().GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current.common_name.ToLower() == "sirius") { TimiDebug.LogColor(enumerator.Current.apparent_magnitude.ToString(), LogColor.cyan); } // if (!string.IsNullOrEmpty(enumerator.Current.common_name)) { // float apparentMagnitudeNormalized = Mathf.InverseLerp(this._apparentMagnitudeDimmest, this._apparentMagnitudeBrightest, enumerator.Current.apparent_magnitude); // TimiDebug.LogColor(enumerator.Current.common_name + ": " + enumerator.Current.apparent_magnitude + ", " + apparentMagnitudeNormalized, color); // } } }
public void GetStreamFromStreamingAssets(string filePathInStreamingAssets, System.Action <Stream> onLoadedCallback) { string fullPath = Path.Combine(Application.streamingAssetsPath, filePathInStreamingAssets); if (string.IsNullOrEmpty(fullPath)) { TimiDebug.LogErrorColor("No such file", LogColor.red); return; } if (!fullPath.Contains("://")) { // Regular File i/o should work here Stream stream = FileUtils.OpenFileStream(fullPath, FileMode.Open, FileAccess.Read); onLoadedCallback.Invoke(stream); } else { // Paths with "file://" are to be treated like urls and handled with UnityWebRequest this.StartCoroutine(this.DownloadStream(fullPath, onLoadedCallback)); } }
public static void Present(string prefabName) { if (!_loadedDialogs.ContainsKey(prefabName)) { // Create new dialog container: DialogBase.CreateNewDialogContainer((container) => { // Instantiate the dialog prefab PrefabLoader.Instance.InstantiateAsynchronous(prefabName, null, (loadedGO) => { DialogBase dialogBase = loadedGO.GetComponent <DialogBase>(); if (dialogBase != null) { dialogBase.Init(prefabName, container); dialogBase.Show(); } else { TimiDebug.LogErrorColor(prefabName + " is not a dialog", LogColor.red); } }); }); } }
private IEnumerator SerialInitialize() { if (this._initializables == null || this._initializables.Count == 0) { yield break; } float startTimeInSeconds = Time.fixedTime; var enumerator = this._initializables.GetEnumerator(); while (enumerator.MoveNext()) { IInitializable initializable = enumerator.Current as IInitializable; if (initializable == null) { GameObject asGO = enumerator.Current as GameObject; initializable = asGO.GetComponent <IInitializable>(); } if (initializable == null) { TimiDebug.LogErrorColor("Unable to convert " + enumerator.Current.name + " to " + typeof(IInitializable).Name, LogColor.red); continue; } TimiDebug.LogColor("Initializing " + initializable.GetName, LogColor.green); initializable.StartInitialize(); while (!initializable.IsFullyInitialized) { if ((Time.fixedTime - startTimeInSeconds) > MAX_TIMEOUT_IN_SECONDS) { TimiDebug.LogErrorColor("Initialization timed out waiting for: " + initializable.GetName, LogColor.red); yield break; } yield return(null); } } TimiDebug.LogColor("Initialization complete", LogColor.green); }