| | |
| | | public class OutlineEx : BaseMeshEffect |
| | | { |
| | | [Header("新shader描边")] |
| | | public Color OutlineColor = Color.white; |
| | | public Color m_OutlineColor= new Color(0, 0, 0, 0.5f);// Color.black; |
| | | public Color OutlineColor |
| | | { |
| | | get { return m_OutlineColor; } |
| | | set |
| | | { |
| | | m_OutlineColor = value; |
| | | this._Refresh(); |
| | | } |
| | | } |
| | | |
| | | QualityTextColType m_ColorType = QualityTextColType.None; |
| | | public QualityTextColType colorType |
| | |
| | | { |
| | | m_ColorType = value; |
| | | OutlineColor = UIHelper.GetUIOutlineColor(value); |
| | | this._Refresh(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | [Range(0, 15)] |
| | | public int OutlineWidth = 0; |
| | | [Range(0, 30)] |
| | | //默认10,不同的颜色(包括调整alpha)视觉上描边粗细有差异,故shader里乘以0.2适应不同情况 |
| | | public int OutlineWidth = 10; |
| | | |
| | | private static List<UIVertex> m_VetexList = new List<UIVertex>(); |
| | | // 材质池:Key为"颜色_宽度"格式的字符串,Value为对应的材质; 减少合批问题,又能保持不同的描边;共用材质会同时改变参数 |
| | | private static Dictionary<string, Material> m_MaterialPool = new Dictionary<string, Material>(); |
| | | private static Shader m_Shader; |
| | | |
| | | static Shader m_tmpShader; |
| | | private static Shader m_Shader |
| | | { |
| | | get |
| | | { |
| | | if (m_tmpShader == null) |
| | | { |
| | | m_tmpShader = Shader.Find("TSF Shaders/UI/OutlineEx"); |
| | | } |
| | | return m_tmpShader; |
| | | } |
| | | } |
| | | |
| | | protected override void Start() |
| | | { |
| | | base.Start(); |
| | | if (m_Shader == null) |
| | | { |
| | | m_Shader = Shader.Find("TSF Shaders/UI/OutlineEx"); |
| | | } |
| | | |
| | | |
| | | // 使用材质池获取或创建材质 |
| | | string key = GetMaterialKey(OutlineColor, OutlineWidth); |
| | | if (!m_MaterialPool.TryGetValue(key, out Material material)) |
| | |
| | | this._Refresh(); |
| | | } |
| | | |
| | | |
| | | #if UNITY_EDITOR |
| | | //在编辑器下打开也刷新下 |
| | | // protected override void OnEnable() |
| | | // { |
| | | // base.OnEnable(); |
| | | // this._Refresh(); |
| | | // } |
| | | |
| | | protected override void OnValidate() |
| | | { |
| | | base.OnValidate(); |
| | |
| | | m_MaterialPool[key] = material; |
| | | } |
| | | |
| | | if (material == null) |
| | | { |
| | | // 防范材质被删的情况,创建新材质 |
| | | material = new Material(m_Shader); |
| | | m_MaterialPool[key] = material; |
| | | } |
| | | |
| | | material.SetColor("_OutlineColor", this.OutlineColor); |
| | | material.SetInt("_OutlineWidth", this.OutlineWidth); |
| | | |