小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Untiy3d

 kiki的號(hào) 2017-04-17

本文固定連接:http://blog.csdn.net/u013108312/article/details/52723347
我們玩過(guò)的游戲中,神優(yōu)化和渣優(yōu)化的案例都不勝枚舉,它們直接影響著玩家們的游戲體驗(yàn)。這篇文章將從最基礎(chǔ)的概念開始,配合實(shí)例講解各種優(yōu)化的技巧,最終建立起一套屬于自己的優(yōu)化方法,完成對(duì)游戲項(xiàng)目的評(píng)估和優(yōu)化工作。

1. 簡(jiǎn)介

1.什么是性能優(yōu)化

1.常見(jiàn)的優(yōu)化類型

1.性能優(yōu)化

2.流出優(yōu)化

3.體驗(yàn)優(yōu)化

2.性能優(yōu)化目標(biāo)

1.游戲流暢運(yùn)行

1.多種幀數(shù)標(biāo)準(zhǔn) 30-60幀
2.避免卡頓

2.游戲符合市場(chǎng)需要

1.硬件兼容性
2.安裝包/數(shù)據(jù)包大小

2.優(yōu)化常見(jiàn)的誤區(qū)

誤區(qū)1:我的游戲很簡(jiǎn)單不需要優(yōu)化 (性能黑點(diǎn))
誤區(qū)2:優(yōu)化工作盡早進(jìn)行
誤區(qū)3:性能優(yōu)化=Debug

3.優(yōu)化的兩大原則

1.不過(guò)早做優(yōu)化
2.用戶不察覺(jué)
玩家不一定能發(fā)現(xiàn)欠優(yōu)化的地方
玩家不一定能發(fā)現(xiàn)優(yōu)化欠佳的地方

