Unity3d 周分享(11期 2019.2.16)

选自过去1~2周 自己所看到外文内容: https://twitter.com/unity3d   和各种其他博客来源吧  

 

1)、  [Unity]编辑器扩展,使Unity编辑器无法退出

using UnityEditor; [InitializeOnLoad] public static class Example {     static Example()     {         EditorApplication.wantsToQuit += () => false;     } }

(如果要终止,任务将从任务管理器终止)

 

2)、   [Unity]编辑器扩展,在退出Unity编辑器时显示确认对话框

[InitializeOnLoad]

public static class Example

{

    static Example()

    {

        EditorApplication.wantsToQuit += () =>

        {

            return EditorUtility.DisplayDialog

            (

                title: "Unity",

                message: "确定关闭Unity么?",

                ok: "确定",

                cancel: "取消"

            );

        };

    }

}

 

3)、  [Unity]编辑器扩展,在启动build 时显示确认对话框

       比如在Build 前做一些检查, 然后提示提示不对的地方等。 

using UnityEditor; [InitializeOnLoad] public static class Example {     static Example()     {         BuildPlayerWindow.RegisterBuildPlayerHandler( OnBuild );     }     private static void OnBuild( BuildPlayerOptions options )     {         var isBuild = EditorUtility.DisplayDialog         (             title   : "Unity",             message : "你想开始Build么?",             ok      : "是的",             cancel  : "取消"         );         if ( !isBuild ) return;         BuildPipeline.BuildPlayer( options );     } }

 

 

 

4)  、 下面两个多余的编辑器扩展。       为什么说多余  , Unity提供的默认方式是    Alt + 鼠标左键点击item.    

[Unity]编辑器扩展,可以使用F3收起/展开Project视图面板中的所有层次结构

https://gist.github.com/baba-s/b3d47952ddff3317d97f627239d7ab09#file-projectcollapser-cs       

[Unity]编辑器扩展,可以使用F4收起/展开Hierarchy面板中的 所有层次结构 

https://gist.github.com/baba-s/de6a0261d47a3c9d724fcdcd1a533e1f#file-hierarchycollapser-cs    

 

 

5)、  技术文章分享:

 

https://connect.unity.com/p/multi-threaded-flow-field-ai-pathing

https://github.com/Gismar/FlowFieldPathing#flow-field-ai-pathing   

 

             流场寻路 算法还是第一次听说, 但是早就有了:  

https://leifnode.com/2013/12/flow-field-pathfinding/

https://howtorts.github.io/2014/01/04/basic-flow-fields.html

 

MMORPG战斗系统随笔(二)、浅谈场寻路Flow Field PathFinding算法:  提到和A*的比较:https://www.cnblogs.com/zblade/p/7608275.html

 

 

 

6)、   视频教程:  《Unity3D Tiny Snake - Improving Code and adding UI & Game Over》https://www.youtube.com/watch?v=9wRfFut76R0&list=PLJWSdH2kAe_J2INQPCk_Kyes2IMpUv18G

      https://[email protected]/Sniffle6/tiny-snake/src

 

7)、Object Graph Visualizer       https://jacksondunstan.com/articles/5034     

有意思~~~~

 

 

8)、 [Unity]如何发布Windows 10的屏幕键盘

#if UNITY_STANDALONE_WIN             System.Diagnostics.Process.Start("osk.exe"); #endif

注意:

  • 仅在平板电脑模式为ON时出现
  • 键盘连接时不会出现

 

9)、 使用C#正则表达式计算字符串的计算公式

有几种方法可以计算字符串公式并输出结果,但这次用正则表达式分析公式。

https://qiita.com/NegiuraRoman/items/6e02d671c47225cd0844

 

 

10)、    我在CircleCI 中运行了Unity的Test&Build  (类似于Jenkins的工具~)

https://qiita.com/MizoTake/items/2d822e85d33bee359f98   

 

 

11)、  作为手册:  《Unity:Material(标准着色器)涵盖所有脚本的参数设置!》

https://qiita.com/kingyo222/items/8a5852c963cc883e1f2c

 

 

