private static ToastsUi InitToastsUi() { var targetCanvas = RootCanvas.GetOrAddRootCanvas().gameObject; var toastContainer = targetCanvas.AddChild(ResourcesV2.LoadPrefab("Messages/ToastContainer1")); return(toastContainer.GetOrAddComponent <ToastsUi>()); }
public static int CalcCurrentMaxSortingOrderInLayer(this Canvas self) { var l = ResourcesV2.FindAllInScene <Canvas>().Filter(x => { if (x == self) { return(false); } // Skip the input canvas if (!x.enabled) { return(false); } // Only include currently active ones if (!x.gameObject.activeInHierarchy) { return(false); } if (x.sortingLayerID != self.sortingLayerID) { return(false); } var o = x.GetComponent <CanvasOrderOnTop>(); if (o != null && o.excludeFromOrderCalc) { return(false); } return(true); }); return(l.Max(x => x.sortingOrder)); }
private static SnackbarsUi InitSnackbarsUi() { var targetCanvas = RootCanvas.GetOrAddRootCanvasV2().gameObject; var snackbarContainer = targetCanvas.AddChild(ResourcesV2.LoadPrefab("Messages/SnackbarContainer1")); return(snackbarContainer.GetOrAddComponent <SnackbarsUi>()); }
public static int CalcCurrentMaxSortingOrderInLayer(this Canvas self) { var l = ResourcesV2.FindAllInScene <Canvas>().Filter(x => x.gameObject.activeInHierarchy && x.enabled && x != self && x.sortingLayerID == self.sortingLayerID ); return(l.Max(x => x.sortingOrder)); }
private static Task <Dictionary <string, I18n.Translation> > DefaultUnityLocaleLoader(string localeToLoad) { try { var listJson = ResourcesV2.LoadV2 <string>("Locales/" + localeToLoad); var list = JsonReader.GetReader().Read <List <I18n.Translation> >(listJson); return(Task.FromResult(list.ToDictionary(e => e.key, e => e))); } catch (Exception) { } return(Task.FromResult <Dictionary <string, I18n.Translation> >(null)); }
public GameObject Show(string toastCaption, string toastMessage, int displayDurationInMs) { var newToast = ResourcesV2.LoadPrefab("Messages/Toast"); var toastUiElems = newToast.GetLinkMap(); InitText(toastUiElems, "Caption", toastCaption); InitText(toastUiElems, "Message", toastMessage); newToast.GetComponentV2 <MonoBehaviour>().ExecuteDelayed(() => newToast.Destroy(), displayDurationInMs); toastsContainer.AddChild(newToast); return(newToast); }
/// <summary> Works better then GameObject.Find </summary> private static GameObject GetSingletonGameObject(string goName) { var go = GameObject.Find(goName); if (go != null) { return(go); } var list = ResourcesV2.FindAllGOsInScene().Filter(g => g.name == goName && g.GetParent() == null); if (!list.IsEmpty()) { go = list.Single(); // Must be exactly 1 Log.d($"GameObject.Find could not find '{goName} but FindAllGOsInScene did'", go); } return(go); }
public GameObject Show(string snackbarMsg, string buttonMsg, Action <GameObject> snackbarAction, int displayDurationInMs) { var newSnackbar = ResourcesV2.LoadPrefab("Messages/Snackbar"); var map = newSnackbar.GetLinkMap(); map.Get <Text>("Message").text = snackbarMsg; if (snackbarAction != null && !buttonMsg.IsNullOrEmpty()) { map.Get <Text>("SnackbarButton").text = buttonMsg; map.Get <Button>("SnackbarButton").SetOnClickAction(snackbarAction); } else { map.Get <GameObject>("SnackbarButton").Destroy(); } newSnackbar.GetComponentV2 <MonoBehaviour>().ExecuteDelayed(() => newSnackbar.Destroy(), displayDurationInMs); snackbarsContainer.AddChild(newSnackbar); return(newSnackbar); }
private static string DefaultUnityLocaleLoader(string localeToLoad) { try { return(ResourcesV2.LoadV2 <string>("Locales/" + localeToLoad)); } catch (Exception e) { Log.w("Could not load json for locale=" + localeToLoad, e); } return(null); }