예제 #1
0
        private static ToastsUi InitToastsUi()
        {
            var targetCanvas   = RootCanvas.GetOrAddRootCanvas().gameObject;
            var toastContainer = targetCanvas.AddChild(ResourcesV2.LoadPrefab("Messages/ToastContainer1"));

            return(toastContainer.GetOrAddComponent <ToastsUi>());
        }
예제 #2
0
        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));
        }
예제 #3
0
        private static SnackbarsUi InitSnackbarsUi()
        {
            var targetCanvas      = RootCanvas.GetOrAddRootCanvasV2().gameObject;
            var snackbarContainer = targetCanvas.AddChild(ResourcesV2.LoadPrefab("Messages/SnackbarContainer1"));

            return(snackbarContainer.GetOrAddComponent <SnackbarsUi>());
        }
예제 #4
0
        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));
        }
예제 #5
0
 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));
 }
예제 #6
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
 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);
 }