制作UI的过程中,为了节省资源,对称的图一般美术切一半给我们

手动拼图 有时会出现拼接处出现裂缝或重叠

调整大小时也不方便 得一块一块调整

所以就用BaseMeshEffect 的ModifyMesh写了一个脚本

效果是

这样调整这种拼接的UI会方便一些

using UnityEngine;

using System.Collections.Generic;
using UnityEngine.UI; [AddComponentMenu("UI/Effects/TestImageGhost")]
public class TestImageGhost : BaseMeshEffect
{
    public enum Type
    {
        Double,
        Quad,
    }     [SerializeField]
    private Type m_type = Type.Double;     [SerializeField]
    private bool m_UseGraphicAlpha = true;     private Vector2 xy;     public Type GhostType
    {
        get { return m_type; }
        set
        {
            if (m_type == value)
                return;
            m_type = value;             if (graphic != null)
                graphic.SetVerticesDirty();
        }
    } #if UNITY_EDITOR
    protected override void OnValidate()
    {
        xy = this.GetComponent<RectTransform>().sizeDelta;
        base.OnValidate();
        if (graphic != null)
            graphic.SetVerticesDirty();
    }
#endif
    protected override void OnEnable()
    {
        base.OnEnable();
        if (graphic != null)
            graphic.SetVerticesDirty();
        xy = this.GetComponent<RectTransform>().sizeDelta;
        Debug.Log("dfsdf");
    }     public bool useGraphicAlpha
    {
        get { return m_UseGraphicAlpha; }
        set
        {
            m_UseGraphicAlpha = value;
            if (graphic != null)
                graphic.SetVerticesDirty();
        }
    }     protected void ApplyGhostDouble(List<UIVertex> verts, int start, int end, float x1, float y1, float x2, float y2,bool self = false)
    {
        UIVertex vt;         var neededCpacity = verts.Count * ;
        if (verts.Capacity < neededCpacity)
            verts.Capacity = neededCpacity;         for (int i = start; i < end; i++)
        {
            vt = verts[i];
            if(!self)
                verts.Add(vt);//添加一遍mesh             Vector3 v = vt.position;
            int offset = i % ;
            switch (offset)
            {
                case :
                case :
                case : v.x += x1; break;
                case :
                case :
                case : v.x += x2; break;
            }
            switch (offset)
            {
                case :
                case :
                case : v.y += y1; break;
                case :
                case :
                case : v.y += y2; break;
            }             vt.position = v;
            verts[i] = vt;
        }
    }     protected void ApplyGhost(List<UIVertex> verts, int start, int end)
    {
        if (m_type == Type.Double)
        {
            var neededCpacity = verts.Count * ;
            if (verts.Capacity < neededCpacity)
                verts.Capacity = neededCpacity;
            ApplyGhostDouble(verts, start, end, , , -xy.x / ,);
            start = end;
            end = verts.Count;
            ApplyGhostDouble(verts, start, end, xy.x, , -xy.x / , ,true);
        }
        else
        {
            var neededCpacity = verts.Count * ;
            if (verts.Capacity < neededCpacity)
                verts.Capacity = neededCpacity;
            start = ;
            end = verts.Count;
            ApplyGhostDouble(verts, start, end,  , , -xy.x / , xy.y / );
            start = end;
            end = verts.Count;
            ApplyGhostDouble(verts, start, end, xy.x ,, -xy.x / , xy.y / );
            start = end;
            end = verts.Count;
            ApplyGhostDouble(verts, start, end, , -xy.y, -xy.x / , xy.y / );
            start = end;
            end = verts.Count;
            ApplyGhostDouble(verts, start, end, xy.x, -xy.y, -xy.x / , xy.y / , true);
        }
    }     public override void ModifyMesh(VertexHelper vh)
    {
        if (!IsActive())
            return;
        xy = GetComponent<RectTransform>().sizeDelta;         List<UIVertex> output = new List<UIVertex>();
        vh.GetUIVertexStream(output);
        ApplyGhost(output, , output.Count);
        vh.Clear();
        vh.AddUIVertexTriangleStream(output);
    }
}