12)、  【Unity】Sprite导入时设置Pivot枢轴 

       主要会遇到这个问题 , 不能只是简单的设置:

https://answers.unity.com/questions/1318809/onpostprocesstexture-textureimporterspritepivot-do.html     

public class ImportProcess : AssetPostprocessor {     void OnPreprocessTexture()     {         var ti = (TextureImporter)assetImporter;         var texSettings = new TextureImporterSettings();         ti.ReadTextureSettings(texSettings);         texSettings.spriteAlignment = (int)SpriteAlignment.Custom;         ti.SetTextureSettings(texSettings);         ti.spritePivot = new Vector2(0.5f, 0.0f);     } }

 

 

 

13)、[白鹭免费咨询室]让白鹭的DisplayObject有点像Unity   

https://qiita.com/motoyasu-yamada/items/8691996d7072da7db25e    

代码:

https://github.com/squmari/EgretEngine/tree/master/All_Stop_With_One_Click    

https://github.com/motoyasu-yamada/egret-unity-demo   

 

 

 

14)、  如何制作改造的apk(MOD)及其对策 :  https://qiita.com/YuukiDeveloper/items/764adb88f5a485f714d8

使用到的工具:

  • Apktool v2.3.4
  • DnSpy v6.0.3
  • Il2CppDumper v4.0.0
  • HxD v.2.2.0.0

 

 

 

15)、  [Unity]更改LineRenderer的 宽度 (在2018.3之后使用)

 

 

16)、 [Unity] AssetDatabase.RenameAsset的第二个参数不是文件路径,而是没有扩展名的文件名 

 

// 不对 AssetDatabase.RenameAsset (      “Assets / Textures / hoge.png”,       “Assets / Textures / fuga.png”  ); // 正确 AssetDatabase.RenameAsset (      “Assets / Textures / hoge.png”,       “fuga”  );

 

 

17)、Unity设置随机种子的方式 :  https://docs.unity3d.com/ScriptReference/Random.InitState.html    

 

 

 

18)、  好文章:  Unity Audio Import Optimisation - getting more BAM for your RAM 

            总结了针对移动平台的建议:

Type Of Sound

Load In Background

Load Type

Preload Audio Data

Compression Format

Quality

Sample Rate Setting

Notes

Dialogue

Y

Compressed in memory

Y

Vorbis/MP3

50

Preserve

 

Environmental long loops

Y

Compressed in memory

Y

Vorbis

35

Preserve

Use higher quality for non-noisy sounds

Environmental one-shots

Y

Decompress on load

Y

Vorbis/MP3

50

Preserve

 

Foley

N

Compressed in memory

Y

PCM/ADPCM*

n/a

Preserve

 

Footsteps

N

Compressed in memory

Y

PCM/ADPCM*

n/a

Optimise

 

Music (long pieces)

n/a

Streaming

n/a

Vorbis

70

Preserve

See Warnings on streaming below

Music (stingers)

Y

Compressed in memory

Y

Vorbis/MP3

70

Preserve

 

Non-dialogue vocalisations

Y

Decompress on load

Y

Vorbis/MP3

50

Preserve

 

Special FX (short)

N

Compressed in memory

Y

PCM/ADPCM*

n/a

Optimise

Sample rate should be preserved if these sounds are ever pitched down

Special FX (long)

N

Decompress on load

Y

Vorbis/MP3

50

Preserve

 

UI sounds (long)

Y

Decompress on load

Y

Vorbis/MP3

50

Preserve

 

UI sounds (short)

N

Compressed in memory

Y

PCM/ADPCM*

n/a

Optimise

 

 

 

 

 

19)、  一个人分享的文章:

  • 管理GameObject中组件之间的状态和事件
  • 通知组件中SharedState共享状态的更改
  • 使用SharedEvents控制角色(示例)  

