When I use FixedSize on UIRoot, I often face the same problem : I can not set the width ...
So I have add a new Scaling Style with more options : FlexibleSize
How it works :
- You set the height AND width of the UI you are working on.
- You set the scaling mode : FitHeight, FitWidth, Fit or Fill
Here the result when you are working on a 16/10 UI (or images) with differents aspect ratio screens

There is just some lines to add :
In
UIRoot.csReplace (line 24) :
public enum Scaling
{
PixelPerfect,
FixedSize,
FixedSizeOnMobiles,
}
with public enum Scaling
{
PixelPerfect,
FixedSize,
FixedSizeOnMobiles,
FlexibleSize,
}
public enum ScalingMode
{
FitHeight,
FitWidth,
Fit,
Fill,
}
Add (line 78) :
public ScalingMode scalingMode = ScalingMode.Fit;
public Vector2 initialSize
= new Vector2
(1920f, 1080
.0f
);
Add after (line 98) :
float aspect = screen.x / screen.y;
if (scalingStyle == Scaling.FlexibleSize)
{
float initialAspect = initialSize.x / initialSize.y;
switch (scalingMode)
{
case ScalingMode.FitHeight:
return Mathf.RoundToInt(initialSize.y);
case ScalingMode.FitWidth:
return Mathf.RoundToInt(initialSize.x / aspect);
case ScalingMode.Fit:
if (initialAspect > aspect)
return Mathf.RoundToInt(initialSize.x / aspect);
else
return Mathf.RoundToInt(initialSize.y);
case ScalingMode.Fill:
if (initialAspect < aspect)
return Mathf.RoundToInt(initialSize.x / aspect);
else
return Mathf.RoundToInt(initialSize.y);
}
}
Add before (line 172) :
if (height < minimumHeight) return (float)minimumHeight / height;
if (scalingStyle == Scaling.FlexibleSize)
return (float)activeHeight / height;
In
UIRootEditor.csReplace (line 21):
if (scaling != UIRoot.Scaling.PixelPerfect)
{
NGUIEditorTools.DrawProperty("Manual Height", serializedObject, "manualHeight");
}
if (scaling != UIRoot.Scaling.FixedSize)
{
NGUIEditorTools.DrawProperty("Minimum Height", serializedObject, "minimumHeight");
NGUIEditorTools.DrawProperty("Maximum Height", serializedObject, "maximumHeight");
}
with if (scaling != UIRoot.Scaling.PixelPerfect && scaling != UIRoot.Scaling.FlexibleSize)
{
NGUIEditorTools.DrawProperty("Manual Height", serializedObject, "manualHeight");
}
if (scaling != UIRoot.Scaling.FixedSize && scaling != UIRoot.Scaling.FlexibleSize)
{
NGUIEditorTools.DrawProperty("Minimum Height", serializedObject, "minimumHeight");
NGUIEditorTools.DrawProperty("Maximum Height", serializedObject, "maximumHeight");
}
if (scaling == UIRoot.Scaling.FlexibleSize)
{
NGUIEditorTools.DrawProperty("Initial Size", serializedObject, "initialSize");
NGUIEditorTools.DrawProperty("Scale Mode", serializedObject, "scalingMode");
}
That's all.
It's not a big change, but I think it can help a lot of people that have the same pb. It would be nice if something like that, is added to NGUI, so feel free to use this code ;-)
BTW you will notice that FitHeight as the same effect as FixedSize. It's possible to merge them, but I don't know if it's a breaking change, so I did not.
Enjoy ^^
Decco