コード例 #1
0
        public T GetCurrentItem(T fallback)
        {
            // if there is no config matching the screen
            if (ResolutionMonitor.CurrentScreenConfiguration == null)
            {
                return(fallback);
            }

            if (!(sorted))
            {
                Sort();
            }


#if UNITY_EDITOR
            // simulation
            var config = ResolutionMonitor.SimulatedScreenConfig;
            if (config != null)
            {
                if (Items.Any(o => o.ScreenConfigName == config.Name))
                {
                    return(Items.First(o => o.ScreenConfigName == config.Name));
                }
            }
#endif

            // search for screen config
            foreach (T item in items)
            {
                if (string.IsNullOrEmpty(item.ScreenConfigName))
                {
                    return(fallback);
                }

                var c = ResolutionMonitor.GetConfig(item.ScreenConfigName);
                if (c.IsActive)
                {
                    return(item);
                }
            }

            // fallback logic
            foreach (var conf in ResolutionMonitor.GetCurrentScreenConfigurations())
            {
                foreach (var c in conf.Fallbacks)
                {
                    var matchingItem = items.FirstOrDefault(o => o.ScreenConfigName == c);
                    if (matchingItem != null)
                    {
                        return(matchingItem);
                    }
                }
            }

            // final fallback
            return(fallback);
        }
コード例 #2
0
        public float CalculateFactor(string screenConfig)
        {
            ScreenInfo info         = ResolutionMonitor.GetOpimizedScreenInfo(screenConfig);
            Vector2    optimizedRes = info.Resolution;
            float      optimizedDpi = info.Dpi;

            Vector2 actualRes = ResolutionMonitor.CurrentResolution;
            float   actualDpi = ResolutionMonitor.CurrentDpi;

            float factor = 0;

            float max   = (SizeModifiers.Count > 0) ? SizeModifiers.Max((o) => o.Impact) : 1;
            float scale = 0;

            foreach (var entry in SizeModifiers)
            {
                factor += entry.GetFactor(optimizedRes, actualRes, optimizedDpi, actualDpi);
                scale  += entry.Impact / max;
            }

            if (factor == 0) // nothing in list
            {
                factor = 1;
            }
            else
            {
                factor /= scale;
                factor  = 1 - factor;
            }

            if (ExponentialScale != 1)
            {
                factor = Mathf.Pow(factor, ExponentialScale);
            }

            return(factor);
        }
コード例 #3
0
 void Update()
 {
     ResolutionMonitor.Update();
 }
コード例 #4
0
 private void SceneLoaded(Scene scene, LoadSceneMode mode)
 {
     ResolutionMonitor.SetDirty();
     ResolutionMonitor.Update();
 }
コード例 #5
0
 static void Initialize()
 {
     // Ensure instances
     ResolutionMonitor.EnsureInstance();
     Materials.EnsureInstance();
 }