Unity3d 周分享(8期 2018.12.16)

版权声明:本文为博主原创文章,未经博主允许不得转载。出自 游戏开发实验室 https://blog.csdn.net/u010019717/article/details/85040135

选自过去1~2周的内容: https://twitter.com/unity3d   和各种其他来源吧

1)、 取消DontDestroyOnLoad效果

DontDestroyOnLoad效果的原理是把物体移动到一个特殊的场景里,这个场景在加载场景时不会被卸载,这个场景里的物体也就不会随着加载场景被销毁。

取消DontDestroyOnLoad效果就是进行一个逆操作,把这个物体移回到活跃场景里。

2) Anti-piracy APK checking

an anti-piracy check, which is used to determine if your app was altered after it was submitted to the Google Play Store

扫描二维码关注公众号,回复: 5028999 查看本文章

Restrict features in your app like level progression or store fronts

反盗版APK检查

反盗版检查,用于确定您的应用在提交到Google Play商店后是否被更改

限制应用中的功能,例如关卡进度, 商店使用等等

https://docs.unity3d.com/ScriptReference/Application-genuine.html

https://docs.unity3d.com/ScriptReference/Application-genuineCheckAvailable.html

3)

安卓的 ADB 拥有专门为Unity 添加的过滤器

adb logcat -s Unity

4)、 http://baba-s.hatenablog.com/entry/2018/12/12/183000

编辑器扩展,输出日志用于测量构建所需的时间

usingSystem;
usingUnityEditor.Build;
usingUnityEditor.Build.Reporting;
usingUnityEngine;
publicclassExample : IPreprocessBuildWithReport, IPostprocessBuildWithReport {
    privateDateTimem_startTime;
    publicintcallbackOrder { get { return0; } }
    publicvoidOnPreprocessBuild (BuildReportreport) {
        m_startTime = DateTime.Now;
        Debug.LogFormat ("【ビルド】開始:{0}", m_startTime.ToString ("HH:mm:ss"));
    }
    publicvoidOnPostprocessBuild (BuildReportreport) {
        varendTime = DateTime.Now;
        vardeltaTime = endTime - m_startTime;
        varhours = deltaTime.Hours.ToString ("00");
        varminutes = deltaTime.Minutes.ToString ("00");
        varseconds = deltaTime.Seconds.ToString ("00");
        Debug.LogFormat ("【ビルド】終了:{0}", endTime.ToString ("HH:mm:ss"));
        Debug.LogFormat ("【ビルド】経過時間:{0}:{1}:{2}", hours, minutes, seconds);
    }
}

将上述脚本添加到Unity项目的“Editor”文件夹中

右键单击Console窗口的选项卡,选择“Open Editor Log”,然后按

“Editor.log”进行*** Completed 'Build.Player.搜索

***在7秒内完成'Build.Player.WindowsStandaloneSupport'(6905毫秒)

5)、 AnimationCurve 类型变量的初始化可以使用「AnimationCurve.Constant」「AnimationCurve.Linear」「AnimationCurve.EaseInOut」

 using UnityEngine;
 public class Example : MonoBehaviour {
     public AnimationCurve m_curve1 =
         AnimationCurve.Constant (0, 1, 0.5f);

     public AnimationCurve m_curve2 =
         AnimationCurve.Linear (0, 0, 1, 1);

     public AnimationCurve m_curve3 =
         AnimationCurve.EaseInOut (0, 0, 1, 1);
 }

6) 官方文档中描述了如何优化IL2CPP的构建时间

https://docs.unity3d.com/Manual/IL2CPP-OptimizingBuildTimes.html

1、 使用增量构建

Https://Docs.Unity3d.Com/ScriptReference/PlayerSettings.SetIncrementalIl2CppBuild.Html 

Https://Docs.Unity3d.Com/ScriptReference/BuildOptions.EishishiipitiiekkusutiirnalModificationsToPlayer.Html

2、 不要让杀毒软件 扫描项目 和构建的目标文件夹。

根据Unity的测试,在Windows 10上禁用Windows Defender时,

构建时间似乎减少了50%到66%

不仅仅是构建, 我是真的烦透杀毒软件, 微软傻逼还自带 关闭不了!!! Unity在执行导入的时候也会看到杀毒软件 100%CPU 占用在执行着扫描 ~~

