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);
                    }
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 private void SetupDebugHUDView()
 {
     if (string.IsNullOrEmpty(this._debugHUDViewPrefabPath))
     {
         TimiDebug.LogWarningColor("Debug hud view prefab path not set", LogColor.orange);
         return;
     }
     PrefabLoader.Instance.InstantiateAsynchronous(this._debugHUDViewPrefabPath, this.MainCanvas.transform);
 }
Beispiel #4
0
 public void LoadSceneSync(string sceneName, LoadSceneMode mode)
 {
     if (!this.CanLoadScene(sceneName))
     {
         TimiDebug.LogErrorColor("Scene name not set", LogColor.red);
         return;
     }
     SceneManager.LoadScene(sceneName, mode);
 }
Beispiel #5
0
 public List <StarData> GetAllStars()
 {
     if (this._data == null)
     {
         TimiDebug.LogWarningColor("No star data", LogColor.grey);
         return(new List <StarData>());
     }
     return(this._data.stars);
 }
Beispiel #6
0
        private void Awake()
        {
            if (UIRootView.Instance != null)
            {
                TimiDebug.LogWarningColor("There should never be more than one UIRootView in the scene!", LogColor.orange);
            }
            UIRootView._instance = this;

            this.SetupDebugHUDView();
        }
Beispiel #7
0
        // 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);
        }
Beispiel #8
0
 private void Start()
 {
     if (this._target != null)
     {
         this.UpdateOrientation();
     }
     else
     {
         TimiDebug.LogWarning("Lookat target not set");
     }
 }
        public static T Service <T>() where T : class, new()
        {
            IService service = null;

            if (_services.TryGetValue(typeof(T), out service))
            {
                return(service as T);
            }
            TimiDebug.LogWarningColor("No service registered for type " + typeof(T).Name, LogColor.red);
            // TODO: currently this does not work for services that are monobehaviours
            service = new T() as IService;
            ServiceLocator.RegisterService <T>(service);
            return(service as T);
        }
Beispiel #10
0
    private void Import(string inputFilePath, string outputFilePath, float apparentMagnitudeCutoff)
    {
        CSVReader.CSVResult csvResult = CSVReader.ReadCSVFile(inputFilePath);
        if (csvResult == null)
        {
            return;
        }

        int       numStarsImported = 0;
        StarsData starsData        = new StarsData();

        starsData.stars = new List <StarData>();

        var enumerator = csvResult.items.GetEnumerator();

        while (enumerator.MoveNext())
        {
            CSVReader.CSVItem item = enumerator.Current;
            float             apparentMagnitude = float.Parse(item.values[APPARENT_MAGNITUDE_KEY]);
            if (apparentMagnitude > apparentMagnitudeCutoff)
            {
                continue;
            }
            ++numStarsImported;

            StarData starData = new StarData();
            starData.common_name         = item.values[COMMON_NAME_KEY];
            starData.right_ascension     = float.Parse(item.values[RIGHT_ASCENSION_KEY]);
            starData.declination         = float.Parse(item.values[DECLINATION_KEY]);
            starData.distance_in_parsecs = float.Parse(item.values[DISTANCE_PARSEC_KEY]);
            starData.apparent_magnitude  = float.Parse(item.values[APPARENT_MAGNITUDE_KEY]);
            starData.absolute_magnitude  = float.Parse(item.values[ABSOLUTE_MAGNITUDE_KEY]);
            starData.constellation_name  = item.values[CONSTELLATION_KEY];
            starData.luminosity          = float.Parse(item.values[LUMINOSITY_KEY]);
            starsData.stars.Add(starData);
        }

        FileStream fileStream = FileUtils.OpenFileStream(outputFilePath, FileMode.Create, FileAccess.Write);

        if (fileStream == null)
        {
            return;
        }

        Serializer.Serialize <StarsData>(fileStream, starsData);
        fileStream.Flush();
        FileUtils.CloseFileStream(fileStream);

        TimiDebug.LogColor("Success! Imported " + numStarsImported.ToString() + " stars", LogColor.green);
    }
Beispiel #11
0
 private void Start()
 {
     if (this._fpsCounterTextMesh == null)
     {
         TimiDebug.LogWarningColor("FPS counter text mesh not set", LogColor.orange);
         GameObject.Destroy(this.gameObject);
     }
     if (this._root == null)
     {
         TimiDebug.LogWarningColor("Root not set", LogColor.orange);
         GameObject.Destroy(this.gameObject);
     }
     this._root.gameObject.SetActive(this._isEnabled);
 }
Beispiel #12
0
 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);
         }
     });
 }
Beispiel #13
0
 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);
     }
 }
Beispiel #14
0
        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);
            }
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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;
        }
Beispiel #17
0
    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();
    }
Beispiel #18
0
    private void Start()
    {
        if (string.IsNullOrEmpty(this._starPrefabPath))
        {
            TimiDebug.LogWarning("Star prefab path not set");
            return;
        }
        if (this._targetCamera == null)
        {
            TimiDebug.LogWarning("Target camera not set");
            return;
        }

        // this.SpawnGridLikeThing();
        this.SpawnStars();
    }
Beispiel #19
0
        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);
        }
Beispiel #20
0
    private void Start()
    {
        if (this._harness == null)
        {
            TimiDebug.LogWarningColor("Harness not set", LogColor.orange);
            GameObject.Destroy(this);
            return;
        }
        if (this._meshFilter == null)
        {
            TimiDebug.LogWarningColor("Mesh Filter not set", LogColor.orange);
            GameObject.Destroy(this);
            return;
        }

        this.GenerateStars(this._meshFilter);
//        this.GenerateOneStar(this._meshFilter);
    }
Beispiel #21
0
        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);
            }
        }
Beispiel #22
0
    // TODO: Remove. This is only for debugging the star position calculations
    private void GenerateOneStar(MeshFilter meshFilter)
    {
        StarData star = AppDataModel.Instance.StarsData.GetStarDataByCommonName("Megrez");

        TimiDebug.LogColor(star.right_ascension + " " + star.declination, LogColor.black);
        int numStars = 1;

        Vector3[] vertices  = new Vector3[4 * numStars];
        int[]     triangles = new int[6 * numStars];
        Vector2[] uvs       = new Vector2[4 * numStars];

        GenerateVerticesForOneStar(star, 0, vertices, triangles, uvs);

        Mesh mesh = new Mesh();

        mesh.vertices   = vertices;
        mesh.triangles  = triangles;
        mesh.uv         = uvs;
        meshFilter.mesh = mesh;
    }
Beispiel #23
0
        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());
        }
Beispiel #24
0
 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);
                 }
             });
         });
     }
 }
Beispiel #25
0
    // 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);
//            }
        }
    }
Beispiel #26
0
        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));
            }
        }
Beispiel #27
0
        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);
        }