| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- using UnityEngine.UI;
- namespace TheraBytes.BetterUi
- {
- #if UNITY_2018_3_OR_NEWER
- [ExecuteAlways]
- #else
- [ExecuteInEditMode]
- #endif
- [HelpURL("https://documentation.therabytes.de/better-ui/BetterAspectRatioFitter.html")]
- [AddComponentMenu("Better UI/Layout/Better Aspect Ratio Fitter", 30)]
- public class BetterAspectRatioFitter : AspectRatioFitter, IResolutionDependency
- {
- [Serializable]
- public class Settings : IScreenConfigConnection
- {
- public AspectMode AspectMode;
- public float AspectRatio = 1;
- [SerializeField]
- string screenConfigName;
- public string ScreenConfigName { get { return screenConfigName; } set { screenConfigName = value; } }
- }
- [Serializable]
- public class SettingsConfigCollection : SizeConfigCollection<Settings> { }
- public Settings CurrentSettings { get { return customSettings.GetCurrentItem(settingsFallback); } }
- public new AspectMode aspectMode
- {
- get { return base.aspectMode; }
- set
- {
- Config.Set(value, (o) => base.aspectMode = value, (o) => CurrentSettings.AspectMode = value);
- }
- }
- public new float aspectRatio
- {
- get { return base.aspectRatio; }
- set
- {
- Config.Set(value, (o) => base.aspectRatio = value, (o) => CurrentSettings.AspectRatio = value);
- }
- }
- [SerializeField]
- Settings settingsFallback = new Settings();
- [SerializeField]
- SettingsConfigCollection customSettings = new SettingsConfigCollection();
-
- protected override void OnEnable()
- {
- base.OnEnable();
- Apply();
- }
-
- public void OnResolutionChanged()
- {
- Apply();
- }
- void Apply()
- {
- base.aspectMode = CurrentSettings.AspectMode;
- base.aspectRatio = CurrentSettings.AspectRatio;
- }
- #if UNITY_EDITOR
- protected override void OnValidate()
- {
- base.OnValidate();
- Apply();
- }
- #endif
- }
-
- }
|