Exemplo n.º 1
0
    public void Init(VisualElement visualElement, PanelSettings panelSettings = null)
    {
        if (texture != null)
        {
            throw new UnityException("Texture already exists.");
        }

        if (visualElement.resolvedStyle.width <= 0 ||
            visualElement.resolvedStyle.height <= 0)
        {
            throw new UnityException("VisualElement has no size. Consider calling Init from GeometryChangedEvent.");
        }

        float scaleX = panelSettings != null
            ? (float)ApplicationUtils.GetCurrentAppResolution().Width / panelSettings.referenceResolution.x
            : 1;
        float scaleY = panelSettings != null
            ? (float)ApplicationUtils.GetCurrentAppResolution().Height / panelSettings.referenceResolution.y
            : 1;

        int width  = (int)(visualElement.resolvedStyle.width * scaleX);
        int height = (int)(visualElement.resolvedStyle.height * scaleY);

        Init(width, height);
        visualElement.style.backgroundImage = new StyleBackground(texture);
    }
Exemplo n.º 2
0
 void Start()
 {
     // Load reference from last scene if needed
     nonStaticSettings = settings;
     if (!initializedResolution)
     {
         initializedResolution = true;
         // GetCurrentAppResolution may only be called from Start() and Awake(). This is why it is done here.
         Settings.GraphicSettings.resolution = ApplicationUtils.GetCurrentAppResolution();
     }
 }
Exemplo n.º 3
0
 protected override void Start()
 {
     base.Start();
     if (Application.isEditor)
     {
         Items           = GetDummyResolutions();
         Selection.Value = Items[0];
     }
     else
     {
         Items = GetResolutions();
         ScreenResolution currentScreenResolution = ApplicationUtils.GetCurrentAppResolution();
         Selection.Value = Items.Where(it => it.Equals(currentScreenResolution))
                           .FirstOrDefault().OrIfNull(Items[0]);
     }
     Selection.Subscribe(newValue => SettingsManager.Instance.Settings.GraphicSettings.resolution = newValue);
 }