private OneShotSoundComponent PlaySound(AudioClip sound, ESoundType soundType, ESoundLocalizationType localizationType, Vector3 position, float minRange = 0f, float maxRange = 0f)
        {
            OneShotSoundComponent oneShotSound       = null;
            GameObject            instantiatedSource = Instantiate(m_AudioSourcePrefab);

            if (instantiatedSource.TryGetComponent(out AudioSource source))
            {
                if (instantiatedSource.TryGetComponent(out oneShotSound))
                {
                    instantiatedSource.transform.position = position;
                    source.clip         = sound;
                    source.spatialBlend = (localizationType == ESoundLocalizationType.Global) ? 0f : 1f;
                    source.minDistance  = (minRange == 0f && maxRange == 0f) ? /*GET DEFAULT VALUE FROM SETTINGS*/ 10f : minRange;
                    source.maxDistance  = (minRange == 0f && maxRange == 0f) ? /*GET DEFAULT VALUE FROM SETTINGS*/ 10f : maxRange;
                    oneShotSound.SetSoundType(soundType);
                }
                else
                {
                    DebugUtils.LogWarning(this, "AudioSourcePrefab has no OneShotSoundComponent, sound will not be played");
                    Destroy(instantiatedSource);
                }
            }
            else
            {
                DebugUtils.LogWarning(this, "AudioSourcePrefab has no AudioSource component, sound will not be played");
                Destroy(instantiatedSource);
            }
            return(oneShotSound);
        }
        //PUBLIC
        //PROTECTED
        //PRIVATE
        #endregion

        #region Attributes
        //PUBLIC
        //PROTECTED
        //PRIVATE
        #endregion

        #region Methods
        //MONOBEHAVIOUR
        protected override void Awake()
        {
            base.Awake();
            if (m_AudioSourcePrefab == null)
            {
                DebugUtils.LogWarning(this, "AudioSourcePrefab not set!");
            }
        }
 public void ButtonBackupDictionary()
 {
     if (BackupDictionary())
     {
         DebugUtils.LogSuccess(this, "Successfully backuped dictionary.");
     }
     else
     {
         DebugUtils.LogWarning(this, "Could not backup dictionary.");
     }
 }
 public void Resume()
 {
     if (m_AudioSource != null)
     {
         m_AudioSource.Play();
         m_IsPaused   = false;
         m_ForcePause = false;
     }
     else
     {
         DebugUtils.LogWarning(this, "Trying to resume but AudioSource is null.");
     }
 }
 //MONOBEHAVIOUR
 protected override void Awake()
 {
     base.Awake();
     if (TryGetComponent(out m_AudioSource))
     {
         m_AudioSource.Play();
     }
     else
     {
         DebugUtils.LogWarning(this, "No AudioSource component on gameObject.");
         Destroy(gameObject);
     }
 }
 //PRIVATE
 private void InternPause(bool force = false)
 {
     if (m_AudioSource != null)
     {
         m_AudioSource.Pause();
         m_IsPaused   = true;
         m_ForcePause = force;
     }
     else
     {
         DebugUtils.LogWarning(this, "Trying to pause but AudioSource is null.");
     }
 }
