using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
  
 | 
[DisallowMultipleComponent] 
 | 
[RequireComponent(typeof(RectTransform))] 
 | 
public class SectionImage:Graphic { 
 | 
  
 | 
    [SerializeField] 
 | 
    [Range(2,100)] 
 | 
    int m_Section = 3; 
 | 
    public int section { 
 | 
        get { 
 | 
            return m_Section; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    [SerializeField] 
 | 
    [Range(1,200)] 
 | 
    float m_Width = 2f; 
 | 
    public float width { 
 | 
        get { 
 | 
            return m_Width; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    Vector2[] uv0s= new Vector2[4] { Vector2.one,Vector2.one,Vector2.one,Vector2.one }; 
 | 
  
 | 
    protected override void OnPopulateMesh(VertexHelper vh) { 
 | 
        vh.Clear(); 
 | 
  
 | 
        var size = new Vector2(rectTransform.rect.width,rectTransform.rect.height); 
 | 
  
 | 
        var squareCount = section - 1; 
 | 
        var deltaX = (size.x - (section - 1) * width) / section + width; 
 | 
        var startX = -size.x * 0.5f + deltaX - width; 
 | 
  
 | 
        for(var i = 0;i < squareCount;i++) { 
 | 
  
 | 
            var positions = new Vector3[4]; 
 | 
  
 | 
            positions[0] = new Vector2(startX,-size.y * 0.5f); 
 | 
            positions[1] = new Vector2(startX + width,-size.y * 0.5f); 
 | 
            positions[2] = new Vector2(startX + width,size.y * 0.5f); 
 | 
            positions[3] = new Vector2(startX,size.y * 0.5f); 
 | 
  
 | 
            UIUtility.AddQuad(vh,positions,color,uv0s); 
 | 
            startX += deltaX; 
 | 
        } 
 | 
  
 | 
    } 
 | 
} 
 |