/// <summary> /// 根据语言的枚举类型 /// </summary> /// <param name="languageContainer"></param> private void GetLanguageConfigureOnLanguageType(ref List <ImageConfige> languageConfigContainer) { if (languageConfigContainer == null) { languageConfigContainer = new List <ImageConfige>(); } var allLanguage = System.Enum.GetValues(typeof(LocalizationManager.LanguageType)); ImageConfige firstConfigure = null; string sptitePath = ""; //根据不同的语言生成一个目录 自动关联 foreach (var language in allLanguage) { ImageConfige config = null; LocalizationManager.LanguageType languageType = (LocalizationManager.LanguageType)System.Enum.Parse(typeof(LocalizationManager.LanguageType), language.ToString()); if (languageConfigContainer.Count == 0) { config = GetTargetImageProperty(languageType); // GetSpritePathByLanguage(ref sptitePath,config.m_SourceImage, LocalizationManager.GetLanguageName(config.m_Language)); firstConfigure = config; } else { config = new ImageConfige(languageType, firstConfigure.m_ImageProperty); } if (IsExitLanguageConfigure(config.m_Language, m_TotalImageConfigure.m_ImageLanguageConfige)) { continue; } languageConfigContainer.Add(config); } }
//获取第一个语言对应的配置 取当前脚本挂载对象上的属性 private ImageConfige GetTargetImageProperty(LocalizationManager.LanguageType firstLanguage) { ImageConfige _configure = new ImageConfige(); _configure.m_Language = firstLanguage; _configure.m_SourceImage = m_TargetImage.sprite; InitialedImageProperty(ref _configure.m_ImageProperty); return(_configure); }
/// <summary> /// 根据参数给定的语言切换图片 /// </summary> /// <param name="language"></param> public void ShowImageViewBaseOnLanguage(LocalizationManager.LanguageType language) { ImageConfige newImageConfige = GetLanguageConfigure(language); if (newImageConfige == null) { Debug.LogError(string.Format("当前图片{0 }没有配置对应的语言{1} ", gameObject.name, language)); return; } InitialedImageProperty(newImageConfige); }
public void ApplyEditorProperty() { ImageConfige config = GetTargetImageProperty(m_CurrentEditorLanguage); for (int dex = 0; dex < m_TotalImageConfigure.m_ImageLanguageConfige.Count; ++dex) { if (m_TotalImageConfigure.m_ImageLanguageConfige[dex].m_Language == config.m_Language) { // m_ImageLanguageConfige[dex] = config; m_TotalImageConfigure.m_ImageLanguageConfige[dex] = CloneImageConfigureValue(m_TotalImageConfigure.m_ImageLanguageConfige[dex], ref config); OnEditorConfigure(); return; } } m_TotalImageConfigure.m_ImageLanguageConfige.Add(config); OnEditorConfigure(); }
/// <summary> /// 切换设置Image 属性 /// </summary> /// <param name="config"></param> private void InitialedImageProperty(ImageConfige config) { m_TargetImage.sprite = config.m_SourceImage; if (config.m_SourceImage == null) { Debug.LogInfor("当前语言" + config.m_Language + " Name=" + gameObject.name + " 图片没有找到"); } m_TargetImage.type = config.m_ImageProperty.m_ImageType; m_TargetImage.color = config.m_ImageProperty.m_ImageColor; m_TargetImage.preserveAspect = config.m_ImageProperty.m_IsPreserveAspect; if (m_TargetImage.type != Image.Type.Filled) { return; } m_TargetImage.fillMethod = config.m_ImageProperty.m_FillMethod; SetImageFillOriginProperty(ref config.m_ImageProperty); m_TargetImage.fillAmount = config.m_ImageProperty.m_FillAmount; }
//将sources 数据赋值到target中 private ImageConfige CloneImageConfigureValue(ImageConfige target, ref ImageConfige sources) { target.m_ImageProperty = sources.m_ImageProperty; return(target); }