Пример #7
0
 public static bool DeleteFile(string path, bool needLogs = false)
 {
     if (File.Exists(path))
     {
         File.Delete(path);
         File.Delete(path + ".meta");
         if (needLogs)
         {
             DebugUtils.LogSuccess(null, "FileUtils.DeleteFile: successfully deleted file " + DebugUtils.ToQuote(path) + ".");
         }
         return(true);
     }
     else if (needLogs)
     {
         DebugUtils.LogWarning(null, "FileUtils.DeleteFile: File " + DebugUtils.ToQuote(path) + " does not exists.");
     }
     return(false);
 }
        private void GenerateDictionary(bool safeMode = true)
        {
            if (m_SupportedLanguages.Length == 0)
            {
                DebugUtils.LogError(this, "No supported languages, aborting generation!");
                return;
            }

            if (HasDuplicatedLanguages(out string duplicatedLanguage))
            {
                DebugUtils.LogError(this, "Found a duplicated language ID: " + DebugUtils.ToQuote(duplicatedLanguage) + " in supported languages, aborting generation!");
                return;
            }

            if (HasDuplicatedStrings(out string duplicatedString))
            {
                DebugUtils.LogError(this, "Found a duplicated string ID: " + DebugUtils.ToQuote(duplicatedString) + " in registered strings, aborting generation!");
                return;
            }

            if (JSONUtils.TryLoadFromPath(m_FilePath, out JSONObject dictionary, true))
            {
                //Start by parsing existing content from file
                if (LocalizationUtils.TryGetLocalizedEntriesFromJSONObject(dictionary, out LocalizedEntries dictionaryEntries, safeMode))
                {
                    //Adding new languages for existing strings
                    List <string> stringIDsToRemove = new List <string>();
                    foreach (string stringID in dictionaryEntries.Keys)
                    {
                        //Remove unsupported strings if needed
                        if (!IsStringSupported(stringID))
                        {
                            if (safeMode)
                            {
                                DebugUtils.LogWarning(this, "Found a non supported string ID: " + DebugUtils.ToQuote(stringID) + ". Please consider removing this entry.");
                            }
                            else
                            {
                                stringIDsToRemove.Add(stringID);
                                break;
                            }
                        }

                        List <string> missingLanguages = new List <string>();
                        foreach (LocalizedLanguage language in m_SupportedLanguages)
                        {
                            missingLanguages.Add(language.GetID());
                        }

                        List <string> languagesToRemove = new List <string>();
                        foreach (string languageID in dictionaryEntries[stringID].Keys)
                        {
                            if (IsLanguageSupported(languageID))
                            {
                                missingLanguages.Remove(languageID);
                            }
                            else
                            {
                                if (safeMode)
                                {
                                    DebugUtils.LogWarning(this, "Found a non supported language ID: " + DebugUtils.ToQuote(languageID) + " for string " + DebugUtils.ToQuote(stringID) + ". Please consider removing this entry.");
                                }
                                else
                                {
                                    languagesToRemove.Add(languageID);
                                }
                            }
                        }

                        //Remove unsupported languages if needed
                        foreach (string languageID in languagesToRemove)
                        {
                            dictionaryEntries[stringID].Remove(languageID);
                            DebugUtils.Log(this, "Removed a non supported language entry: " + DebugUtils.ToQuote(languageID) + " for string " + DebugUtils.ToQuote(stringID) + ".");
                        }

                        //Adding missing language entries
                        foreach (string languageID in missingLanguages)
                        {
                            if (!dictionaryEntries[stringID].ContainsKey(languageID))
                            {
                                dictionaryEntries[stringID][languageID] = "";
                            }
                        }
                    }

                    //Remove unsupported string Ids if needed
                    foreach (string stringID in stringIDsToRemove)
                    {
                        dictionaryEntries.Remove(stringID);
                        DebugUtils.Log(this, "Removed a non supported entry: " + DebugUtils.ToQuote(stringID) + ".");
                    }

                    //Adding missing entries
                    foreach (LocalizedStringData stringData in m_Strings)
                    {
                        if (!dictionaryEntries.ContainsKey(stringData.GetID()))
                        {
                            if (stringData.GetID() != "")
                            {
                                Dictionary <string, string> valuesByLanguage = new Dictionary <string, string>();
                                foreach (LocalizedLanguage language in m_SupportedLanguages)
                                {
                                    valuesByLanguage[language.GetID()] = "";
                                }
                                dictionaryEntries[stringData.GetID()] = valuesByLanguage;
                            }
                            else
                            {
                                DebugUtils.LogError(this, "Localized string \"" + stringData.name + "\" has no defined ID, aborting generation!");
                                return;
                            }
                        }
                    }

                    //Write dictionary back to file
                    if (BackupDictionary())
                    {
                        JSONUtils.WriteToPath(m_FilePath, LocalizationUtils.GetJSONObjectFromLocalizedEntries(dictionaryEntries), true);
                        ObjectUtils.TryCast(AssetDatabase.LoadAssetAtPath(m_FilePath, typeof(TextAsset)), out m_GeneratedDictionary);
                    }
                    else
                    {
                        DebugUtils.LogError(this, "Could not backup dictionary, aborting generation!");
                    }
                }