https://github.com/deniskozlov/yunka_sharedstate_exaple  

        他的目的是解决两个组件的强耦合(需要引用对方在访问对方的成员)。  他引入了 SharedState,  SharedEvents  ,状态改变一开始利用Update就是轮询的方式让对方组件获取到,   第二篇文章重构为状态改变通知。      第三篇文章作为案例。

 

                 又看到另外一个人的分享《Unity3D组件之间的消息系统或“软耦合”》   , 总结了

  • 基于UnityEvents / UnityAction的消息传递系统
  • C# 中经典的event, delegate 
  • 具有字符串标识的反射消息系统
  • 具有数据类型标识的反射消息系统

 

 

 

20)、  文章:  Color Spread Post-Processing Effect Tutorial in Unity   

            使用 LWRP + Post-Processing   实现的显示效果!

 

 

21)、  Unity在 5.0 之后引入一个API :  https://docs.unity3d.com/ScriptReference/Texture2D.PackTextures.html      将多个贴图打成一个图集。   但是API的参数怎么设置,怎么得到?https://twitter.com/_staggart_/status/1095271775322157056       示例代码:  https://bitbucket.org/Jonny10/texture-atlas-creator/src   

 

 

 

22)、  有一些简单的抛射数学,比如找到发射速度来击中2D或3D空间中的给定目标   

https://twitter.com/rtm223/status/1092879537854128128      , 代码:  https://pastebin.com/hi3KzVi5  

Gameplay Favourites in here are:

- Launch velocity to hit a target with given apex height (for prettier arcs)

- Minimum launch velocity to hit target (for organic throws)

- Launch velocity for the lowest possible arc to hit, given max launch speed (for minimum travel time)

这里的游戏玩法是:

 - 发射速度以达到给定顶点高度的目标(对于更漂亮的弧线)

 - 达到目标的最小发射速度(对于有机投掷)

 - 给定最大发射速度(最短行程时间),发射最低可能弧线的速度

 

 

23)、Unity GPU剔除实验     

https://www.mpc-rnd.com/unity-gpu-culling-experiments/

https://www.mpc-rnd.com/unity-gpu-culling-experiments-part2-optimizations/?t=

 

 

24)、 https://twitter.com/LotteMakesStuff/status/1093082165460566016?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E1093082165460566016&ref_url=https%3A%2F%2Fdevdog.io%2Fblog%2F10-best-unity-tips-for-game-developers-78%2F 

你最近更新了Burst吗? burst inspector有一个很棒的新功能 - 如果勾选'Enhanced Disassembly'复选框,它会使用行号和文件名注释Assembly视图,这样您就可以看到您的工作代码如何匹配!

简单的例子,使用float3和Vector3有什么区别?好吧。 float3被编译为单个指令〜

文档: https://docs.unity3d.com/Packages/[email protected]/manual/index.html#optimization-guidelines  

 

 

 

25)、  Unity 2018.2  开始增加了图集图集操作的相关Editor 扩展:

           图集内元素增删改查, 设置等。 

 

UnityEditor.U2D

  • Classes
    • SpriteAtlasExtensions
    • SpriteAtlasPackingSettings
    • SpriteAtlasTextureSettings
    • SpriteAtlasUtility

        API 怎么使用 :   http://kan-kikuchi.hatenablog.com/entry/SpriteAtlasExtensions   

 

 

 

26)、 Unity的默认资源位置 ,安装路径下  Unity 2019.1.0a11\Editor\Data\Resources  

            导入到项目中, 注意记得添加  后缀名  .asset  .    就可以看到里面包含的内容了。 

       怎么在代码中访问他们,   两个API , 在官方文档中搜索不到居然(Unity 4.x 就有了)。     一个是在编辑器下使用, 一个是出包之后使用(必须这样)。  

#if UNITY_EDITOR   Material spriteDefaultMaterial = UnityEditor.AssetDatabase.GetBuiltinExtraResource("Sprites-Default.mat"); #else   Material spriteDefaultMaterial = Resources.GetBuiltinResource("Sprites-Default.mat");     // 与Resources.Load 不同,这个要添加后缀名。  #endif

 

 

 

27)、看到一个 基于浏览器的 2d动画编辑器:     而且还支持Unity 运行时。  

免费存储空间创作的东西都是public的, 如果想私有 就要花钱。      创建完成之后可以导出序列帧或者 对应库的骨骼动画数据 。        而且支持Web 平台。 

