Unity
开发过程中实用的Unity功能
时无言
如果有什么技术问题请在评论中留言,一起学习,一起研究,一起进步。
——路漫漫其修远兮,吾将上下而求索
展开
-
多层拼接遮罩
多物体组合遮罩,被遮罩物体和遮罩物体没有层级关系原创 2022-12-22 18:27:16 · 177 阅读 · 1 评论 -
unity 多颜色自定义融合
unity 多颜色自定义融合原创 2022-10-09 10:47:01 · 1506 阅读 · 0 评论 -
atlas.GetSprite(name)内存泄露
Unity 内存泄露 有Mono代码内存GfxDriver资源内存GC.Collect() 代码垃圾回收Resources.UnloadUnusedAssets()资源垃圾回收Resources.UnloadAsset()资源回收但是UGUI中使用图集频繁获取切换图片atlas.GetSprite(name)克隆出的资源不会自动卸载所以已获取过的图片不要再使用这个方法获取了我这里使用字典存了一下 Dictionary<string, Sprite> Loc...原创 2021-08-27 15:15:25 · 911 阅读 · 0 评论 -
unity 坐标之间的转换
public static Bounds CalculateRelativeRectTransformBounds(Transform root, Transform child); public static Bounds CalculateRelativeRectTransformBounds(Transform trans); // // 摘要: // Flips the horizontal and vertical axe..原创 2021-08-02 09:51:54 · 366 阅读 · 0 评论 -
Unity 使用字符串调用方法
在项目开发中有时候在同一个地方需要调用不同类中的不同方法这时候需要使用字符串来找到物体身上挂载的类使用非静态方法,或直接类中的静态方法 string className = "className"; string funName = "OnRaycastHit"; var sheep = go.GetComponent(className); MethodInfo mi = sheep.GetType().GetMethod(funName);原创 2021-08-02 09:46:54 · 748 阅读 · 0 评论 -
unity 跟随手指摇杆
在手指按下的地方using UnityEngine;using UnityEngine.EventSystems;public class JoyStick : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler{ /// <summary> /// 摇杆最大半径 /// 以像素为单位 /// </summary> private float Jo原创 2021-07-29 10:05:44 · 384 阅读 · 0 评论 -
UnityUGUIText根据内容自适应(滑动框、图标跟随)
一.icon图标跟随在文字前面随文本长短而移动位置1.Text组件GameObject添加Content Size Fitter组件控制文本框大小随内容而变化2.把图标放到子物体位置,Rect Transform 中的Pivot设置为1,0.5调整好位置即可3.上、下或者右边同理。文本扩展方向以及位置通过改变和Rect Transform 中的Pivot设置二.Scroll View滑动框大小随文字改变比如竖直排列1.文本框上添加Content Size Fitter..原创 2021-07-22 16:11:47 · 2296 阅读 · 2 评论 -
shader后处理:伸手不见五指的浓雾或者相机聚焦效果
想要做一种能见度很低的不会飘动浓雾效果,unity自带的体积雾不行,就想到对比深度来进行渲染实现想要的效果后加上高斯模糊就变成了相机的聚焦效果shader中blur = tex2D(_BlurTex, i.uv) C#中/*-----*/注释部分放开就是相机景深效果其中fixed4 blur = /*tex2D(_BlurTex, i.uv)*/_fog_color;中 如果blur = tex2D(_BlurTex, i.uv)就是相机景深效果,blur = _fog_color 就是浓雾效果原创 2021-05-27 11:36:11 · 660 阅读 · 0 评论 -
快速对不同平台设置自定义宏
工具的使用另外下面的输入框输入另外的宏以“,”隔开代码public class SettingWindows : EditorWindow{ private List<MacroItem> macroItemLists = new List<MacroItem>(); private Dictionary<string, bool> dic = new Dictionary<string, bool>(); priv原创 2021-05-27 11:07:50 · 239 阅读 · 0 评论 -
unity WebGL 在移动端浏览器全屏自适应Build模板
<meta name="viewport" content="width=device-width,initial-scale=1.0">content属性值 : width:可视区域的宽度,值可为数字或关键词device-width height:同width intial-scale:页面首次被显示是可视区域的缩放级别,取值1.0则页面按实际尺寸显示,无任何缩放 maximum-scale=1.0, minimum-scale=1....原创 2021-05-27 10:19:49 · 3665 阅读 · 14 评论 -
科大讯飞语音评测+录音
1.调用录音设备保存录音using System;using System.Collections;using System.Collections.Generic;using System.IO;using UnityEngine;using UnityEngine.UI;public class MicroPhoneManager : MonoBehaviour{ public int DeviceLength; private void Awake原创 2020-08-18 11:18:57 · 5823 阅读 · 5 评论 -
科大讯飞 语音评测 流式版鉴权
public static string getAuthUrl(string hostUrl, string apiKey, string apiSecret) { Uri uri = new Uri(hostUrl); TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string date = DateTime.UtcNow..原创 2020-08-13 12:49:06 · 980 阅读 · 0 评论 -
Unity高版本使用string添加组件-调用方法
由于之前的AddComponent(string name)过时了,使用AddComponent(System.Type t)Type t = Type.GetType(“CustomClassName”);var asmb = System.Reflection.Assembly.Load(assembly);Type t = asmb.GetType(assembly + "." + classname); 如果是系统的类的话,比如Button什么的,系统函数的命名空间分的很...原创 2020-05-28 17:17:04 · 600 阅读 · 0 评论 -
Unity 开发——标签
1、ExecuteInEditModeExecuteInEditMode属性的作用是在EditMode下也可以执行脚本。Unity中默认情况下,脚本只有在运行的时候才被执行,加上此属性后,不运行程序,也能执行脚本。与PlayMode不同的是,函数并不会不停的执行。Update : 只有当场景中的某个物体发生变化时,才调用。OnGUI : 当GameView接收到一个Event时才调用。OnRenderObject 和其他的渲染回调函数 : SceneVidw或者GameView重绘时,调原创 2020-05-26 10:00:16 · 291 阅读 · 0 评论