unity3d ui maskgui mask 可以改大小吗

&&1using&UnityE&&2using&System.C&&3using&UnityEngine.UI;&&4&&5using&System.Collections.G&&6using&UnityEngine.S&&7&&8namespace&UnityEngine.UI&&9{&10&11&&&&public&class&GuideHighlightMask&:&MaskableGraphic,&UnityEngine.ICanvasRaycastFilter&12&&&&{&13&&&&&&&&public&RectTransform&&14&&&&&&&&public&Vector2&center&=&Vector2.&15&&&&&&&&public&Vector2&size&=&new&Vector2(<span style="color: #0,&<span style="color: #0);&16&17&&&&&&&&public&void&DoUpdate()&18&&&&&&&&{&19&&&&&&&&&&&&//&当引导箭头位置或者大小改变后更新,注意:未处理拉伸模式&20&&&&&&&&&&&&if&(arrow&&&&center&!=&arrow.anchoredPosition&||&size&!=&arrow.sizeDelta)&21&&&&&&&&&&&&{&22&&&&&&&&&&&&&&&&this.center&=&arrow.anchoredP&23&&&&&&&&&&&&&&&&this.size&=&arrow.sizeD&24&&&&&&&&&&&&&&&&SetAllDirty();&25&&&&&&&&&&&&}&26&&&&&&&&}&27&28&&&&&&&&public&bool&IsRaycastLocationValid(Vector2&sp,&Camera&eventCamera)&29&&&&&&&&{&30&&&&&&&&&&&&//&点击在箭头框内部则无效,否则生效&31&&&&&&&&&&&&return&!RectTransformUtility.RectangleContainsScreenPoint(arrow,&sp,&eventCamera);&32&&&&&&&&}&33&34&&&&&&&&protected&override&void&OnFillVBO(List&UIVertex&&vbo)&35&&&&&&&&{&36&&&&&&&&&&&&Vector4&outer&=&new&Vector4(-rectTransform.pivot.x&*&rectTransform.rect.width,&&37&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&-rectTransform.pivot.y&*&rectTransform.rect.height,&38&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&(<span style="color: #&-&rectTransform.pivot.x)&*&rectTransform.rect.width,&39&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&(<span style="color: #&-&rectTransform.pivot.y)&*&rectTransform.rect.height);&40&41&&&&&&&&&&&&Vector4&inner&=&new&Vector4(center.x&-&size.x&/&<span style="color: #,&42&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&center.y&-&size.y&/&<span style="color: #,&43&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&center.x&+&size.x&*&<span style="color: #.5f,&44&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&center.y&+&size.y&*&<span style="color: #.5f);&45&46&&&&&&&&&&&&vbo.Clear();&47&48&&&&&&&&&&&&var&vert&=&UIVertex.simpleV&49&50&&&&&&&&&&&&//&left&51&&&&&&&&&&&&vert.position&=&new&Vector2(outer.x,&outer.y);&52&&&&&&&&&&&&vert.color&=&&53&&&&&&&&&&&&vbo.Add(vert);&54&55&&&&&&&&&&&&vert.position&=&new&Vector2(outer.x,&outer.w);&56&&&&&&&&&&&&vert.color&=&&57&&&&&&&&&&&&vbo.Add(vert);&58&59&&&&&&&&&&&&vert.position&=&new&Vector2(inner.x,&outer.w);&60&&&&&&&&&&&&vert.color&=&&61&&&&&&&&&&&&vbo.Add(vert);&62&63&&&&&&&&&&&&vert.position&=&new&Vector2(inner.x,&outer.y);&64&&&&&&&&&&&&vert.color&=&&65&&&&&&&&&&&&vbo.Add(vert);&66&67&&&&&&&&&&&&//&top&68&&&&&&&&&&&&vert.position&=&new&Vector2(inner.x,&inner.w);&69&&&&&&&&&&&&vert.color&=&&70&&&&&&&&&&&&vbo.Add(vert);&71&72&&&&&&&&&&&&vert.position&=&new&Vector2(inner.x,&outer.w);&73&&&&&&&&&&&&vert.color&=&&74&&&&&&&&&&&&vbo.Add(vert);&75&76&&&&&&&&&&&&vert.position&=&new&Vector2(inner.z,&outer.w);&77&&&&&&&&&&&&vert.color&=&&78&&&&&&&&&&&&vbo.Add(vert);&79&80&&&&&&&&&&&&vert.position&=&new&Vector2(inner.z,&inner.w);&81&&&&&&&&&&&&vert.color&=&&82&&&&&&&&&&&&vbo.Add(vert);&83&84&&&&&&&&&&&&//&right&85&&&&&&&&&&&&vert.position&=&new&Vector2(inner.z,&outer.y);&86&&&&&&&&&&&&vert.color&=&&87&&&&&&&&&&&&vbo.Add(vert);&88&89&&&&&&&&&&&&vert.position&=&new&Vector2(inner.z,&outer.w);&90&&&&&&&&&&&&vert.color&=&&91&&&&&&&&&&&&vbo.Add(vert);&92&93&&&&&&&&&&&&vert.position&=&new&Vector2(outer.z,&outer.w);&94&&&&&&&&&&&&vert.color&=&&95&&&&&&&&&&&&vbo.Add(vert);&96&97&&&&&&&&&&&&vert.position&=&new&Vector2(outer.z,&outer.y);&98&&&&&&&&&&&&vert.color&=&&99&&&&&&&&&&&&vbo.Add(vert);<span style="color: #0<span style="color: #1&&&&&&&&&&&&//&bottom<span style="color: #2&&&&&&&&&&&&vert.position&=&new&Vector2(inner.x,&outer.y);<span style="color: #3&&&&&&&&&&&&vert.color&=&<span style="color: #4&&&&&&&&&&&&vbo.Add(vert);<span style="color: #5<span style="color: #6&&&&&&&&&&&&vert.position&=&new&Vector2(inner.x,&inner.y);<span style="color: #7&&&&&&&&&&&&vert.color&=&<span style="color: #8&&&&&&&&&&&&vbo.Add(vert);<span style="color: #9<span style="color: #0&&&&&&&&&&&&vert.position&=&new&Vector2(inner.z,&inner.y);<span style="color: #1&&&&&&&&&&&&vert.color&=&<span style="color: #2&&&&&&&&&&&&vbo.Add(vert);<span style="color: #3<span style="color: #4&&&&&&&&&&&&vert.position&=&new&Vector2(inner.z,&outer.y);<span style="color: #5&&&&&&&&&&&&vert.color&=&<span style="color: #6&&&&&&&&&&&&vbo.Add(vert);<span style="color: #7&&&&&&&&}<span style="color: #8<span style="color: #9&&&&&&&&private&void&Update()<span style="color: #0&&&&&&&&{<span style="color: #1&&&&&&&&&&&&DoUpdate();<span style="color: #2&&&&&&&&}<span style="color: #3&&&&}<span style="color: #4}<span style="color: #5
&re: [Unity3D]UGUI 新手引导遮罩控件&&&&
这个没试过,当前版本用的5.01,不过原理应该差不多哦
阅读排行榜
评论排行榜【技术贴】关于UGUI中修改Text的字间距【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:71,219贴子:
【技术贴】关于UGUI中修改Text的字间距收藏
令人非常遗憾,UGUI的Text只能设置行间距,却不能调整相邻字之间的间距。为了解决这个问题,我研究了一下源码,然后直接晕了,搜索了一下,发现国外有几个大神解决了这个问题。国内貌似还没有相关资料,所以我在这里说一下。
达内unity3d培训全程&实战教学&,unity3d金牌讲师授课.免费unity3d课程试听中!到达内unity3d学院学习unity3d,只需4个月速成unity3d游戏工程师.
解决方案一如果是Bitmap字体,修改它的参数问题是不适用于所有字体,且不能灵活调整多个Text的情况。
解决方案二LetterSpacing.cs原理:在ModifyVertices函数里改变Text里各个顶点的位置(可参考UI源码里的Shadow脚本)using UnityEusing System.Cusing System.Collections.Gnamespace UnityEngine.UI{
[AddComponentMenu(&UI/Effects/Letter Spacing&, 14)]
public class LetterSpacing : BaseVertexEffect
[SerializeField]
private float m_spacing = 0f;
protected LetterSpacing() { }
#if UNITY_EDITOR
protected override void OnValidate()
spacing = m_
base.OnValidate();
public float spacing
get { return m_ }
if (m_spacing == value)
m_spacing =
if (graphic != null) graphic.SetVerticesDirty();
public override void ModifyVertices(List&UIVertex& verts)
if (! IsActive())
Text text = GetComponent&Text&();
if (text == null)
Debug.LogWarning(&LetterSpacing: Missing Text component&);
string[] lines = text.text.Split(&#39;\n&#39;);
letterOffset
= spacing * (float)text.fontSize / 100f;
alignmentFactor = 0;
switch (text.alignment)
case TextAnchor.LowerLeft:
case TextAnchor.MiddleLeft:
case TextAnchor.UpperLeft:
alignmentFactor = 0f;
case TextAnchor.LowerCenter:
case TextAnchor.MiddleCenter:
case TextAnchor.UpperCenter:
alignmentFactor = 0.5f;
case TextAnchor.LowerRight:
case TextAnchor.MiddleRight:
case TextAnchor.UpperRight:
alignmentFactor = 1f;
for (int lineIdx=0; lineIdx & lines.L lineIdx++)
string line = lines[lineIdx];
float lineOffset = (line.Length -1) * letterOffset * alignmentF
for (int charIdx = 0; charIdx & line.L charIdx++)
int idx1 = glyphIdx * 4 + 0;
int idx2 = glyphIdx * 4 + 1;
int idx3 = glyphIdx * 4 + 2;
int idx4 = glyphIdx * 4 + 3;
// Check for truncated text (doesn&#39;t generate verts for all characters)
if (idx4 & verts.Count - 1)
UIVertex vert1 = verts[idx1];
UIVertex vert2 = verts[idx2];
UIVertex vert3 = verts[idx3];
UIVertex vert4 = verts[idx4];
pos = Vector3.right * (letterOffset * charIdx - lineOffset);
vert1.position +=
vert2.position +=
vert3.position +=
vert4.position +=
verts[idx1] = vert1;
verts[idx2] = vert2;
verts[idx3] = vert3;
verts[idx4] = vert4;
glyphIdx++;
// Offset for carriage return character that still generates verts
glyphIdx++;
另外该脚本的作者注释了几点注意事项——/*Produces an simple tracking/letter-spacing effect on UI Text components.Set the spacing parameter to adjust letter spacing.
Negative values cuddle the text up tighter than normal. Go too far and it&#39;ll look odd.
Positive values spread the text out more than normal. This will NOT respect the text area you&#39;ve defined.
Zero spacing will present the font with no changes.Relies on counting off characters in your Text compoennt&#39;s text property andmatching those against the quads passed in via the verts array. This is reallyrather primitive, but I can&#39;t see any better way at the moment. It means thatall sorts of things can break the effect...This component should be placed higher in component list than any other vertexmodifiers that alter the total number of verticies. Eg, place this above Shadowor Outline effects. If you don&#39;t, the outline/shadow won&#39;t match the positionof the letters properly. If you place the outline/shadow effect second however,it will just work on the altered vertices from this component, and functionas expected.This component works best if you don&#39;t allow text to automatically wrap. It alsoblows up outside of the given text area. Basically, it&#39;s a cheap and dirty effect,not a clever text layout engine. It can&#39;t affect how Unity chooses to break upyour lines. If you manually use line breaks however, it should detect those andfunction more or less as you&#39;d expect.The spacing parameter is measured in pixels multiplied by the font size. This waschosen such that when you adjust the font size, it does not change the visual spacingthat you&#39;ve dialed in. There&#39;s also a scale factor of 1/100 in this number tobring it into a comfortable adjustable range. There&#39;s no limit on this parameter,but obviously some values will look quite strange.This component doesn&#39;t really work with Rich Text. You don&#39;t need to remember toturn off Rich Text via the checkbox, but because it can&#39;t see what makes aprintable character and what doesn&#39;t, it will typically miscount characters when youuse HTML-like tags in your text. Try it out, you&#39;ll see what I mean. It doesn&#39;tbreak down entirely, but it doesn&#39;t really do what you&#39;d want either.*/
我总结翻译如下——1.放在Shadow和Outline的上面,否则只改变部分效果2.字间距的调整无视Horizontal Overflow-Wrap的限制,所以最好调为Overflow3.当调整字体大小时,字间距也会调整,因而你设置的视觉上效果不变letterOffset
= spacing * text.fontSize / 100f;spacing是几,就表示字间距为当前字号的百分之几。4.不兼容RichText,但也不用在Editor里取消勾选RichText,因为html格式会自动不被识别5.方法很原始,效果很粗糙
解决方案三商店里有个叫Kerned Text for Unity UI的插件,直接继承Text进行修改,貌似解决得非常完美,哪位土豪买一下传播一下啊!!!
你是在哪里看国外贴的
解决方案四把字拆成一个一个text 然后想怎么控就怎么空
直接打空格...
更新到5.2.0 f3后发现构成每个字的顶点数从4升到了6,小小地修改了一下LetterSpacing的代码(好像还处理了一些简单的报错)——using UnityEusing System.Cusing System.Collections.Gusing UnityEngine.UI;[AddComponentMenu(&UI/Effects/Letter Spacing&, 14)]public class LetterSpacing : BaseMeshEffect{[SerializeField]private float m_spacing = 0f;protected LetterSpacing() { }#if UNITY_EDITORprotected override void OnValidate(){spacing = m_base.OnValidate();}#endifpublic float spacing{get { return m_ }set{if (m_spacing == value)m_spacing =if (graphic != null) graphic.SetVerticesDirty();}}public override void ModifyMesh(Mesh mesh){
List&UIVertex& verts = new List&UIVertex&();
using (var helper = new VertexHelper(mesh))
helper.GetUIVertexStream(verts);
if (!IsActive())Text text = GetComponent&Text&();if (text == null){Debug.LogWarning(&LetterSpacing: Missing Text component&);}string[] lines = text.text.Split(&#39;\n&#39;);Vector3float
letterOffset
= spacing * (float)text.fontSize / 100f;float
alignmentFactor = 0;int
= 0;switch (text.alignment){case TextAnchor.LowerLeft:case TextAnchor.MiddleLeft:case TextAnchor.UpperLeft:alignmentFactor = 0f;case TextAnchor.LowerCenter:case TextAnchor.MiddleCenter:case TextAnchor.UpperCenter:alignmentFactor = 0.5f;case TextAnchor.LowerRight:case TextAnchor.MiddleRight:case TextAnchor.UpperRight:alignmentFactor = 1f;}
for (int lineIdx=0; lineIdx & lines.L lineIdx++){string line = lines[lineIdx];float lineOffset = (line.Length -1) * letterOffset * alignmentFfor (int charIdx = 0; charIdx & line.L charIdx++){int idx1 = glyphIdx * 6 + 0;int idx2 = glyphIdx * 6 + 1;int idx3 = glyphIdx * 6 + 2;int idx4 = glyphIdx * 6 + 3;
int idx5 = glyphIdx * 6 + 4;
int idx6 = glyphIdx * 6 + 5;
// Check for truncated text (doesn&#39;t generate verts for all characters)
if (idx4 & verts.Count - 1)UIVertex vert1 = verts[idx1];UIVertex vert2 = verts[idx2];UIVertex vert3 = verts[idx3];UIVertex vert4 = verts[idx4];
UIVertex vert5 = verts[idx5];
UIVertex vert6 = verts[idx6];
pos = Vector3.right * (letterOffset * charIdx - lineOffset);vert1.position +=vert2.position +=vert3.position +=vert4.position +=
vert5.position +=
vert6.position +=
verts[idx1] = vert1;verts[idx2] = vert2;verts[idx3] = vert3;verts[idx4] = vert4;
verts[idx5] = vert5;
verts[idx6] = vert6;
glyphIdx++;}// Offset for carriage return character that still generates vertsglyphIdx++;}
using (var helper = new VertexHelper())
helper.AddUIVertexTriangleStream(verts);
helper.FillMesh(mesh);
unity3d千锋VR培训0元入学,「高薪」就业!「预约申请2周免费试学」.火爆预约中!千锋VR培训,招生限大专以上学历,年龄30岁以下,符合条件即可报名,入学即签订就业协议!
`UnityEngine.UI.LetterSpacing&#39; does not implement inherited abstract member `UnityEngine.UI.BaseMeshEffect.ModifyMesh(UnityEngine.UI.VertexHelper)&#39;
UGUI ?? ?? ???, ??? ? ? ??? ??? ? ?? UNITU3D ????? ????
Assets/LuaFramework/SelfScripts/UGUIHelp/Text/LetterSpacing.cs(8,14): error CS0534: `LetterSpacing&#39; does not implement inherited abstract member `UnityEngine.UI.BaseMeshEffect.ModifyMesh(UnityEngine.UI.VertexHelper)&#39;
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或程序写累了,就来玩玩酷跑小游戏吧,嘿嘿。
雨松MOMO送你一首歌曲,嘿嘿。
UGUI研究院之全面理解图集与使用(三)
UGUI研究院之全面理解图集与使用(三)
围观110452次
编辑日期: 字体:
UGUI的图集打包与工作原理,整整看了一天多,终于看明白了~晕~还是记录一下我研究的成果,也希望大家在下面给我留言我们一起讨论一下。
先说说UGUI的Atlas和NGUI的Atlas的区别,NGUI是必须先打出图集然后才能开始做界面。这一点很烦,因为始终都要去考虑你的UI图集。比如图集会不会超1024 ,图集该如何来规划等等。而UGUI的原理则是,让开发者彻底模糊图集的概念,让开发者不要去关心自己的图集。做界面的时候只用小图,而在最终打包的时候unity才会把你的小图和并在一张大的图集里面。然而这一切一切都是自动完成的,开发者不需要去care它。
如下图所示,Editor-&Project Settings 下面有sprite packer的模式。Disabled表示不启用它,Enabled For Builds 表示只有打包的时候才会启用它,Always Enabled 表示永远启用它。 这里的启用它就表示是否将小图自动打成图集。
我的选项是Always Enabled 。因为开发的时候我们需要清楚的看到现在是几个Draw Call,从而才能优化小图。在最终打包的时候unity会自动构建大的图集,可是我开发的时候就想看图集会占几个Draw Call,这怎么办呢?如下图所示,首先将你的图片拖入unity中,将同一图集的所有图片的packing tag设置成一个名子即可。
注意你的图片不能放在Resources文件夹下面,Resources文件夹下的资源将不会被打入图集,切记(也就是在这里混淆了我很久)。然后在Windows-&Sprite Packer 里,点击packer 在这里你就可以预览到你的图集信息。图集的大小还有图集的格式等等很多参数我们都是可以控制的,也可以通过脚本来设置。我在下一篇文章里详细说这个(请期待嘿嘿)。
图集的预览紧紧是让你看看你的图集大概张什么样子。那么我们的图集的这张图片保存在了哪里呢?它保存在和Assets文件夹同级的目录,Libary/AtlasCache里面。你不用管它,也不要删除它,就算你删除了也没用因为只要你打包,它就会生成并且会打到包中。
此时在Hierarchy视图中创建两个Image对象。如下图所示,我们可以清楚的看到此时我的draw call已经被合并成了1 。
这两个图片是我是在Editor模式下预先拖入Hierarchy视图中的,可是如果我想运行时根据图片的名子来动态创建精灵该如何?可是unity根本没有提供加载图集的方法,也没有提供加载图集上某个图片的方法。 因为UGUI就不像让开发者有图集的这个概念,可是我们肯定是要实现这个需求的。。怎么办呢?
第一个设想,先把散=小图打包成图集,然后再把所有散图拷贝在Resources文件夹下,这样运行时就能用Resources.load了。
第二个设想,还是先把小图打成图集,然后把所有小图关联在prefab上,拷贝在Resources文件夹下,这样运行时也能用Resources.load了。到底那个靠谱呢? 给大家看一个图大家就知道答案了。
如下图所示,打成图集的图片如果在放在Resources那么资源就变成双份了。。 所以我们只能把小图关联在Prefab上,把所有的Prefab放在Resources下面,这样就不占用多余的空间了。
好了,现在方法我们已经掌握,那么就开始写工具吧。如下图所示可以按文件夹分,每一个文件夹就是一个图集。然后每一张小图创建一个Prefab,Prefab的名子就起小图的名子,文件关联在Resources下面。
代码比较简单,我就不注释了。
123456789101112131415161718192021222324
[MenuItem ("MyMenu/AtlasMaker")] static private void MakeAtlas() {
string spriteDir = Application.dataPath +"/Resources/Sprite";
if(!Directory.Exists(spriteDir)){
Directory.CreateDirectory(spriteDir);
DirectoryInfo rootDirInfo = new DirectoryInfo (Application.dataPath +"/Atlas");
foreach (DirectoryInfo dirInfo in rootDirInfo.GetDirectories()) {
foreach (FileInfo pngFile in dirInfo.GetFiles("*.png",SearchOption.AllDirectories)) {
string allPath = pngFile.FullName;
string assetPath = allPath.Substring(allPath.IndexOf("Assets"));
Sprite sprite = Resources.LoadAssetAtPath&Sprite&(assetPath);
GameObject go = new GameObject(sprite.name);
go.AddComponent&SpriteRenderer&().sprite = sprite;
allPath = spriteDir+"/"+sprite.name+".prefab";
string prefabPath = allPath.Substring(allPath.IndexOf("Assets"));
PrefabUtility.CreatePrefab(prefabPath,go);
GameObject.DestroyImmediate(go);
然后是运行时的代码。
123456789101112131415161718192021222324252627
using UnityEngine;using System.Collections;using UnityEngine.UI;&public class UIMain : MonoBehaviour {& void Start ()
CreatImage(loadSprite("image0"));
CreatImage(loadSprite("image1")); }& private void CreatImage(Sprite sprite ){
GameObject go = new GameObject(sprite.name);
go.layer = LayerMask.NameToLayer("UI");
go.transform.parent = transform;
go.transform.localScale= Vector3.one;
Image image = go.AddComponent&Image&();
image.sprite = sprite;
image.SetNativeSize(); }& private Sprite loadSprite(string spriteName){
return Resources.Load&GameObject&("Sprite/" + spriteName).GetComponent&SpriteRenderer&().sprite; }&}
因为这两个图是在同一个图集上,所以drawcall就是1了。这样我们就可以根据图片的名子来运行时加载图片了。
接下来就是Assetbundle了,如果我们的图集需要在线更新那该怎么办呢? 其实Assetbundle比Resources要更简单一些,无论如何我们要先开始打图集。
12345678910111213141516171819202122232425262728293031323334
[MenuItem ("MyMenu/Build Assetbundle")] static private void BuildAssetBundle() {
string dir = Application.dataPath +"/StreamingAssets";&
if(!Directory.Exists(dir)){
Directory.CreateDirectory(dir);
DirectoryInfo rootDirInfo = new DirectoryInfo (Application.dataPath +"/Atlas");
foreach (DirectoryInfo dirInfo in rootDirInfo.GetDirectories()) {
List&Sprite& assets = new List&Sprite&();
string path = dir +"/"+dirInfo.Name+".assetbundle";
foreach (FileInfo pngFile in dirInfo.GetFiles("*.png",SearchOption.AllDirectories))
string allPath = pngFile.FullName;
string assetPath = allPath.Substring(allPath.IndexOf("Assets"));
assets.Add(Resources.LoadAssetAtPath&Sprite&(assetPath));
if(BuildPipeline.BuildAssetBundle(null, assets.ToArray(), path,BuildAssetBundleOptions.UncompressedAssetBundle| BuildAssetBundleOptions.CollectDependencies, GetBuildTarget())){
static private BuildTarget GetBuildTarget()
BuildTarget target = BuildTarget.WebPlayer;#if UNITY_STANDALONE
target = BuildTarget.StandaloneWindows;#elif UNITY_IPHONE
target = BuildTarget.iPhone;#elif UNITY_ANDROID
target = BuildTarget.Android;#endif
return target;
如下图所示,我的assetbundle已经打出来了。
然后把UIMain.cs在改一改。
12345678910111213141516171819202122232425262728293031323334
using UnityEngine;using System.Collections;using UnityEngine.UI;&public class UIMain : MonoBehaviour {& AssetBundle assetbundle = null; void Start ()
CreatImage(loadSprite("image0"));
CreatImage(loadSprite("image1")); }& private void CreatImage(Sprite sprite ){
GameObject go = new GameObject(sprite.name);
go.layer = LayerMask.NameToLayer("UI");
go.transform.parent = transform;
go.transform.localScale= Vector3.one;
Image image = go.AddComponent&Image&();
image.sprite = sprite;
image.SetNativeSize(); }& private Sprite loadSprite(string spriteName){#if USE_ASSETBUNDLE
if(assetbundle == null)
assetbundle = AssetBundle.CreateFromFile(Application.streamingAssetsPath +"/Main.assetbundle");
return assetbundle.Load(spriteName) as Sprite;#else
return Resources.Load&GameObject&("Sprite/" + spriteName).GetComponent&SpriteRenderer&().sprite;#endif
如下图所示,依然还是一个drawcall。
衷心希望有经验的朋友在留言处给我提提意见, 或者大家一起讨论讨论。。 我们共同为把NGUI干掉的目标而奋斗,嘻嘻。
本文固定链接:
转载请注明:
雨松MOMO提醒您:亲,如果您觉得本文不错,快快将这篇文章分享出去吧 。另外请点击网站顶部彩色广告或者捐赠支持本站发展,谢谢!
作者:雨松MOMO
专注移动互联网,Unity3D游戏开发
如果您愿意花10块钱请我喝一杯咖啡的话,请用手机扫描二维码即可通过支付宝直接向我捐款哦。
您可能还会对这些文章感兴趣!}

我要回帖

更多关于 unity3d shader mask 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信