Exemple #1
0
        /// Returns a locally formatted string suitable to display for big numbers.
        /// It'll show "million" or "billion", accordingly.
        ///
        /// @param amount
        ///		the number to format
        ///
        /// @return a formatted string for the number
        ///
        public static string GetNumberString(long amount)
        {
            string format      = k_numberFormat;
            string parseFormat = k_decimalFormat;
            float  number      = amount;

            if (Math.Abs(amount) >= k_million)
            {
                number = amount / k_million;
                string formatID            = LocalisedTextIdentifiers.k_millionFormat;
                var    localisationService = GlobalDirector.Service <LocalisationService>();
                if (Math.Abs(amount) >= k_billion)
                {
                    number   = amount / k_billion;
                    formatID = LocalisedTextIdentifiers.k_billionFormat;
                }
                format = localisationService.GetGameText(formatID);
            }

            if (Math.Ceiling(number) != Math.Floor(number))
            {
                number      = Mathf.RoundToInt(number * 100) / 100.0f;
                parseFormat = k_floatFormat;
            }

            return(string.Format(format, number.ToString(parseFormat)));
        }
        /// @param callback
        ///     The function to call when all popups are dismissed
        ///
        private void DisplayNextPopup(Action callback)
        {
            if ((m_currentIndex == 0) || (m_currentIndex < m_infoBodies.Count))
            {
                var popupView = GlobalDirector.Service <PopupService>().QueuePopup(m_popupType);
                popupView.SetHeaderText(m_headerID.Localise(m_headerCategory));

                if (m_currentIndex < m_infoBodies.Count)
                {
                    popupView.SetBodyText(m_infoBodies[m_currentIndex].Localise(m_bodyCategory));
                }

                popupView.OnPopupDismissed += (popup) =>
                {
                    DisplayNextPopup(callback);
                };

                ++m_currentIndex;
            }
            else
            {
                m_currentIndex = 0;
                callback.SafeInvoke();
            }
        }
Exemple #3
0
        /// Initialise function
        ///
        public void Initialise()
        {
            m_audioService        = GlobalDirector.Service <AudioService>();
            m_inputService        = GlobalDirector.Service <InputService>();
            m_localisationService = GlobalDirector.Service <LocalisationService>();

            InitialiseInternal();
        }
Exemple #4
0
 /// Called when the global director is ready
 ///
 protected virtual void OnDirectorReady()
 {
     m_localisationService = GlobalDirector.Service <LocalisationService>();
     m_localisationService.OnLanguageChanged += OnLanguageChanged;
     if (m_localisationService.m_loaded == true)
     {
         OnLanguageChanged();
     }
 }
Exemple #5
0
 /// Called when the global director is ready
 ///
 protected override void OnDirectorReady()
 {
     base.OnDirectorReady();
     m_bankService = GlobalDirector.Service <BankService>();
     if (m_currencyID != string.Empty)
     {
         SetCurrency(m_currencyID);
     }
 }
Exemple #6
0
        /// @param localDirector
        ///     The local director owner of the Controller
        /// @param sceneView
        ///     The view component of the scene
        /// @param exitSceneID
        ///     The ID of the scene to exit to
        ///
        public SceneFSMController(LocalDirector localDirector, SceneFSMView sceneView, string exitSceneID = "")
            : base(localDirector, sceneView)
        {
            m_sceneView   = sceneView;
            m_exitSceneID = exitSceneID;

            m_audioService = GlobalDirector.Service <AudioService>();
            m_inputService = GlobalDirector.Service <InputService>();
            m_sceneService = GlobalDirector.Service <SceneService>();
        }
Exemple #7
0
        ///	Constructor
        ///
        protected MetadataLoader()
        {
            GlobalDirector.Service <MetadataService>().RegisterLoader(this);

            Init();

            if (m_loaderBehaviour == LoaderBehaviour.LoadAllAtInit)
            {
                LoadGroup(string.Empty);
            }
        }
Exemple #8
0
        /// @param savable
        ///     The savable to serialize to file
        ///
        public static void Save(this ISavable savable)
        {
            string filePath = string.Format(k_filePathFormat, savable.GetType().ToString());

            if (FileSystem.DoesFileExist(filePath, FileSystem.Location.Persistent))
            {
                // Create a backup automatically
                string backup = string.Format(k_filePathBackupFormat, savable.GetType().ToString());
                FileSystem.CopyFile(filePath, backup, FileSystem.Location.Persistent);
            }

            // Queue the save
            var saveData = (Dictionary <string, object>)savable.Serialize();

            GlobalDirector.Service <SaveService>().AddSaveJob(filePath, saveData);
        }
Exemple #9
0
        /// Dismiss & destroy this popup after the Dismissing coroutine has completed
        ///
        private IEnumerator Dismiss()
        {
            if (gameObject.activeInHierarchy == true)
            {
                Disable();

                yield return(StartCoroutine(Dismissing()));

                OnDismissedInternal();
                OnPopupDismissed.SafeInvoke(this);
                Hide();
            }

            GlobalDirector.Service <PopupService>().RemovePopup(this);
            Destroy(gameObject);
        }
