Beispiel #1
0
        private void HandleNewLevel()
        {
            TWLevel currentLevel = TWGameManager.instance.CurrentLevel;

            if (currentLevel == null ||
                dateText == null || fullLevelText == null ||
                slider == null || handle == null)
            {
                return;
            }

            DateTime now = System.DateTime.Now;

            // Set Date
            // TODO use satic start month and day in location info
            dateText.text = now.ToString("MMMM, d ") + currentLevel.year;

            // Update slider level text
            fullLevelText.text = currentLevel.year + ": " + currentLevel.label;

            // Move slider
            slider.GetComponent <Slider>().value = currentLevel.year;

            // Make sure slider handle is last sibling (for z order)
            handle.GetComponent <Transform>().SetAsLastSibling();

            levelLoadTime = Time.timeSinceLevelLoad;
        }
Beispiel #2
0
        private void SetCurrentLevel()
        {
            if (timeWalkLevels == null)
            {
                return;
            }

            TWLevel newLevel = null;

            timeWalkLevels.ForEach(delegate(TWLevel l)
            {
                if (l.isDefault)
                {
                    newLevel = l;
                }
            });

            // Just pick first level if no defaults
            if (newLevel == null)
            {
                newLevel = timeWalkLevels[0];
            }

            SetCurrentLevel(newLevel);
        }
Beispiel #3
0
        public void OnTimeWalkLevelChanged(TWLevel newLevel)
        {
            if (newLevel == null)
            {
                return;
            }

            SetCurrentLevel(newLevel);
        }
Beispiel #4
0
        private void ProcessLevelChange()
        {
            // If current exists and isn't already loading or loaded, load it
            if (currentLevel != null)
            {
                Scene currentLevelScene = SceneManager.GetSceneByName(currentLevel.levelSceneName);
                if (currentLevelLoading)
                {
                    // Make sure it is valid
                    if (currentLevelScene.IsValid())
                    {
                        if (currentLevelScene.isLoaded)
                        {
                            currentLevelLoading = false;

                            // New scene ready
                            if (TWLevelChanged != null)
                            {
                                TWLevelChanged();
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Unable to load " + currentLevelScene.name);
                    }
                }
                else
                if (!currentLevelScene.isLoaded)
                {
                    // Load new scene
                    SceneManager.LoadSceneAsync(currentLevel.levelSceneName, LoadSceneMode.Additive);
                    currentLevelLoading = true;
                }
            }

            // If previous exists and is loaded, unload it
            if (previousLevel != null)
            {
                Scene previousLevelScene = SceneManager.GetSceneByName(previousLevel.levelSceneName);
                if (previousLevelUnloading)
                {
                    if (!previousLevelScene.isLoaded)
                    {
                        // Old scene unloaded
                        previousLevelUnloading = false;
                        previousLevel          = null;
                    }
                }
                else
                {
                    SceneManager.UnloadSceneAsync(previousLevel.levelSceneName);
                    previousLevelUnloading = true;
                }
            }
        }
Beispiel #5
0
        public TWLevel GetLevelByYear(int year)
        {
            TWLevel level = null;

            timeWalkLevels.ForEach(delegate(TWLevel l)
            {
                if (l.year == year)
                {
                    level = l;
                }
            });
            return(level);
        }
Beispiel #6
0
        private void HandleLocationInfo()
        {
            TWLocationInfo locationInfo = TWGameManager.instance.TimeWalkLocationInfo;

            if (locationText == null || locationInfo == null)
            {
                return;
            }

            TWLevel currentLevel = TWGameManager.instance.CurrentLevel;

            locationText.text = locationInfo.city + ", " + locationInfo.state;
            UpdateTime();
        }
Beispiel #7
0
        private void SetCurrentLevel(TWLevel newLevel)
        {
            if (currentLevel == newLevel)
            {
                return;
            }

            previousLevel = currentLevel;
            currentLevel  = newLevel;

            Debug.Log(String.Format("Level change from {0} to {1}",
                                    previousLevel != null ? previousLevel.levelSceneName : "null",
                                    currentLevel != null ? currentLevel.levelSceneName : "null"));
            ProcessLevelChange();
        }
Beispiel #8
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            TWLevel otherLevel = obj as TWLevel;

            if (otherLevel != null)
            {
                return(-1 * this.year.CompareTo(otherLevel.year));
            }
            else
            {
                throw new ArgumentException("Object is not a TWLevel");
            }
        }
Beispiel #9
0
        // Slider handler
        private void ChangeYear(int year)
        {
            TWLevel newLevel = TWGameManager.instance.GetLevelByYear(year);

            TWGameManager.instance.OnTimeWalkLevelChanged(newLevel);
        }
Beispiel #10
0
        private void TruncateLevelText()
        {
            TWLevel currentLevel = TWGameManager.instance.CurrentLevel;

            fullLevelText.text = currentLevel.year.ToString();
        }