private void Update() { base.Update(); foreach (AssetBundle b in AssetBundle.GetAllLoadedAssetBundles()) { if (b.name == "hld/bios/photos") { tmp = b; } } var outStr = ""; if (GetCurrentlySelectedListElement() != null) { outStr = UIB_Utilities.SplitOnFinalUnderscore(GetCurrentlySelectedListElement().name); outStr = UIB_Utilities.SplitCamelCase(outStr); outStr = outStr.Replace(" ", "_"); } try { ImageToUse = tmp.LoadAsset <Sprite>(outStr); } catch (Exception e) { if (e.GetBaseException().GetType() == typeof(NullReferenceException)) { } } var BgPhoto = transform.Find("UIB_Background").Find("Background_Mask").Find("Background_Image") .GetComponent <Image>(); BgPhoto.sprite = ImageToUse; if (BgPhoto != null) { BgPhoto.sprite = ImageToUse; //set recttransform aspect based on image and aspect ratio of screen var ar = UIB_AspectRatioManager.ScreenWidth / UIB_AspectRatioManager.ScreenHeight; var imgAR = 9f / 16f; if (!ar.Equals(imgAR)) { try { if (ImageToUse != null) { BgPhoto.rectTransform.sizeDelta = new Vector2(ImageToUse.rect.width, ImageToUse.rect.height * ar); } } catch (Exception e) { if (e.GetBaseException().GetType() == typeof(NullReferenceException)) { } } } } }
public void Update() { var scrollTransform = scroll.content.transform; if (scrollTransform.childCount == 0) { return; } center = scroll.transform.Find("Center").gameObject; var contentMiddle = center.transform.position; Debug.DrawLine(scroll.viewport.position, contentMiddle, Color.green); for (int i = 0; i < scrollTransform.childCount; i++) { if (scrollTransform.GetChild(i).tag != "App_SubMenuButton") { continue; } if (closest == null) { closest = scrollTransform.GetChild(i).gameObject; } if (scrollTransform.GetChild(i).gameObject != closest) { scrollTransform.GetChild(i).gameObject.GetComponent <UIB_Button>().ResetButtonColors(); } if (Vector3.Distance(scrollTransform.GetChild(i).position, contentMiddle) < Vector3.Distance(closest.transform.position, contentMiddle)) { closest = scrollTransform.GetChild(i).gameObject; } } //if UAP is enabled, we use a different button to focus if (UAP_AccessibilityManager.IsEnabled()) { if (UAP_AccessibilityManager.GetCurrentFocusObject() != null) { if (UAP_AccessibilityManager.GetCurrentFocusObject().tag.Equals("App_SubMenuButton")) { closest = UAP_AccessibilityManager.GetCurrentFocusObject(); } } } CurrentlySelectedListElement = closest; CurrentlySelectedListElement.GetComponent <UIB_Button>().SetupButtonColors(); //Update the background based on the scroll box Sprite ImageToUse = null; AssetBundle tmp = null; foreach (AssetBundle b in AssetBundle.GetAllLoadedAssetBundles()) { if (b.name == "hld/" + ShowName.ToLower() + "/narratives/photos") { tmp = b; } } var outStr = ""; if (GetCurrentlySelectedListElement() != null) { outStr = UIB_Utilities.SplitOnFinalUnderscore(GetCurrentlySelectedListElement().name); outStr = UIB_Utilities.SplitCamelCase(outStr); outStr = outStr.Replace(" ", "_"); outStr = UIB_Utilities.CleanUpHyphenated(outStr); outStr = UIB_Utilities.RemoveAllButLastUnderscore(outStr); } try { ImageToUse = tmp.LoadAsset <Sprite>(outStr); } catch (Exception e) { if (e.GetBaseException().GetType() == typeof(NullReferenceException)) { } } var BgPhoto = transform.Find("UIB_Background").Find("Background_Mask").Find("Background_Image") .GetComponent <Image>(); BgPhoto.sprite = ImageToUse; if (BgPhoto != null) { BgPhoto.sprite = ImageToUse; //set recttransform aspect based on image and aspect ratio of screen var ar = UIB_AspectRatioManager.ScreenWidth / UIB_AspectRatioManager.ScreenHeight; var imgAR = 9f / 16f; if (!ar.Equals(imgAR)) { try { if (ImageToUse != null) { BgPhoto.rectTransform.sizeDelta = new Vector2(ImageToUse.rect.width, ImageToUse.rect.height * ar); } } catch (Exception e) { if (e.GetBaseException().GetType() == typeof(NullReferenceException)) { } } } } }