예제 #1
0
        /// Coroutine to handle transitioning to a scene with a transition screen
        ///
        /// @param sceneLoadOperation
        ///     AsyncOperation for the scene loading
        /// @param transitionView
        ///     SceneTransitionView to use as the transition screen
        /// @param [optional] callback
        ///     Function to call when the transiton is done
        ///
        private IEnumerator StartTransition(AsyncOperation sceneLoadOperation, SceneTransitionView transitionView, Action callback = null)
        {
            sceneLoadOperation.allowSceneActivation = false;

            if (transitionView != null)
            {
                yield return(GlobalDirector.ExecuteCoroutine(transitionView.Show()));
            }

            sceneLoadOperation.allowSceneActivation = true;
            yield return(new WaitUntil(() => sceneLoadOperation.isDone));

            LocalDirector[] localDirectors = GameObject.FindObjectsOfType <LocalDirector>();
            foreach (LocalDirector localDirector in localDirectors)
            {
                yield return(new WaitUntil(() => localDirector.IsReady()));
            }

            callback.SafeInvoke();
            OnSceneActive.SafeInvoke(GetActiveScene());

            if (transitionView != null)
            {
                yield return(GlobalDirector.ExecuteCoroutine(transitionView.Hide()));
            }
        }
예제 #2
0
 ///@param sceneName
 ///     Name of the scene to switch to
 /// @param [optional] callback
 ///     Function to call when the transiton is done
 ///
 public void LoadSceneAdditively(string sceneName, Action callback = null)
 {
     GlobalDirector.ExecuteCoroutine(StartLoadScene(sceneName, LoadSceneMode.Additive, () =>
     {
         callback.SafeInvoke();
     }));
 }
예제 #3
0
 /// Invoke the Action in the end of the frame. If the Action is null, it does nothing.
 /// 
 public static void DelayInvoke(this Action action)
 {
     if (action != null)
     {
         GlobalDirector.WaitForFrame(action);
     }
 }
예제 #4
0
        /// Initialise function
        ///
        public void Initialise()
        {
            m_audioService        = GlobalDirector.Service <AudioService>();
            m_inputService        = GlobalDirector.Service <InputService>();
            m_localisationService = GlobalDirector.Service <LocalisationService>();

            InitialiseInternal();
        }
예제 #5
0
 /// Disposes the static instance of the singleton
 ///
 protected override void OnDirectorDispose()
 {
     if (s_instance == this)
     {
         s_instance   = null;
         s_isDisposed = true;
     }
 }
예제 #6
0
        /// @param sceneName
        ///     Name of the scene to switch to
        /// @param transitionPrefabName
        ///     Name of the prefab inside the default transition folder to use for the transition screen
        /// @param [optional] callback
        ///     Function to call when the transiton is done
        ///
        public void SwitchToScene(string sceneName, string transitionPrefabName, Action callback = null)
        {
            m_scenes.Clear();
            AsyncOperation      loadSceneOperation = SceneManager.LoadSceneAsync(sceneName);
            SceneTransitionView transitionView     = CreateTransitionView(transitionPrefabName);

            GlobalDirector.ExecuteCoroutine(StartTransition(loadSceneOperation, transitionView, callback));
        }
예제 #7
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);
     }
 }
예제 #8
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();
     }
 }
예제 #9
0
 /// Invoke the Action in the end of the frame. If the Action is null, it does nothing.
 /// 
 /// @param param
 /// 	The parameter of the Action
 ///
 public static void DelayInvoke<Type>(this Action<Type> action, Type param)
 {
     if (action != null)
     {
         GlobalDirector.WaitForFrame(() =>
         {
             action.Invoke(param);
         });
     }
 }
예제 #10
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>();
        }
예제 #11
0
 /// Start the presenting process
 ///
 public void RequestPresent()
 {
     m_coroutine = GlobalDirector.ExecuteCoroutine(Present(() =>
     {
         if (m_backButtonEnabled == true)
         {
             m_inputService.AddBackButtonListener(OnBackPressed);
         }
     }));
 }
예제 #12
0
        /// @param animator
        ///     The animator to use
        /// @param animationName
        ///     The name of the animation
        /// @param callback
        ///     The function to call once the animation has played once
        ///
        /// @return The created coroutine
        ///
        public static Coroutine PlayAnimation(this Animator animator, string animationName, Action callback = null)
        {
            var time = animator.GetAnimationLength(animationName);

            if (animator.gameObject.activeInHierarchy)
            {
                animator.Play(animationName);
            }
            return(GlobalDirector.WaitFor(time, callback));
        }
