Unity UGUI 图片 轴对称效果 减少资源
制作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 图片 轴对称效果 减少资源的更多相关文章
- Unity UGUI在鼠标位置不同时 图片浮动效果
/// <summary> /// 在鼠标位置不同时 图片浮动效果 /// </summary> public class TiltWindow : MonoBehaviour ...
- Unity Shader 效果(1) :图片流光效果
很多游戏Logo中可以看到这种流光效果,一般的实现方案就是对带有光条的图片uv根据时间进行移动,然后和原图就行叠加实现,不过实现过程中稍稍有点需要注意的地方.之前考虑过风宇冲的实现方式,但是考虑到sh ...
- [Unity UGUI]ScrollRect效果大全
UGUI各种优化效果 本文所实现的UGUI效果需求如下: - 支持缩放滑动效果 - 支持动态缩放循环加载 - 支持大数据固定Item复用加载 - 支持不用Mask遮罩无限循环加载 - 支持Object ...
- Unity UGUI图文混排源码(二)
Unity UGUI图文混排源码(一):http://blog.csdn.net/qq992817263/article/details/51112304 Unity UGUI图文混排源码(二):ht ...
- Unity UGUI图文混排源码(一)
Unity UGUI图文混排源码(一):http://blog.csdn.net/qq992817263/article/details/51112304 Unity UGUI图文混排源码(二):ht ...
- Unity UGUI实现图文混排
目前在unity实现图文混排的好像都是通过自定义字体然后在文本获取字符的位置,用图片替换掉图片标签,这样对于支持英文来说,并没有什么影响.然后对于中文来说就是一个相当麻烦的事了,毕竟图文混排多用于游戏 ...
- Unity UGUI Layout自动排版组件用法介绍
Unity UGUI布局组件 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享 ...
- NGUI和UGUI图片字 艺术字(Bitmap图片转文字)制作方法
用图片字而不是图片 美术和程序的配合,需要程序能够很快抓住问题重点并提出解决方案.美术出的图片字比我们使用的字体更好好看,那么是否要一个个图片去拼成数字呢? NGUI创建图片字 准备材料 美术提供的数 ...
- js鼠标滚轮滚动图片切换效果
效果体验网址:http://keleyi.com/keleyi/phtml/image/12.htm HTML文件代码: <!DOCTYPE html PUBLIC "-//W3C// ...
随机推荐
- js使用hover事件做一个“个人中心”的浮动层
原材料知识点:hover html: css:
- CSS&JS定位器
一.CssSelector定位器 1.概述 CssSelector是效率很高的元素定位方法,Selenium官网的Document里极力推荐使用CSS locator,而不是XPath来定位元素,原因 ...
- UDP端口启动后一段时间无法接收到数据
接口需求:开发一个UDP协议的接口作为服务端接收来自客户端的认证数据,数据量每分钟7w+条; 数据格式:标准的redius协议,redius协议的相关知识在网上查资料,提供线索:http://blog ...
- django-基于中间件实现限制ip频繁访问
########django-基于中间件写一个限制频繁登陆######## 额额,标题已经很醒目了,通过中间件去实现,其他方法也可以实现 浏览器前端传来的请求,必须通过中间件,才能到后面路由,视图函数 ...
- zepto 基础知识(2)
20.append append(content) 类型:self 在每个匹配的元素末尾插入内容(内部插入).内容可以为html 字符串.dom节点,或者节点组成的数组. $('ul').append ...
- 邮件发送失败问题:Sending the email to the following server failed : smtp.qiye.163.com:25
[邮件发送错误] : Sending the email to the following server failed : smtp.qiye.163.com:25, {}org.apache.com ...
- 几种常用的git命令
1.合并代码出现冲突,用git status 查看冲突所在的文件 2. clone 指定分支分支的文件夹 git clone -b **** ***; 3.git merge 和 git rebase ...
- mongodb的高级查询
db的帮助文档 输入:db.help(); db.AddUser(username,password[, readOnly=false]) 添加用户 db.auth(usrename,passwor ...
- Java源码解析——集合框架(五)——HashMap源码分析
HashMap源码分析 HashMap的底层实现是面试中问到最多的,其原理也更加复杂,涉及的知识也越多,在项目中的使用也最多.因此清晰分析出其底层源码对于深刻理解其实现有重要的意义,jdk1.8之后其 ...
- Git----将本地代码推送到远程仓库
1.初始化本地 git init 2.添加文件 -A等于 -. 和-a的集合 git add -A 3.提交 git commit -m 'add' 4.关联到远程库 git remote add o ...