Exemple #10
0
        /// Used to complete the initialisation in case the service depends
        /// on other Services
        ///
        public override void OnCompleteInitialisation()
        {
            m_loaded   = false;
            m_language = SystemLanguage.Unknown;
            m_loader   = GlobalDirector.Service <MetadataService>().GetLoader <LocalisedTextData>() as LocalisedTextLoader;

            // Retrieve the starting language
            var startingLanguage = Application.systemLanguage;

            if (PlayerPrefs.HasKey(LocalisedTextIdentifiers.k_languageSettings) == true)
            {
                startingLanguage = PlayerPrefs.GetString(LocalisedTextIdentifiers.k_languageSettings).AsEnum <SystemLanguage>();
            }
            SetLanguage(startingLanguage);

            LoadCategories();
        }
Exemple #11
0
        /// Writes the given bytes to a binary file at the given path relative to the platform's storage
        /// location. This method will create the file if it does not already exist and overwrite an
        /// existing file.
        ///
        /// @param data
        ///     Binary data to write
        /// @param relativePath
        ///     Path relative to data storage at which to write, or null
        /// @param location
        ///     Directory location. Default to Persistent
        /// @param action
        ///     Action to perform when the task is completed
        ///
        public static void WriteBinaryFileAsync(byte[] data, string relativePath, Location location = Location.Persistent, Action action = null)
        {
#if UNITY_WEBGL
            Debug.Assert(false, "WebGL cannot perform file operations.");
#endif
            var taskSchedulerService = GlobalDirector.Service <TaskSchedulerService>();
            taskSchedulerService.ScheduleBackgroundTask(() =>
            {
                WriteBinaryFile(data, relativePath, location);
                if (action != null)
                {
                    taskSchedulerService.ScheduleMainThreadTask(() =>
                    {
                        action.Invoke();
                    });
                }
            });
        }
Exemple #12
0
        /// Used to complete the initialisation in case the service depends
        /// on other Services
        ///
        public override void OnCompleteInitialisation()
        {
            m_timeService = GlobalDirector.Service <TimeService>();
            m_pitch       = m_timeService.GetCurrentTimeScale();
            m_timeService.OnTimeScaleChanged += OnTimeScaleChanged;

            // Create a game object to hold audio sources
            m_audioSourceHolder = new GameObject(k_audioSourceName);
            GameObject.DontDestroyOnLoad(m_audioSourceHolder);

            // Load settings if there
            m_musicMuted = PlayerPrefs.GetInt(k_keyMusicMuted, k_unmuted) != k_unmuted;
            m_sfxMuted   = PlayerPrefs.GetInt(k_keySFXMuted, k_unmuted) != k_unmuted;

            // Create a music source for the music
            CreateMusicSource();

            // Create audio sources for the sfx
            CreateSFXSources(k_sfxListSize);
            CreateLoopingSources(k_loopListSize);

            this.RegisterCaching();
        }
Exemple #13
0
        /// Reads data from the binary file at the given path relative
        /// to the platform's storage location. This method will log an error
        /// if the file does not exist, or if no action is provided.
        ///
        /// @param relativePath
        ///     Path relative to data storage at which to save, or null
        /// @param location
        ///     Directory location
        /// @param action
        ///     Action to perform when the task is completed. Will pass the read data.
        ///
        public static void ReadBinaryFileAsync(string relativePath, Location location, Action <byte[]> action)
        {
#if UNITY_WEBGL
            Debug.Assert(false, "WebGL cannot perform file operations.");
#endif
            if (action != null)
            {
                var taskSchedulerService = GlobalDirector.Service <TaskSchedulerService>();
                taskSchedulerService.ScheduleBackgroundTask(() =>
                {
                    byte[] data = ReadBinaryFile(relativePath, location);

                    taskSchedulerService.ScheduleMainThreadTask(() =>
                    {
                        action.Invoke(data);
                    });
                });
            }
            else
            {
                Debug.LogError("No callback provided.");
            }
        }
Exemple #14
0
 /// @param savable
 ///     The savable to register for local caching only
 ///
 public static void UnregisterCaching(this ISavable savable)
 {
     GlobalDirector.Service <SaveService>().UnregisterCaching(savable);
 }
Exemple #15
0
 /// Used to complete the initialisation in case the service depends
 /// on other Services
 ///
 public override void OnCompleteInitialisation()
 {
     m_taskScheduler = GlobalDirector.Service <TaskSchedulerService>();
 }
Exemple #16
0
 /// Called when the player presses the info button
 ///
 public void OnPressed()
 {
     GlobalDirector.Service <AudioService>().PlaySFX(AudioIdentifiers.k_buttonPressed);
     Trigger();
 }
Exemple #17
0
 /// Used to complete the initialisation in case the service depends
 /// on other Services
 ///
 public override void OnCompleteInitialisation()
 {
     m_sceneService = GlobalDirector.Service <SceneService>();
 }
Exemple #18
0
 /// The Initialise function
 ///
 protected override void Initialise()
 {
     m_audioService = GlobalDirector.Service <AudioService>();
 }