예제 #13
0
 /// Invoke the Action in the end of the frame. If the Action is null, it does nothing.
 /// 
 /// @param paramA
 /// 	The first parameter of the Action
 /// @param paramB
 /// 	The second parameter of the Action
 /// @param [optional] emptyAction
 ///     Whether the action should be emptied after invoking
 ///
 public static void DelayInvoke<TypeA, TypeB>(this Action<TypeA, TypeB> action, TypeA paramA, TypeB paramB)
 {
     if (action != null)
     {
         GlobalDirector.WaitForFrame(() =>
         {
             action.Invoke(paramA, paramB);
         });
     }
 }
예제 #14
0
        ///	Constructor
        ///
        protected MetadataLoader()
        {
            GlobalDirector.Service <MetadataService>().RegisterLoader(this);

            Init();

            if (m_loaderBehaviour == LoaderBehaviour.LoadAllAtInit)
            {
                LoadGroup(string.Empty);
            }
        }
예제 #15
0
 ///@param sceneName
 ///     Name of the scene to unload
 /// @param [optional] callback
 ///     Function to call when the transiton is done
 ///
 public void UnloadScene(string sceneName, Action callback = null)
 {
     if (IsSceneLoaded(sceneName) == true)
     {
         GlobalDirector.ExecuteCoroutine(StartUnloadScene(SceneManager.GetSceneByName(sceneName), callback));
     }
     else
     {
         callback.SafeInvoke();
     }
 }
예제 #16
0
        /// Awake function
        ///
        private void Awake()
        {
            if (string.IsNullOrEmpty(m_category) == true)
            {
                m_category = LocalisedTextIdentifiers.k_categoryGame;
            }

            if (m_textComponent == null)
            {
                m_textComponent = GetComponent <TMP_Text>();
            }
            Debug.Assert(m_textComponent != null, string.Format("Could not find TextMeshPro component on '{0}", transform.name));

            GlobalDirector.CallWhenReady(OnDirectorReady);
        }
예제 #17
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);
        }
예제 #18
0
파일: ISaveable.cs 프로젝트: NicTda/MAGTask
        /// @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);
        }
예제 #19
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();
        }
예제 #20
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();
                    });
                }
            });
        }
예제 #21
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.");
            }
        }
예제 #22
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();
        }
예제 #23
0
        /// Initialises the singleton reference. If this is already set it
        /// proceeds to destroy the current instance. It also create and
        /// initialises the FSM
        ///
        /// @return Whether the Director initialised correctly
        ///
        protected override bool OnDirectorAwake()
        {
            bool result = true;

            if (s_instance == null)
            {
                s_instance = this;

#if UNITY_EDITOR || DEBUG
                LocalDirector[] localDirectors = GetComponents <LocalDirector>();
                Debug.Assert(localDirectors.Length == 0, "GlobalDirector GameObject should not have a LocalDirector on the same object");
#endif
                DontDestroyOnLoad(gameObject);
            }
            else if (s_instance != this)
            {
                m_disposed = true;
                Destroy(this);
                result = false;
            }

            return(result);
        }
예제 #24
0
 /// @param callback
 ///     The function to call when the data is loaded
 ///
 public void LoadCachedData(Action callback = null)
 {
     m_coroutine = GlobalDirector.ExecuteCoroutine(LoadDataAsync(callback));
 }
예제 #25
0
파일: ISaveable.cs 프로젝트: NicTda/MAGTask
 /// @param savable
 ///     The savable to register for local caching only
 ///
 public static void UnregisterCaching(this ISavable savable)
 {
     GlobalDirector.Service <SaveService>().UnregisterCaching(savable);
 }
예제 #26
0
 /// Awake function
 ///
 private void Awake()
 {
     GlobalDirector.CallWhenReady(Initialise);
 }
예제 #27
0
 /// Called when the player presses the info button
 ///
 public void OnPressed()
 {
     GlobalDirector.Service <AudioService>().PlaySFX(AudioIdentifiers.k_buttonPressed);
     Trigger();
 }
예제 #28
0
 /// Start the dismissing process
 ///
 public void RequestDismiss()
 {
     DisableBackButton();
     m_coroutine = GlobalDirector.ExecuteCoroutine(Dismiss());
 }
예제 #29
0
 /// Used to complete the initialisation in case the service depends
 /// on other Services
 ///
 public override void OnCompleteInitialisation()
 {
     m_sceneService = GlobalDirector.Service <SceneService>();
 }
예제 #30
0
 /// Used to complete the initialisation in case the service depends
 /// on other Services
 ///
 public override void OnCompleteInitialisation()
 {
     m_taskScheduler = GlobalDirector.Service <TaskSchedulerService>();
 }