4.優(yōu)化的組成部分

  • 腳本
    – 常見(jiàn)的性能黑點(diǎn)(正確的代碼放到了錯(cuò)誤的地方)底層?。?!
    – 如何找到需要優(yōu)化的代碼

    1.常規(guī)循環(huán)
    2.變量的隱性調(diào)用
    3.Gmaeobject.Find 儲(chǔ)存到變量中 gameobject Go; 查找一次就可以了。
    4.多線程

    IEnumerator Work()
    {
        //線程不安全
        //StartCoroutine(MyIoWork1());
        //StartCoroutine(MyIoWork2());
        yield return StartCoroutine(MyIoWork1());
        yield return StartCoroutine(MyIoWork2());
    }

    IEnumerator MyIoWork1()
    {
        for (int i = 0; i < 1000; i++)
        {
            System.IO.File.Delete("c:\a.zip");
            yield return null;
        }

    }

    IEnumerator MyIoWork2()
    {
        for (int i = 0; i < 1000; i++)
        {
            System.IO.File.Delete("c:\a.zip");
            yield return null;
        }

    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

5.數(shù)學(xué)
計(jì)算距離:Mathf.Sqrt
計(jì)算方向:Vector3.Angle
Minimize use of complex mathematical operations such as pow, sin and cos in pixel shaders.

using UnityEngine;
using System.Collections;

public class TestMagnitude : MonoBehaviour {

    public Transform player1;
    public Transform player2;

    void Start()
    {
        Calc();
    }

    void Calc()
    {
        float distance1 = (player1.position - transform.position).magnitude;
        float distance2 = (player2.position - transform.position).magnitude;
        Debug.Log("Player1 is closer than Player2:" + (distance1 < distance2).ToString());

        float distance11 = (player1.position - transform.position).sqrMagnitude;
        float distance22 = (player2.position - transform.position).sqrMagnitude;
        Debug.Log("Player1 is closer than Player2:" + (distance1 < distance2).ToString());
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
using UnityEngine;
using System.Collections;

public class Compare : MonoBehaviour {

    public Transform player1;
    public Transform player2;

    // Use this for initialization
    void Start () {

        float angle = Vector3.Angle(player2.forward, player1.forward);
        float dot = Vector3.Dot(player2.forward,player1.forward);

        Debug.Log("Dot=" + dot +" Angle=" + angle);
    }

    // Update is called once per frame
    void Update () {

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

6.Object Pool 適用于頻繁操作的對(duì)象,需要緩存

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TestPool : MonoBehaviour
{
    public Transform root;
    public GameObject prefab;

    public float loopCount;
    public float prefabCount;
    List<GameObject> objects;

    // Use this for initialization
    void Start()
    {

        objects = new List<GameObject>();
        System.DateTime startTime = System.DateTime.Now;
        TestCaseWaitOutPool();
        System.DateTime endTime = System.DateTime.Now;
        string totalMs = (endTime - startTime).TotalMilliseconds.ToString();

        Debug.Log("Test case Without Pool take " + totalMs + "ms.");
    }

    // Update is called once per frame
    void Update()
    {

    }

    void TestCaseWaitOutPool()
    {
        for (int j = 0; j < loopCount; j++)
        {
            for (int i = 0; i < prefabCount; i++)
            {
                //create prefab
                GameObject go = Instantiate(prefab);
                //set parent
                go.transform.parent = root;
                //add to list
                objects.Add(go);
            }
            for (int i = 0; i < prefabCount; i++)
            {
                GameObject.Destroy(objects[i]);
            }

            //destory prefab
            objects.Clear();
        }

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

使用 Pool 之后。

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TestPool : MonoBehaviour
{
    public SimplePool pool;
    public Transform root;
    public GameObject prefab;

    public float loopCount;
    public float prefabCount;
    List<GameObject> objects;

    // Use this for initialization
    void Start()
    {

        objects = new List<GameObject>();
        // with out pool
        System.DateTime startTime = System.DateTime.Now;
        TestCaseWaitOutPool();
        System.DateTime endTime = System.DateTime.Now;
        string totalMs = (endTime - startTime).TotalMilliseconds.ToString();

        Debug.Log("Test case Without Pool take " + totalMs + "ms.");

        // with pool
        System.DateTime poolstartTime = System.DateTime.Now;
        TestCaseWithPool();
        System.DateTime poolendTime = System.DateTime.Now;
        string pooltotalMs = (poolendTime - poolstartTime).TotalMilliseconds.ToString();

        Debug.Log("Test case With Pool take " + pooltotalMs + "ms.");
    }

    void TestCaseWaitOutPool()
    {
        for (int j = 0; j < loopCount; j++)
        {
            for (int i = 0; i < prefabCount; i++)
            {
                //create prefab
                GameObject go = Instantiate(prefab);
                //set parent
                go.transform.parent = root;
                //add to list
                objects.Add(go);
            }
            for (int i = 0; i < prefabCount; i++)
            {
                GameObject.Destroy(objects[i]);
            }

            //destory prefab
            objects.Clear();
        }

    }

    void TestCaseWithPool()
    {
        for (int i = 0; i < loopCount; i++)
        {
            List<GameObject> objectsList = pool.GetObjects((int)prefabCount);
            pool.DestroyObjects(objectsList);
        }

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SimplePool : MonoBehaviour
{
    public Transform root;
    public GameObject prefab;
    public int size;

    List<GameObject> pooled;

    void Start()
    {
        pooled = new List<GameObject>();
        Prewarm();
    }
    void Prewarm()
    {
        PoolObjects(size);
    }

    List<GameObject> PoolObjects(int _amount)
    {
        List<GameObject> newPooled = new List<GameObject>();
        for (int i = 0; i < _amount; i++)
        {
            GameObject go = Instantiate(prefab);
            go.transform.parent = root;
            go.SetActive(false);
            newPooled.Add(go);
        }
        pooled.AddRange(newPooled);
        return newPooled;
    }

    public List<GameObject> GetObjects(int _amount)
    {
        List<GameObject> pooledObjects = pooled.FindAll(_go => !_go.activeSelf);
        if (pooledObjects.Count < _amount)
        {
            List<GameObject> newObjects = PoolObjects(_amount - pooledObjects.Count);
            pooledObjects.AddRange(newObjects);
            foreach (var go in pooledObjects)
            {
                go.SetActive(true);
            }
            return pooledObjects;
        }
        else
        {
            foreach (var go in pooledObjects)
            {
                go.SetActive(true);
            }
            return pooledObjects;
        }
    }

    public void DestroyObjects(List<GameObject> objects)
    {
        for (int i = 0; i < objects.Count; i++)
        {
            objects[i].SetActive(false);
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
Test case Without Pool take 226.1487ms.
UnityEngine.Debug:Log(Object)
TestPool:Start() (at Assets/TestPool.cs:26)
Test case With Pool take 58.0407ms.
UnityEngine.Debug:Log(Object)
TestPool:Start() (at Assets/TestPool.cs:34)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

時(shí)間從 226.1487ms 縮短到58.0407ms??纯窗?,這就是效率

7.Total 與 Self
在 Unity-Window-Profiler
Overview 里面的 Total,Self 觀察 百分百

using UnityEngine;
using System.Collections;

public class TestTime : MonoBehaviour {

    public GameObject prefab;

    void Start()
    {
        //self
        System.Threading.Thread.Sleep(2000);

        Create(); // others
    }

    void Create()
    {
        for (int i = 0; i < 10000; i++)
        {
            GameObject go = GameObject.Instantiate(prefab);
            GameObject.Destroy(go);
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 圖形與物理
    –美術(shù)資源
    對(duì)Mesh的優(yōu)化

打開Game場(chǎng)景Stats 觀察 Tris(三角形),Verts(頂點(diǎn)數(shù))
模型面數(shù)
在這里可以使用插件 Simple LOD可以生成更低的模型tris減少,但是模型會(huì)變得不清晰

using UnityEngine;
using System.Collections;

public class TestLod : MonoBehaviour {

    public float[] camDistance;
    public Mesh[] lod;
    SkinnedMeshRenderer skin;

    // Use this for initialization
    void Start () {

        skin = GetComponent<SkinnedMeshRenderer>();
    }

    // Update is called once per frame
    void Update () {

        int level = GetLevel();
        skin.sharedMesh = lod[level];
    }

    int GetLevel()
    {
        float distance = Vector3.Distance(transform.position,Camera.main.transform.position);
        for (int i = 0; i < camDistance.Length; i++)
        {
            if (distance < camDistance[i])
            {
                return i;
            }
        }
        return camDistance.Length;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

Material
SetPass Calls 在移動(dòng)平臺(tái)上最好不要超過(guò)60或者80,PC 300
2D UI 打包成圖集 減少setpass calls
3D 合并材質(zhì)
本質(zhì) 共享材質(zhì),壓縮材質(zhì)

Shader
Main Maps 越少越好
這里在推薦一個(gè)插件: shader Fore
使用 Mobile 使用 圖形化工具

粒子
數(shù)量 數(shù)量要限制
透明
材質(zhì) /shader 移動(dòng)端:SM2.0

–物理效果
1.鏡頭
Clipping Planes
Occlusion Culling 默認(rèn)勾上了。但是沒(méi)有任何效果
打開Window-Occlusion Culling 需要bake 一下
需要bake的東西,必須是Static
Smallers Occluder 擋住后面的東西,優(yōu)化做不好,就可能是負(fù)優(yōu)化
在Scene場(chǎng)景,選中攝像機(jī),可以設(shè)置Occlusion Culling是Edit或者Visualize。這個(gè)時(shí)候隨著鏡頭的移動(dòng),鏡頭中的物體就會(huì)動(dòng)態(tài)的顯示了。
從屏幕上看到的點(diǎn),都不會(huì)剔除掉的。
Unity 3專業(yè)版內(nèi)置了一個(gè)強(qiáng)大的 Occlusion Culling 插件 Umbra免費(fèi)的
2.光照
Bake and Probes
我們的目標(biāo)就是降低:SetPass Calls
Light 選則Bake光,使用靜態(tài)光。出現(xiàn)色差
設(shè)置:Scenes In Build Player Setting
找到Color Space 有 Linear(不支持移動(dòng)端) Gamma
缺點(diǎn):移動(dòng)的物體不會(huì)受到光照的影響。這個(gè)時(shí)候就需要?jiǎng)?chuàng)建光照探針了。Light-Light Probe Group.記錄靜態(tài)光照的效果。

3.碰撞
Collider盡可能簡(jiǎn)單
控制rigidbody數(shù)量
Rigidbody檢查方式,檢測(cè)間隔,Collision Detection 持續(xù)的。離散型的。

4.CheckList
Simple checklist to make your game faster
對(duì)于PC建筑(取決于目標(biāo)GPU)時(shí),請(qǐng)記住下面的200K和3M頂點(diǎn)數(shù)每幀。
如果你使用內(nèi)置著色器,從挑選的那些移動(dòng)或熄滅類別。他們?cè)诜且苿?dòng)平臺(tái)以及工作,但更復(fù)雜的著色器的簡(jiǎn)化和近似版本。
保持每個(gè)場(chǎng)景低的不同材料的數(shù)量,并共享不同的對(duì)象盡可能之間盡可能多的材料。
將Static非運(yùn)動(dòng)物體的屬性,以允許像內(nèi)部?jī)?yōu)化靜態(tài)批次。
只有一個(gè)(最好是定向)pixel light影響幾何體,而不是整數(shù)倍。
烘烤照明,而不是使用動(dòng)態(tài)照明。
盡可能使用壓縮紋理格式,以及超過(guò)32位紋理使用16位紋理。
避免使用霧在可能的情況。
使用遮擋剔除,以減少可見(jiàn)的幾何圖形的量和抽取呼叫中的有很多閉塞復(fù)雜靜態(tài)場(chǎng)景的情況。閉塞記撲殺設(shè)計(jì)你的水平。
使用包廂到“假”遙遠(yuǎn)的幾何體。
使用像素著色器或紋理組合搭配,而不是多遍方法有幾個(gè)紋理。
使用half精度變量在可能的情況。
盡量減少使用復(fù)雜的數(shù)學(xué)運(yùn)算,如的pow,sin并cos在像素著色器。
使用每個(gè)片段較少紋理。

  • 文件
    1.AssetBundle 創(chuàng)建 讀取
    設(shè)置Prefab。
    AssetBundle New:env/go
using UnityEngine;
using System.Collections;
using System;

public class TestAssetBundle : MonoBehaviour {

    public string path;
    public string file;

    // Use this for initialization
    void Start () {

        StartCoroutine( Load());
    }

    IEnumerator Load()
    {
        string _path = "file:///" + Application.dataPath + path;
        WWW www = WWW.LoadFromCacheOrDownload(_path,1);
        yield return www;

        AssetBundle bundle = www.assetBundle;
        AssetBundleRequest request = bundle.LoadAssetAsync(file);
        yield return request;

        GameObject prefab = request.asset as GameObject;
        Instantiate(prefab);

        //Clean
        bundle.Unload(false);
        www.Dispose();
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

2.移動(dòng)端打包優(yōu)化
縮減包體積
設(shè)置 Andriod player setting Optimlzation .NET2.0(完整版) .NET2.0 Subset(簡(jiǎn)化版)
Stripping Leve Disabled .Strip Assembies. Strip Byte Code(一般用這個(gè)就可以了) .Use Micro mscorlib

1.momo version
full
subset
2.stripping level
disabled
strip bute code
3.媒體文件
圖片 psd/png/jpg
音頻 ogg/mp3/wav
fbx 公用animationclip

3.跨平臺(tái)開發(fā)效率優(yōu)化
節(jié)省時(shí)間 utomate插件
Debug SRDebugger插件

–安裝包的優(yōu)化
–資源包的優(yōu)化
–工作流程的優(yōu)化

5.所有游戲都需要優(yōu)化嗎?

性能完美是我們追求的目標(biāo)
不同類型的游戲?qū)?yōu)化的側(cè)重點(diǎn)不一樣
優(yōu)化工作會(huì)占生命周期非常大的一部分

2. Profiler

這里要多查看 官網(wǎng)的API 在Manual 里面搜索 Profiler
Unity3D-Window-Profiler
Profiler window
CPU Usage Area
Rendering Area
Memory Area
Audio Area
Physics Profiler
GPU Area
觀察Profiler 窗口 測(cè)試代碼:

using UnityEngine;
using System.Collections;

public class BadExampleProfiler : MonoBehaviour {

    public GameObject cube;

    // Update is called once per frame
    void Update () {

        Loop ();
    }

    void Loop()
    {
        for (int i = 0; i < 100; i++) {
            float x = Random.Range (0,360f);
            float y = Random.Range (0,360f);
            float z = Random.Range (0,360f);
            Vector3 randomVector = new Vector3 (x,y,z);
            Object.Instantiate (cube, randomVector, Quaternion.Euler(randomVector));
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

3. 圖形優(yōu)化

4. 文件優(yōu)化

5. 結(jié)束

建立一套屬于自己的優(yōu)化方法
1.確定優(yōu)化目標(biāo) (幀數(shù))(卡頓)
2.選擇合適的工具(Profiler)(SRDebugger)
3.找到性能瓶頸(腳本)(圖形)(繞開)
4.無(wú)法解決(找手冊(cè))(問(wèn)google)(繞開)
5.經(jīng)常與團(tuán)隊(duì)溝通

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多