3、将项目和构建文件夹保存到SSD

SSD比HDD更具可读性和可写性

https://forum.unity.com/threads/incremental-builds-for-il2cpp.365470/

7)、 “Unity Selection History”,可以通过Ctrl + Shift + Z或Ctrl + Shift + Y前进和前进选择状态

https://github.com/garettbass/UnityExtensions.SelectionHistory

此人分享蛮多扩展的: https://github.com/garettbass?tab=repositories

8)、 新的Memory Profiler的包可用(目前是预览版)

https://forum.unity.com/threads/new-memory-profiler-preview-package-available-for-unity-2018-3.597271/

2018年12月14日,它还是一个预览版本。

您可以通过将以下行添加到Unity项目的“Packages”文件夹中的“manifest.json” 来使用它

“ com.unity.memoryprofiler ” : “ 0.1.0-preview.2 ”,

打开快照, 然后可以查看内存使用情况 如下

快照存放在 项目的 MemoryCaptures 文件夹中~~~

9)、 https://qiita.com/noolbar/items/b4895a5345dc78f3b098

文章中提到了一个 Unity引擎使用 https://www.babylontoolkit.com/# 此工具, 将项目导出为 abylon.js 引擎项目(这个是Web游戏开发引擎)

Https://Www.Crossroad-tech.Com/entry/Babylonjs_Unity3 

Https://Github.Com/BabylonJS/Exporters.Git 

Https://Github.Com/flushpot1125/BabylonJS_UnityExportSample

10)、 当您在控制台窗口中选择日志时按Ctrl + C,您可以复制

11)、 现在可以从Package Manager安装 可以在编辑器扩展中使用协程的包(现在预览版)

https://docs.unity3d.com/Packages/[email protected]/manual/

2018年12月14日还是预览版

怎么用?

//启动协程
//第二参数中的对象(发起协程者)
EditorCoroutineUtility.StartCoroutine( Test(), this );

//启动
//你可以使用它而不指定启动协程的对象
EditorCoroutineUtility.StartCoroutineOwnerless( Test() );

//停止coroutine 
var c = EditorCoroutineUtility.StartCoroutine( Test(), this );
EditorCoroutineUtility.StopCoroutine( c );

使用例子:

using System.Collections;
using Unity.EditorCoroutines.Editor;
using UnityEditor;
using UnityEngine;

public class Example : EditorWindow
{
    private EditorCoroutine m_coroutine;

    [MenuItem( "Tools/Hoge" )]
    private static void Init()
    {
        GetWindow<Example>();
    }

    private void OnGUI()
    {
        if ( GUILayout.Button( "开始,(指定对象)" ) )
        {
            m_coroutine = EditorCoroutineUtility.StartCoroutine( Test(), this );
        }
        if ( GUILayout.Button( "开始,(不指定对象)" ) )
        {
            m_coroutine = EditorCoroutineUtility.StartCoroutineOwnerless( Test() );
        }
        if ( GUILayout.Button( "停止" ) )
        {
            EditorCoroutineUtility.StopCoroutine( m_coroutine );
        }
    }

    private IEnumerator Test()
    {
        while ( true )
        {
            Debug.Log( "测试" );
            yield return null;
        }
    }
}

12)、 Unity 2018.3新功能添加了禁用垃圾回收的API

怎么用?

使用UnityEngine.Scripting命名空间中存在的GarbageCollector类

使用 UnityEngine.Scripting;

//激活垃圾收集
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;

//禁用垃圾回收
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;

//在更改模式时调用
GarbageCollector.GCModeChanged += mode => Debug.Log( mode );

使用例子:

using System;
using System.Text;
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UI;

public class Example : MonoBehaviour
{
    public Text m_text;

