随笔分类 - Unity / Unity-UGUI
摘要:var rtf = GetComponent<RectTransform>(); rtf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200); SetSizeWithCurrentAnchors不会改变anchorMin和anc
阅读全文
摘要:最终效果 代码 using System.Collections; using UnityEngine; using UnityEngine.UI; [DisallowMultipleComponent] [RequireComponent(typeof(CanvasRenderer))] [Req
阅读全文
摘要:3d部分使用MeshRenderer来渲染,ugui的渲染均使用CanvasRenderer。 如何渲染出来呢?只需要把顶点,材质,贴图设置给CanvasRenderer,就能渲染出来了。 下面的代码,我们直接使用CanvasRenderer来进行渲染,等同于Graphic渲染部分的核心代码。 us
阅读全文
摘要:效果 原理:就是将原有区域分割成围绕中心0的多个三角形 using UnityEngine; using UnityEngine.Sprites; using UnityEngine.UI; [RequireComponent(typeof(Image))] public class Polygon
阅读全文
摘要:主要涉及到的类 看到最多的就是EventSystem这个自动添加的GameObject 代码阅读要点 1) 事件系统做了什么? 在Update中不断的检测这一帧发生的输入事件,并根据输入事件解析出当前在进行的操作。 所以,所有的逻辑都是在EventSystem.Update中发生的。Standalo
阅读全文
摘要:主要的代码: public static readonly Vector2[] s_VertScratch = new Vector2[4]; public static readonly Vector2[] s_UVScratch = new Vector2[4]; private void Ge
阅读全文
摘要:#if UNITY_EDITOR using System; using System.IO; using UnityEditor; using UnityEngine; public static class SpriteTool { // OpenDirAfterExport const str
阅读全文
摘要:最终效果,左侧为ugui的,右侧为自己实现的 using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MyText : Graphic { public Font m_Font;
阅读全文
摘要:效果,左侧为ugui的,右侧为自己实现的 using UnityEngine; using UnityEngine.UI; public class MyText : Graphic { public Font m_Font; public string m_Text = ""; public in
阅读全文
摘要:最终效果 就简简单单一个利用Font把文本渲染出来 using UnityEngine; using UnityEngine.UI; public class MyText : Graphic { public Font m_Font; public string m_Text = "Hellow
阅读全文
摘要:Dynamic字符 1) ttf字体默认是Dynamic的,就是用到什么字符,运行时渲染对应的字符到字体贴图上 比如:Text组件上的New Text,在运行起来后字体贴图就渲染了NewText上去 2) 使用Font.GetCharacterInfo来获取字符信息 //不传fontSize参数,
阅读全文
摘要:最终效果 1) fnt文件上右击,执行命令 2) 空白位置右击,打开工具窗口生成fontsettings文件。 或者从菜单 -> Assets -> BMFont -> open BMFontTool打开 字体渲染中的几个术语 1) baseline, ascent, descent, Charac
阅读全文
摘要:Font Settings 这边就是outline建议设为0(也就是关掉),这个在Unity中支持不是很好,而且BMFont生成的描边效果也很差。 Export Options padding和spacing建议不要使用0,可以减少边缘的毛糙效果。(下面第1张设置用的0,第2张用的2)
阅读全文
摘要:用于解析BMFont软件生成的fnt文件 using System; using System.Collections.Generic; using System.Text.RegularExpressions; using UnityEngine; public class FntParse {
阅读全文
摘要:BMFont下载地址:BMFont - AngelCode.com Font Settings上的参数与fnt文件中的对应关系 Export Options上的参数与fnt文件中的对应关系 fnt文件中各字段的意义 face对应字体 size字体大小, 一般就是默认行高 bold粗体 italic斜
阅读全文
摘要:主要改动以下几个地方: 1) 考虑下面的几个使用场景: a) 有多个功能页签,某个页签要玩家等级10级才可以切换过去,不满10级的时候,点击该页签提示:10级后开启 不可ToggleOn b) 合成道具的时候,最多勾选4个道具,选择第5个时,不能勾选上,且提示:最多选择4个道具 不可ToggleOn
阅读全文
摘要:官方的ugui源代码地址:GitHub - Unity-Technologies/uGUI at 2018.4 我的加了注释辅助自己理解的仓库:https://gitee.com/CodeRead/ugui-2018-src 这边是在Unity2018.4.35下阅读调试UGUI代码 1) 屏蔽内置
阅读全文
摘要:不带特效模型 1) 使用一个单独的Camera对准3d模型,Camera的结果输出到RenderTexture上 这边新建了一张512x512的RenderTexture 2) ugui使用RawImage显示该RenderTexture 上面存在2个问题: 1) RawImage把相机的白色背景也
阅读全文
摘要:裁剪区域计算涉及的几种情况 1) 只有一个RectMask2D时,裁剪区域就是RectMask2D所在的区域 2) RectMask2D嵌套RectMask2D时: a) RectMask2D(红色)的祖先节点中没有RectMask2D了,所以裁剪区域就是自己所在的矩形区域。 b) RectMask
阅读全文