Hi, there are a couple of threads already on this subject however I have a solution for anyone, and I hope will be integrated into NGUI for all perhaps, and any changes welcome for integration
History : I was looking at this site :
https://www.grabient.com/ And thought code driven gradients will be cool and so had a look at the forums to see if there were any already given solutions, turned up none. So off I went.
I have changed the inspector to have a foldout for using the gradients making the UI simpler if not using gradients.
The results for a white sprite is this image :
https://ibb.co/naOtMa Code :
UIBasicSprite :
remove lines 51,52
[HideInInspector][SerializeField] protected Color mGradientTop = Color.white;
[HideInInspector
][SerializeField
] protected Color mGradientBottom
= new Color
(0
.7f, 0
.7f, 0
.7f
);
replace with :
[HideInInspector] [SerializeField] protected Color mGradientLeftTop = Color.white;
[HideInInspector] [SerializeField] protected Color mGradientRightTop = Color.white;
[HideInInspector
][SerializeField
] protected Color mGradientLeftBottom
= new Color
(0
.7f, 0
.7f, 0
.7f
); [HideInInspector
][SerializeField
] protected Color mGradientRightBottom
= new Color
(0
.7f, 0
.7f, 0
.7f
);
Then at 480 delete all in AddVertexColours and add this in.
if (mType == Type.Simple)
{
if (y == 1 && x == 1) //Left-Bottom
{
cols.Add(color * mGradientLeftBottom);
}
else if (y == 2 && x == 1) //Left-Top
{
cols.Add(color * mGradientLeftTop);
}
else if (y == 2 && x == 2) //Right-Top
{
cols.Add(color * mGradientRightTop);
}
else if (y == 1 && x == 2) //Right-Bottom
{
cols.Add(color * mGradientRightBottom);
}
}
else if(mType == Type.Sliced)
{
if (y <= 1 && x <= 1 ) //left bottom
{
cols.Add(color * mGradientLeftBottom);
}
else if(y >= 2 && x <= 1) //left top
{
cols.Add(color * mGradientLeftTop);
}
else if (y <= 1 && x >= 2) //right bottom
{
cols.Add(color * mGradientRightBottom);
}
else if (y >= 2 && x >= 2) // right Top
{
cols.Add(color * mGradientRightTop);
}
else
{
cols.Add(color * Color.cyan); //error
}
}
else
{
if (y == 0 || y == 1)
{
cols.Add(color * mGradientRightBottom);
}
else if (y == 2 || y == 3)
{
cols.Add(color * mGradientLeftBottom);
}
}
So now all you have to do is change the custom inspector for the sprite.
image of inspector :
https://ibb.co/eL0F1aIn UIBasicSpriteEditor
Remove all from line 79 -> 95 and replace with :
SerializedProperty grdientProp = serializedObject.FindProperty("mApplyGradient");
if (grdientProp != null)
{
GUILayout.BeginHorizontal();
grdientProp.boolValue = EditorGUILayout.Foldout(grdientProp.boolValue, "Gradient");
GUILayout.EndHorizontal();
if (grdientProp.boolValue)
{
GUILayout.BeginHorizontal();
GUILayout.Space(79f);
NGUIEditorTools.SetLabelWidth(90f);
serializedObject.DrawProperty("mGradientLeftTop", "Top Left", GUILayout.MinWidth(40f));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
NGUIEditorTools.SetLabelWidth(90f);
GUILayout.Space(79f);
serializedObject.DrawProperty("mGradientRightTop", "Top Right", GUILayout.MinWidth(40f));
NGUIEditorTools.SetLabelWidth(80f);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
NGUIEditorTools.SetLabelWidth(90f);
GUILayout.Space(79f);
serializedObject.DrawProperty("mGradientLeftBottom", "Bottom Left", GUILayout.MinWidth(40f));
NGUIEditorTools.SetLabelWidth(80f);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
NGUIEditorTools.SetLabelWidth(90f);
GUILayout.Space(79f);
serializedObject.DrawProperty("mGradientRightBottom", "Bottom Right", GUILayout.MinWidth(40f));
NGUIEditorTools.SetLabelWidth(80f);
GUILayout.EndHorizontal();
}
I've only spent a couple of hours on this, I'm sure there are bits that could be improved, please let me know.
Thanks.