Unity UGUI 图片 轴对称效果 减少资源的更多相关文章

  1. Unity UGUI在鼠标位置不同时 图片浮动效果

    /// <summary> /// 在鼠标位置不同时 图片浮动效果 /// </summary> public class TiltWindow : MonoBehaviour ...

  2. Unity Shader 效果(1) :图片流光效果

    很多游戏Logo中可以看到这种流光效果,一般的实现方案就是对带有光条的图片uv根据时间进行移动,然后和原图就行叠加实现,不过实现过程中稍稍有点需要注意的地方.之前考虑过风宇冲的实现方式,但是考虑到sh ...

  3. [Unity UGUI]ScrollRect效果大全

    UGUI各种优化效果 本文所实现的UGUI效果需求如下: - 支持缩放滑动效果 - 支持动态缩放循环加载 - 支持大数据固定Item复用加载 - 支持不用Mask遮罩无限循环加载 - 支持Object ...

  4. Unity UGUI图文混排源码(二)

    Unity UGUI图文混排源码(一):http://blog.csdn.net/qq992817263/article/details/51112304 Unity UGUI图文混排源码(二):ht ...

  5. Unity UGUI图文混排源码(一)

    Unity UGUI图文混排源码(一):http://blog.csdn.net/qq992817263/article/details/51112304 Unity UGUI图文混排源码(二):ht ...

  6. Unity UGUI实现图文混排

    目前在unity实现图文混排的好像都是通过自定义字体然后在文本获取字符的位置,用图片替换掉图片标签,这样对于支持英文来说,并没有什么影响.然后对于中文来说就是一个相当麻烦的事了,毕竟图文混排多用于游戏 ...

  7. Unity UGUI Layout自动排版组件用法介绍

    Unity UGUI布局组件 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享 ...

  8. NGUI和UGUI图片字 艺术字(Bitmap图片转文字)制作方法

    用图片字而不是图片 美术和程序的配合,需要程序能够很快抓住问题重点并提出解决方案.美术出的图片字比我们使用的字体更好好看,那么是否要一个个图片去拼成数字呢? NGUI创建图片字 准备材料 美术提供的数 ...

  9. js鼠标滚轮滚动图片切换效果

    效果体验网址:http://keleyi.com/keleyi/phtml/image/12.htm HTML文件代码: <!DOCTYPE html PUBLIC "-//W3C// ...

随机推荐

  1. 7.Vue-Quill-Editor图片插入自定义

    Vue-Quill-Editor图片插入自定义 前言: 因为在项目中前端采用了Vue来实现,正好用到了富文本编辑器这一块,于是,经过技术上的选择,决定使用Vue-Quill-Editor. 使用的过程 ...

  2. TinyMCE(富文本编辑器)在Asp.Net中的使用方法

    TinyMCE(富文本编辑器)在Asp.Net中的使用方法   转至:http://www.cnblogs.com/freeliver54/archive/2013/02/28/2936506.htm ...

  3. js解决异步的方法汇总

    参考:https://www.cnblogs.com/zuobaiquan01/p/8477322.html 一.callback回调函数 回调是一个函数被作为一个参数传递到另一个函数里,在那个函数执 ...

  4. 实践笔记-VA05 销售订单清单 增加字段

    现在都自开发很多报表 ,估计没有多少人 用  VA05 1.在结构 VBMTVZ 中增加需要的字段 2.表t180a 中  添加一条 “添加字段”的数据,如下: 3.取值 修改程序 INCLUDE V ...

  5. oracle调度中使用schedule管理调度

    开始前,先说一句:作为dba应该禁止所有应用使用dbms_job. dbms_scheduler非常复杂,oracle在两本书中专门花费不少章节描述,这两本书分别是: Oracle® Database ...

  6. Sql Server 查看存储过程最后修改时间

    Sql Server 查看存储过程最后修改时间 select * from sys.procedures order by modify_date desc

  7. Python3 operator模块关联代替Python2 cmp() 函数

    Python2 cmp() 函数 描述 cmp(x,y) 函数用于比较2个对象,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1. Python ...

  8. 用bootstrap框架弄的网站。(首页)

    网站的每一处代码都加上注解,以便浏览! 效果图: <!doctype html>   <html lang="zh-cn">   <head> ...

  9. 解决如下出错:DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19.

    背景:在Spyder中写几行脚本,目的是应用sklearn自带的svm(支持向量机)算法,来对其自带的digits(手写体数字)数据集进行分类,过程包括训练阶段和预测阶段.将手写体数字数据的特征数据d ...

  10. R语言绘图:直方图

    使用ggplot2包绘制直方图 ######*****绘制直方图代码*****####### data1 <- data0[(data0[, 2] <= 500) & (data0 ...