选自过去1~2周的内容: https://twitter.com/unity3d 和各种其他来源吧
1)、 Unity的库: 2D PSD Importer
有了它,当导入psd 文件时, 文件会自动转为sprite文件并且散图都切完的。
这样精灵锁片的层级顺序也保存着,可能各个部位的位置也不用调整了。
【主要是针对2d游戏,2d骨骼动画的, 不是针对UI的 】
2)、 这里顺便推荐一个开源库 : 根据PSD 文件生成 UGUI Prefab 。
https://github.com/kyubuns/Baum2
可以看这篇博文了解更多: https://qiita.com/kyubuns/items/b4c0c92e60754a8dc544
3)、 Leaking泄露? 我们非常棒的控制台支持#Unity3D团队刚刚发布了一个有助于识别内存泄漏的工具,称为Zombie Object Detector。 当C#包装器对象在其本机C ++对象被销毁后保留在mem中时,V很有用 https://github.com/Unity-Technologies/ZombieObjectDetector
4)、 重新审视了 Survival Shooter ECS项目,并写了一些关于它的说明: https://twitter.com/gamevanilla/status/1080558187131088902
要求: Unity 2018.3.0f2
https://github.com/davidpol/SurvivalShooterECS
5)、 unity3d的光探针放置工具现在是一个包package (因此它不会再污染您的asset 文件夹),并且它附带了几个修复程序。
示例项目:https://github.com/laurenth-unity/LightProbesPlacement
单独包:https://github.com/laurenth-unity/LightingTools.LightProbesVolumes
6)、 Unity有了新的Prefab工作流
https://blogs.unity3d.com/jp/2018/06/20/introducing-new-prefab-workflows/
其中 Prefab 编辑器。 https://connect.unity.com/p/purehabuedeitanitsuite https://connect.unity.com/p/2018-3yi-jiang-nopurehabunoji-ben-cao-zuo https://connect.unity.com/p/purehabubariantodeisannihong-jiao-wosheng-yasu
这个只是代表游戏对象。
代表与预制体相关联的游戏对象。而且右侧添加了 “>”
7)、 [Unity]引入“Unity - MultiProcess - BuildPipeline”,可以在多个流程中构建资产包并缩短构建时间
https://github.com/jiangzhhhh/Unity-MultiProcess-BuildPipeline 应该是国人开发者
怎么用?
using System.Collections.Generic; using UnityEditor; public static class Example { [MenuItem( "Example/Build" )] private static void Build() { var buildSet = new SortedDictionary<string, string[]> { {"Assets/Res/64k.txt", new string[]{ "Assets/Res/64k.txt" } }, {"Assets/Res/128k.txt", new string[]{ "Assets/Res/128k.txt" } }, {"Assets/Res/196k.txt", new string[]{ "Assets/Res/196k.txt" } }, {"Assets/Res/CubeA.mat", new string[]{ "Assets/Res/CubeA.mat" } }, {"Assets/Res/CubeA.prefab", new string[]{ "Assets/Res/CubeA.prefab" } }, {"Assets/Res/CubeB.prefab", new string[]{ "Assets/Res/CubeB.prefab" } }, {"Assets/Res/CubeB1.mat", new string[]{ "Assets/Res/CubeB1.mat" } }, {"Assets/Res/CubeB2.mat", new string[]{ "Assets/Res/CubeB2.mat" } }, {"Assets/Res/CubeC.prefab", new string[]{ "Assets/Res/CubeC.prefab" } }, {"Assets/Res/CubeD.prefab", new string[] { "Assets/Res/CubeD.prefab", "Assets/Res/CubeD1.mat", "Assets/Res/CubeD2.mat", "Assets/Res/CubeD3.mat", "Assets/Res/CubeD4.mat", "Assets/Res/CubeD5.mat", "Assets/Res/CubeD6.mat", "Assets/Res/CubeD7.mat", "Assets/Res/CubeD8.mat", "Assets/Res/CubeD9.mat", "Assets/Res/CubeD10.mat", } }, }; var builds = new List<AssetBundleBuild>(); foreach ( var pair in buildSet ) { var build = new AssetBundleBuild { assetBundleName = pair.Key, assetNames = pair.Value, }; builds.Add( build ); } MultiProcessBuild.BuildPipeline.BuildAssetBundles ( output : "ab", builds : builds.ToArray(), options : BuildAssetBundleOptions.None, target : BuildTarget.Android ); } }
通过这种方式,定义了自己的资产的构建目标有依赖关系,通过调用MultiProcessBuild.BuildPipeline.BuildAssetBundles功能,你可以在一个多进程建立资产包
在存储库作者的环境中,构建时间似乎可以从300分钟减少到42分钟
8)、 [Unity] “TMP_RectVisualizer”,它可以将游戏画面上的 Text和TextMesh Pro的大小可视化
使用UGUI 的时候会遇到比如一段话很长,但是显示不全, 这个时候要大概能猜到是什么原因, 如果可以放方便知道组件的具体大小就更好了, 这个工具不错的~
https://github.com/baba-s/TMP_RectVisualizer
使用:
TMP_RectVisualizer.Show ( outlineSize : 2, outlineColor : Color.red ); TMP_RectVisualizer.Hide();
9)、 开源库: “MeshEffectForTextMeshPro”,它可以在TextMesh Pro中使用反转,渐变,阴影,轮廓
https://github.com/mob-sakai/MeshEffectForTextMeshPro
“ShinyEffectForTMPro”,可以在TextMesh Pro上使用Quira闪耀的效果 (流光效果)。
https://github.com/mob-sakai/ShinyEffectForTMPro
溶解着色器可以在TextMesh Pro中使用的“DissolveEffectForTMPro”
https://github.com/mob-sakai/DissolveEffectForTMPro
10) 、 [Unity]“UI Shapes Kit”可以用uGUI绘制任意数字
https://github.com/thisotherthing/ui-shapes-kit
https://uishapeskit.thisotherthing.co/home/
类似的是这个库:
https://github.com/all-iver/shapes2d
http://sub-c.org/Shapes2D/documentation/
您可以通过将“Shape”组件 附加到SpriteRenderer或Image 组件的 的对象来使用它
类似的库还有:
https://github.com/epezent/ShapeRenderer
只需要将 XXXXShape 组件附加到任意的游戏对象上。 没有限制。
11)、 [Unity]可以从Unity游戏和资产包中提取资产的****工具“uTinyRipper”
https://github.com/mafaca/UtinyRipper
http://baba-s.hatenablog.com/entry/2019/01/07/160000
类似的工具是:
****工具“Unity Assets Bundle Extractor(UABE)”,可以从Unity游戏和资产包中提取资产
https://github.com/DerPopo/UABE
https://7daystodie.com/forums/showthread.php?22675-Unity-Assets-Bundle-Extractor
12)、 IL2CPP内置****工具“Il2CppDumper”,以便能够从APK引入提取.NET的元数据
https://github.com/Perfare/Il2CppDumper 国人维护的项目
https://github.com/Perfare/Il2CppDumper/blob/master/README.zh-CN.md
他还有提取资源的工具 : https://github.com/Perfare/AssetStudio
13)、 性能分析挺有意思: https://qiita.com/divideby_zero/items/a5dd8f2f5a1a721a1957
RectTransform 多种访问时间的测试:
GetComponent:2.73ms
AsCast:2.53ms
MemberCache:2.28ms
ExtendMethodAsCast :2.66ms
PropertyCache :2.68ms 通过减少 != null 的判空也能将时间提升到 : :2.37ms
14)、 RectTransform 的一些扩展 :
http://baba-s.hatenablog.com/entry/2018/08/20/130000
http://baba-s.hatenablog.com/entry/2018/03/14/164000
http://baba-s.hatenablog.com/entry/2019/01/10/180000
15)、如果当您提交Git内容,其中没有.META索引, Git的有可能停止提交。 “unity-git-hooks” 库简介
https://github.com/doitian/unity-git-hooks 国人的
post-checkout 、post-merge 、 pre-commit
16)、文章 : Gamedev中的数学很简单。Unity中的三角剖分和Triangle.Net https://habr.com/post/435374/ 文中提到经典的耳切法多边形。
文中提到两个库: Triangle.NET 和 poly2Tri
17)、 为了确保所有内容都适合相机的视图,您可以简单地计算任何距离的frustum切片,并使用Z = 0的DrawWireCube场景视图 进行绘制
https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html
18)、如果您在Unity中对自己的shadowmaps阴影贴图进行采样,则可以为阴影绘制轮廓线。 (pastebin中的着色器代码)
|
Shader "Unlit/recieveShadowMapWithOutline" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "LightMode" = "ForwardBase" "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #define SHADOWS_SCREEN #include "AutoLight.cginc" #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; UNITY_FOG_COORDS(1) SHADOW_COORDS(5) float4 pos : SV_POSITION; }; sampler2D _MainTex; float4 _MainTex_ST; v2f vert (appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); TRANSFER_SHADOW(o); UNITY_TRANSFER_FOG(o,o.pos); return o; } float sampleEdge(sampler2D tex, float2 uv, float Offset) { float mi = 1000.; float ma = -100.; float x, y; for (y = -1.; y <= 1.; y += 1.0) { for (x = -1.; x <= 1.; x += 1.0) { float offsets = Offset / _ScreenParams.xy; float v = tex2D(tex, uv + float2(x, y)*offsets ); mi = min(v, mi); ma = max(v, ma); } } return abs(ma - mi); } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv); float3 shadowCoord = i._ShadowCoord.xyz / i._ShadowCoord.w; float shadowmap = tex2D(_ShadowMapTexture, shadowCoord.xy); float thickness = 20.; float e = sampleEdge(_ShadowMapTexture, shadowCoord.xy, thickness / i._ShadowCoord.w); col.xyz = lerp(pow(col.xyz, 3.6)*0.45, col.xyz, shadowmap); col.xyz = lerp(col.xyz, float3(.1,0.2,0.3), e); UNITY_APPLY_FOG(i.fogCoord, col); return col; } ENDCG } } FallBack "VertexLit" } |
18)
https://twitter.com/_janloehr/status/1073230428755148800
想知道物体是否在屏幕内? 使用此片段来扩展Transform类并编写:
|
public static class TransformExtensions { public static bool IsOnScreen(this Transform transform) { //Answer only if the cursor is actually on this client's screen Vector3 cursorScreenSpace = GetMainCam().WorldToScreenPoint(transform.position); if (cursorScreenSpace.z > 0 && cursorScreenSpace.x > 0 && cursorScreenSpace.x < Screen.currentResolution.width && cursorScreenSpace.y > 0 && cursorScreenSpace.y < Screen.currentResolution.height) { return true; } return false; } private static Camera GetMainCam() { return Camera.main; } } |
19)、 使用Application.logMessageReceived挂钩进入Unity调试日志,编写自己的游戏错误日志
https://docs.unity3d.com/ScriptReference/Application-logMessageReceived.html
20)、 想要在Editor Windows中快速/动态地绘制任何枚举列表? 今天我学会了如何编写一个静态编辑器方法,它可以一般地处理任何枚举列表并将它们显示为它们的Enum Popup。:d
是否要在“场景视图”中显示GUI元素以使开发步骤更快更容易? 将您选择的静态方法添加到onSceneGUIDelegate并绘制所需的所有内容。
在 Inspector 面板进入 Debug 模式时, 按Alt 键可以看到 将显示完整变量名字 。
选择游戏对象,鼠标左键双击一下 代替F键(定位功能) get新技能
(自己试一试就知道了~~)
UGUI降低填充率, unity2018.3 这功能强!!
21)、 将项目中的所有预制件转换为2018.3格式
|
using UnityEditor; using UnityEngine; namespace Sandbox { public static class ReimportPrefab { [MenuItem("Sandbox/ReimportPrefab")] public static void Run() { var directory = new System.IO.DirectoryInfo(Application.dataPath); var files = directory.GetFiles("*.prefab", System.IO.SearchOption.AllDirectories); foreach (var file in files) { var path = "Assets" + file.ToString().Replace(Application.dataPath, ""); Debug.Log(path); var go = PrefabUtility.LoadPrefabContents(path); PrefabUtility.SaveAsPrefabAsset(go, path); PrefabUtility.UnloadPrefabContents(go); } } } } |
22)、 编辑器扩展的小Tips
粗体文字:
|
GUIStyle _style = new GUIStyle() { fontSize = EditorStyles.boldFont.fontSize, fontStyle = FontStyle.Bold }; EditorGUILayout.LabelField(_message, _style, _layout); |
划线:
|
GUILayout.Box(GUIContent.none, GUILayout.Width(1f), GUILayout.ExpandHeight(true)); GUILayout.Box(GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.Height(1f)); |
框:
|
Rect _rect = EditorGUILayout.BeginVertical(GUI.skin.box); { // 做一些事情 } EditorGUILayout.EndVertical(); |
段落:
|
Label("項目名"); EditorGUI.indentLevel++; //<- 段落进行缩进 Label("段落内容"); EditorGUI.indentLevel--; //<-恢复缩进 |