    private void Update()
    {
        //适当地生成的GC的Alloc
        for ( int i = 0; i < 10000; i++ )
        {
            string.Format( "{0}{1}{2}{3}{4}", 0, 1, 2, 3, 4 );
        }

        var mode    = GarbageCollector.GCMode;
        var count   = GC.CollectionCount( 0 );
        var sb      = new StringBuilder();

        //切换GC按下空格键时打开/关闭
        if ( Input.GetKeyDown( KeyCode.Space ) )
        {
            GarbageCollector.GCMode = mode == GarbageCollector.Mode.Enabled
                ? GarbageCollector.Mode.Disabled
                : GarbageCollector.Mode.Enabled
            ;
        }

        sb.AppendFormat( "GarbageCollector.GCMode: {0}", mode.ToString() ).AppendLine();
        sb.AppendFormat( "GC.CollectionCount( 0 ): {0}", count.ToString() );
        m_text.text = sb.ToString();
    }
}

当我按空格键时,

我创建了一个脚本来打开/关闭垃圾收集并尝试它

13)、2D FpsKit Unity3D

Includes:

Player Camera

Player Control and Shooting

Enemy AI and Enemy Shooting

Player and Enemy Health System

在这里下载 : https://sites.google.com/view/tetonentertainmemt/downloads

14)、 在Unity着色器中使用Stencil Comparison的定义值

https://docs.unity3d.com/Manual/SL-Stencil.html

CompareFunction(比较关数)

项目

说明

Disabled

0

禁用模板测试。

Never

1

使模板测试始终失败。

Less

2

仅当像素的参考值小于缓冲区的值时才会渲染。

Equal

3

仅当像素的参考值等于缓冲区的值时才会渲染。

LEqual

4

仅在像素的参考值小于或等于缓冲区的值时才渲染。

Greater

5

仅在像素的参考值大于缓冲区的值时才渲染。

NotEqual

6

仅当像素的参考值不等于缓冲区的值时才会渲染。

GEqual

7

仅在像素的参考值大于或等于缓冲区的值时才渲染。

Always

8

始终通过模板测试。默认值。

15)、 在Unity中使用 LWRP 创建Outline 。

https://habr.com/post/430792/

16)、 俄罗斯的两篇文章 :

Game features with ECS: we add kits to the shooter

As we wrote the network code of mobile PvP shooter: player synchronization on the client

17)、 这个文章有点意思: http://www.codersblock.org/blog/client-side-prediction-in-unity-2018

演示项目显示Unity中客户端预测的基本实现,因此实际网络发生,所有网络流量都在单个Unity实例中模拟。

https://github.com/spectre1989/unity_physics_csp

https://docs.unity3d.com/ScriptReference/Physics.Simulate.html

18)、 Timeline 在Unity 2019 中引入了事件系统:

https://forum.unity.com/threads/new-in-2019-1-timeline-signals.594142/

Https://forum.unity.com/threads/new-in-2019-1-marker-customization.594712/

https://github.com/Unity-Technologies/Timeline-MessageMarker

http://tsubakit1.hateblo.jp/entry/2018/12/10/233146

此功能可以从Unity 2019.1 a11稳定使用。 如果在 之前的版本中使用怎么办呢? 早就有的一种开源方案: http://tsubakit1.hateblo.jp/entry/2018/07/06/234812

增加了一个新的轨道 : SignalTrack

首先如何从Timeline 上调用方法

时间轴添加了一个名为“信号”Signal的新概念,以区别于动画事件。

Signal这是一种资产。 在场景中会有Signal Receiver 来监听Timeline的事件。 当Timeline在执行过程中调用 Signal 时, 场景中的Signal Receiver会接收信号, 并调用Unity Event 的流。

name

function

Signal

Register as asset, marker

Marker

Event registered with Timeline

Signal Receiver

Identify the signal from the marker and call UnityEvent

怎么使用?

首先要创建资产: Project -> Craete -> Signal

然后在 GameObject 上添加 Signal Receiver 组件, 对感兴趣的信号做处理 ,比如 Emit

之后在时间轴上做标记, 用于触发Signal

可以扩展么? 自己看原文吧!!!!

19)、 [时间轴]关于通过播放和编辑时间轴来分离环境的设计

https://qiita.com/jukey17/items/1158e9549368fd69a63e 文章没看太懂, 但是感觉很有用???

20)、使用SpriteAtlas打包 方式,延迟加载纹理

http://tsubakit1.hateblo.jp/entry/2018/12/14/221116

感觉很有用啊~

首先 Scene 或者 Prefab应用的 Sprite会立即加载。 那么~

懒加载纹理

猜你喜欢

转载自blog.csdn.net/u010019717/article/details/85040135