https://www.2dimensions.com/runtimes       https://github.com/2d-inc  

 

 

 

 

 

同时又看到  一个2d骨骼动画的工具 :

http://creature.kestrelmoon.com/index.html     

提供Unity 支持 :  https://github.com/kestrelm/Creature_Unity     而且支持UGUI .  

        看到的文章:  《CreaturePack: High Performance 2D WebGL Character Animation with WebAssembly》, 《Advanced 2D Skeletal Character Animation for the WeChat Mini Game Engine with Cocos Creator Tutorial》使用CocosCreator 开发微信小游戏有使用这个动画工具

   顺便  发几个 微信小游戏的架构图片:

 

 

https://www.lewagon.com/blog/wechat-mini-games-making-noise-how-developers-get-started-guickly 

 

 

 

 

28)、  使用 Flutter  做游戏开发?

     Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面。 Flutter可以与现有的代码一起工作。在全世界,Flutter正在被越来越多的开发者和组织使用,并且Flutter是完全免费、开源的。    这是百科的介绍。  

          但是看到有文章分享:

  • Building A 2D game in Flutter- A Comprehensive Guide
  • Sprite Sheet Animations in Flutter

使用的是 基于Flutter的游戏引擎   flame:  https://github.com/luanpotter   

         

    还有不使用引擎, 做的三消游戏:  https://github.com/boeledi/flutter_crush    https://medium.com/flutter-community/flutter-crush-debee5f389c3

 

 

 

29)、 物理2D Raycaster的“Max Ray Intersections”设置为0时

 

将发生几个字节的GC Alloc。

物理2D Raycaster的“Max Ray Intersections”如果为1时,则不会有问题。

 

 

 

30)、   Post Processing Stack V2 (简称 PPS2 或者 PostFX v2) 扩展

https://docs.unity3d.com/Packages/[email protected]/manual/Writing-Custom-Effects.html   

          Because we only use command buffers, the system relies on MaterialPropertyBlock to store shader data. You don't need to create those yourself as the framework does automatic pooling for you to save time and make sure performances are optimal. So we'll just request a PropertySheet for our shader and set the uniform in it.

Finally we use the CommandBuffer provided by the context to blit a fullscreen pass with our source, destination, sheet and pass number.

And that's it for the C# part.

 

https://docs.unity3d.com/Manual/GraphicsCommandBuffers.html   

https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.html

            PPS2 使用到 G-Buffer 

https://github.com/keijiro/PostProcessingUtilities

https://connect.unity.com/p/unityzhong-de-postfx-v2    

 

 

31)、 通过代码和 adb 进行APK的安装和启动

http://kurihara-n.hatenablog.com/entry/2015/12/06/222600

 

 

using UnityEngine;

using UnityEditor;

using System.Collections;

using System.Diagnostics;

 

public class InstallAndRun : EditorWindow

{

    [MenuItem("Android/Install and Run")]

    public static void DoInstallAndRun()

    {

        string adbPath = EditorPrefs.GetString("AndroidSdkRoot") + "\\platform-tools\\adb.exe"; // AndroidSdkPath根据环境而变化

        string apkPath = EditorUtility.OpenFilePanel("Select apk file", "", "apk"); // 打开apk文件选择对话框

 

        if (string.IsNullOrEmpty(apkPath))

        {

            return;

        }

 

        // 运行安装过程: adb install -r apk

        Process installProcess = new Process

        {

            StartInfo =

            {

                FileName = adbPath,

                Arguments = "install -r " + apkPath

            }

        };

 

        installProcess.Start();

 

        installProcess.WaitForExit();

 

        // 运行启动过程: adb shell am start -n YourActivity

        Process runProcess = new Process

        {

            StartInfo =

            {

                FileName = adbPath,

                Arguments = "shell am start -n " + Application.identifier + ".UnityPlayerNativeActivity"

                            // 默认类名是 :"/com.unity3d.player.UnityPlayerActivity" ,但是要根据自己项目的中manifest的定义 

            }

        };

 

        runProcess.Start();

    }

}

你可能感兴趣的:(学unity涨知识,unity3d,周分享)