/// Save data to Json File /// /// @param fileName /// the file name /// @param saveData /// Data to save /// @param onOverwriteDelegate /// Function that is called if file already exists /// public static void SaveDataToJsonFile <T>(string fileName, T saveData, FileSystem.Location location = FileSystem.Location.Persistent, System.Func <string, bool> onOverwriteDelegate = null) { #if UNITY_WEBGL return; #endif string data = JsonWrapper.Serialize(saveData); if (FileSystem.DoesDirectoryExist(fileName, location)) { if ((onOverwriteDelegate == null) || (onOverwriteDelegate(fileName) == true)) { FileSystem.WriteTextFile(data, fileName, location); } } else { FileSystem.WriteTextFile(data, fileName, location); } #if UNITY_EDITOR //Only do refresh if were on the main thread if (GlobalDirector.Service <TaskSchedulerService>().IsMainThread()) { UnityEditor.AssetDatabase.Refresh(); } #endif }
/// @param text /// The text to localise /// @param category /// The category to check /// @oaram args /// The format arguments /// public static string Localise(this string text, string category, params object[] args) { string localisedText = text; if (string.IsNullOrEmpty(text) == false) { // Cache the localisation service if needed if (m_cachedLocalisationService == null) { m_cachedLocalisationService = GlobalDirector.Service <LocalisationService>(); } // Localise the text if (string.IsNullOrEmpty(category) == false) { localisedText = m_cachedLocalisationService.GetText(category, text); } else { localisedText = m_cachedLocalisationService.GetText(text); } // Apply arguments if available if (args.Length > 0) { localisedText = string.Format(localisedText, args); } } return(localisedText); }
/// @param cost /// The cost to display /// /// @return The formatted cost string /// public static string LocaliseColouredCost(this CurrencyItem cost) { if (m_cachedBankService == null) { m_cachedBankService = GlobalDirector.Service <BankService>(); } string costString = string.Empty; if (k_currencies.Contains(cost.m_currencyID) == true) { costString = cost.LocaliseCost(); } else { if (cost.IsFree() == true) { costString = k_free.LocaliseGame(); } else { int current = Math.Min(m_cachedBankService.GetBalance(cost.m_currencyID), cost.m_value); string currentString = TextUtils.GetFormattedCurrencyString(current); string formatID = k_costFail; if (m_cachedBankService.CanAfford(cost) == true) { formatID = k_costSuccess; } costString = string.Format(formatID.LocaliseGame(), cost.m_currencyID, TextUtils.GetFormattedCurrencyString(cost.m_value), currentString); } } return(costString); }
/// @param scores /// The scores to achieve /// public void InitialiseScores(List <int> scores) { m_audioService = GlobalDirector.Service <AudioService>(); m_scoreText.SafeText(TextUtils.GetFormattedCurrencyString(m_score)); m_scores = scores; foreach (var star in m_starsProgress) { star.SetProgress(0.0f); } }
/// Initialise function /// protected override void Initialise() { m_bankService = GlobalDirector.Service <BankService>(); m_audioService = GlobalDirector.Service <AudioService>(); m_popupService = GlobalDirector.Service <PopupService>(); m_sceneService = GlobalDirector.Service <SceneService>(); m_sceneService.OnSceneActive += OnSceneActive; if (s_instance.Contains(this) == false) { s_instance.Add(this); } }
/// @param localDirector /// The local director owner of the Controller /// @param view /// The view of the scene /// @param cameraController /// The camera controller /// public StartupController(LocalDirector localDirector, StartupView view) : base(localDirector, view) { m_view = view; m_saveService = GlobalDirector.Service <SaveService>(); m_audioService.PlayMusic(AudioIdentifiers.k_musicMain); m_fsm.RegisterStateCallback(k_stateLoad, EnterStateLoad, null, null); m_fsm.RegisterStateCallback(k_stateOutro, EnterStateOutro, null, null); m_fsm.ExecuteAction(k_actionNext); }
/// @param localDirector /// The local director owner of the Controller /// @param view /// The view of the scene /// @param cameraController /// The camera controller /// public MapController(LocalDirector localDirector, MapView view, CameraController cameraContoller) : base(localDirector, view, SceneIdentifiers.k_main) { m_view = view; m_cameraController = cameraContoller; m_popupService = GlobalDirector.Service <PopupService>(); m_audioService.PlayMusicFadeCross(AudioIdentifiers.k_musicMain); m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null); m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle); m_fsm.ExecuteAction(k_actionNext); }
/// @param localDirector /// The local director owner of the Controller /// @param view /// The view of the scene /// @param cameraController /// The camera controller /// public LevelEditorController(LocalDirector localDirector, LevelEditorView view) : base(localDirector, view) { m_view = view; m_popupService = GlobalDirector.Service <PopupService>(); m_levelService = GlobalDirector.Service <LevelService>(); m_levelLoader = GlobalDirector.Service <MetadataService>().GetLoader <LevelData>() as LevelDataLoader; m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null); m_fsm.RegisterStateCallback(k_stateLoad, EnterStateLoad, null, null); m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle); m_fsm.ExecuteAction(k_actionNext); }
/// @param localDirector /// The local director owner of the Controller /// @param view /// The view of the scene /// @param cameraController /// The camera controller /// public MapNodeController(LocalDirector localDirector, MapNodeView view) : base(localDirector, view) { m_audioService = GlobalDirector.Service <AudioService>(); m_popupService = GlobalDirector.Service <PopupService>(); m_levelService = GlobalDirector.Service <LevelService>(); MapNodeView = view; LevelModel = m_levelService.GetLevelModel(MapNodeView.LevelIndex); MapNodeView.SetName(MapNodeView.LevelIndex.ToString()); m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null); m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle); m_fsm.RegisterStateCallback(k_stateLocked, EnterStateLocked, null, ExitStateLocked); m_fsm.RegisterStateCallback(k_stateUnlock, null, null, ExitStateUnlock); m_fsm.RegisterStateCallback(k_stateDone, EnterStateDone, null, ExitStateDone); m_fsm.ExecuteAction(k_actionNext); }
/// @param text /// The text to localise /// @param category /// The category to check /// @oaram args /// The format arguments /// public static string LocaliseRandom(this string text, string category, params object[] args) { // Cache the localisation service if needed if (m_cachedLocalisationService == null) { m_cachedLocalisationService = GlobalDirector.Service <LocalisationService>(); } // Localise the text string localisedText = m_cachedLocalisationService.GetRandomText(category, text); // Apply arguments if available if (args.Length > 0) { localisedText = string.Format(localisedText, args); } return(localisedText); }
/// @param localDirector /// The local director owner of the Controller /// @param view /// The view of the scene /// @param cameraController /// The camera controller /// public LevelController(LocalDirector localDirector, LevelView view) : base(localDirector, view, SceneIdentifiers.k_map) { m_view = view; m_tileFactory = localDirector.GetFactory <TileFactory>(); m_levelService = GlobalDirector.Service <LevelService>(); m_popupService = GlobalDirector.Service <PopupService>(); m_objectiveService = localDirector.GetService <ObjectiveService>(); m_audioService.PlayMusicFadeCross(AudioIdentifiers.k_musicLevel); m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null); m_fsm.RegisterStateCallback(k_stateLoad, EnterStateLoad, null, null); m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle); m_fsm.RegisterStateCallback(k_stateShuffle, EnterStateShuffle, null, null); m_fsm.RegisterStateCallback(k_stateResolve, EnterStateResolve, null, ExitStateResolve); m_fsm.RegisterStateCallback(k_stateWin, EnterStateWin, null, null); m_fsm.RegisterStateCallback(k_stateLose, EnterStateLose, null, null); m_fsm.ExecuteAction(k_actionNext); }
/// Used to complete the initialisation in case the service depends /// on other Services /// public override void OnCompleteInitialisation() { m_sceneService = GlobalDirector.Service <SceneService>(); m_levelLoader = GlobalDirector.Service <MetadataService>().GetLoader <LevelData>() as LevelDataLoader; this.RegisterCaching(); }