1
NGUI 3 Support / Re: gradient sprites - solution
« on: October 13, 2017, 06:58:49 AM »
Finally had time for work on this again. I cant work out how to do as you say however could you make AddVertexColours a virtual protected method, then I can just override the calling of the colors like the attached files.
GradientSprite.CS
GradientSpriteEditor.cs
or if you could point me in the right direction on how to actually do this with inheriting from the UISprite that would be great.
GradientSprite.CS
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GradientSprite : UISprite {
- [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);
- protected override void AddVertexColours(List<Color> cols, ref Color color, int x, int y)
- {
- 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);
- }
- }
- }
- }
GradientSpriteEditor.cs
- using UnityEditor;
- using UnityEngine;
- [CanEditMultipleObjects]
- public class GradientSpriteEditor : UISpriteInspector
- {
- protected override void DrawCustomProperties()
- {
- base.DrawCustomProperties();
- 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();
- }
- }
- }
- }
or if you could point me in the right direction on how to actually do this with inheriting from the UISprite that would be great.

