123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System;
- using UnityEngine;
- using System.Linq;
- using System.Collections.Generic;
- using Object = UnityEngine.Object;
- namespace I2.Loc
- {
- public interface ILanguageSource
- {
- LanguageSourceData SourceData { get; set; }
- }
- [ExecuteInEditMode]
- [Serializable]
- public partial class LanguageSourceData
- {
- #region Variables
- [NonSerialized] public ILanguageSource owner;
- public Object ownerObject { get { return owner as UnityEngine.Object; } }
- public bool UserAgreesToHaveItOnTheScene = false;
- public bool UserAgreesToHaveItInsideThePluginsFolder = false;
- public bool GoogleLiveSyncIsUptoDate = true;
- [NonSerialized] public bool mIsGlobalSource;
- #endregion
- #region Variables : Terms
- public List<TermData> mTerms = new List<TermData>();
- public bool CaseInsensitiveTerms = false;
- //This is used to overcome the issue with Unity not serializing Dictionaries
- [NonSerialized] public Dictionary<string, TermData> mDictionary = new Dictionary<string, TermData>(StringComparer.Ordinal);
- public enum MissingTranslationAction { Empty, Fallback, ShowWarning, ShowTerm };
- public MissingTranslationAction OnMissingTranslation = MissingTranslationAction.Fallback;
- public string mTerm_AppName;
- #endregion
- #region Variables : Languages
- public List<LanguageData> mLanguages = new List<LanguageData>();
- public bool IgnoreDeviceLanguage; // If false, it will use the Device's language as the initial Language, otherwise it will use the first language in the source.
- public enum eAllowUnloadLanguages { Never, OnlyInDevice, EditorAndDevice }
- public eAllowUnloadLanguages _AllowUnloadingLanguages = eAllowUnloadLanguages.Never;
- #endregion
- #region Variables : Google
- public string Google_WebServiceURL;
- public string Google_SpreadsheetKey;
- public string Google_SpreadsheetName;
- public string Google_LastUpdatedVersion;
- #if UNITY_EDITOR
- public string Google_Password = "change_this";
- #endif
- public enum eGoogleUpdateFrequency { Always, Never, Daily, Weekly, Monthly, OnlyOnce, EveryOtherDay }
- public eGoogleUpdateFrequency GoogleUpdateFrequency = eGoogleUpdateFrequency.Weekly;
- public eGoogleUpdateFrequency GoogleInEditorCheckFrequency = eGoogleUpdateFrequency.Daily;
- // When Manual, the user has to call LocalizationManager.ApplyDownloadedDataFromGoogle() during a loading screen or similar
- public enum eGoogleUpdateSynchronization { Manual, OnSceneLoaded, AsSoonAsDownloaded }
- public eGoogleUpdateSynchronization GoogleUpdateSynchronization = eGoogleUpdateSynchronization.OnSceneLoaded;
- public float GoogleUpdateDelay = 0; // How many second to delay downloading data from google (to avoid lag on the startup)
- public event LanguageSource.fnOnSourceUpdated Event_OnSourceUpdateFromGoogle; // (LanguageSource, bool ReceivedNewData, string errorMsg)
- #endregion
- #region Variables : Assets
- public List<Object> Assets = new List<Object>(); // References to Fonts, Atlasses and other objects the localization may need
- //This is used to overcome the issue with Unity not serializing Dictionaries
- [NonSerialized] public Dictionary<string, Object> mAssetDictionary = new Dictionary<string, Object>(StringComparer.Ordinal);
- #endregion
- #region EditorVariables
- #if UNITY_EDITOR
- public string Spreadsheet_LocalFileName;
- public string Spreadsheet_LocalCSVSeparator = ",";
- public string Spreadsheet_LocalCSVEncoding = "utf-8";
- public bool Spreadsheet_SpecializationAsRows = true;
- #endif
- #endregion
- #region Language
- public void Awake()
- {
- LocalizationManager.AddSource (this);
- UpdateDictionary();
- UpdateAssetDictionary();
- LocalizationManager.LocalizeAll(true);
- }
- public void OnDestroy()
- {
- LocalizationManager.RemoveSource(this);
- }
-
- public bool IsEqualTo( LanguageSourceData Source )
- {
- if (Source.mLanguages.Count != mLanguages.Count)
- return false;
- for (int i=0, imax=mLanguages.Count; i<imax; ++i)
- if (Source.GetLanguageIndex( mLanguages[i].Name ) < 0)
- return false;
- if (Source.mTerms.Count != mTerms.Count)
- return false;
- for (int i=0; i<mTerms.Count; ++i)
- if (Source.GetTermData(mTerms[i].Term)==null)
- return false;
- return true;
- }
- internal bool ManagerHasASimilarSource()
- {
- for (int i=0, imax=LocalizationManager.Sources.Count; i<imax; ++i)
- {
- LanguageSourceData source = (LocalizationManager.Sources[i] as LanguageSourceData);
- if (source!=null && source.IsEqualTo(this) && source!=this)
- return true;
- }
- return false;
- }
- public void ClearAllData()
- {
- mTerms.Clear ();
- mLanguages.Clear ();
- mDictionary.Clear();
- mAssetDictionary.Clear();
- }
- public bool IsGlobalSource()
- {
- return mIsGlobalSource;
- }
- #endregion
- public void Editor_SetDirty()
- {
- #if UNITY_EDITOR
- if (ownerObject != null)
- {
- UnityEditor.EditorUtility.SetDirty(ownerObject);
- }
- #endif
- }
- }
- }
|