Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Unity Memory
Search
Wei Wang
July 17, 2014
Programming
0
130
Unity Memory
How to optimize memory usage of Unity. Made for Unity team in Kayac.
Wei Wang
July 17, 2014
Tweet
Share
More Decks by Wei Wang
See All by Wei Wang
網路之難,難於上青天 - iPlayground 2019
onevcat
11
4.8k
GMTC 2019 - 在分歧中发展,2019 我们能用 Swift 做什么
onevcat
0
870
从 Swift 到机器学习
onevcat
2
910
iOS Dev - The Dark Side
onevcat
0
110
面向协议编程与 Cocoa 的邂逅
onevcat
14
4.6k
Swift 3 - From Expert to Beginner
onevcat
2
210
如何打造一个让人愉快的框架
onevcat
4
22k
JSPatch Introduction
onevcat
0
180
Objective-C Runtime Swizzle
onevcat
0
170
Other Decks in Programming
See All in Programming
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
14
3.8k
AWS IaCの注目アップデート 2024年10月版
konokenj
3
2.1k
WEBエンジニア向けAI活用入門
sutetotanuki
0
290
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
0
200
テスト駆動開発✅️
akitoshiga
1
210
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
530
Golang と Erlang
taiyow
8
1.8k
#pixiv小説画像メーカー はこうしてできた / The Making of the pixiv Novel Image Maker
roiban
0
220
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
180
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
0
210
Identifying User Idenity
moro
4
6.1k
ActiveRecordの力でDBのメタデータを迅速に解析する
lnit
5
2.2k
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
KATA
mclloyd
29
13k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Typedesign – Prime Four
hannesfritz
39
2.4k
Scaling GitHub
holman
458
140k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Being A Developer After 40
akosma
86
590k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Making Projects Easy
brettharned
115
5.9k
Transcript
Unity ϝϞϦʔ࠷దԽ Ԧቨ 2014-07-17
None
None
None
མͪΔ མͪΔ མͪΔ σʔλͷಡΈࠐΉ ॲཧ͍ͯ͠ͳ͍Τϥʔ ֎෦ϓϥάΠϯͷѱ͍ ϝϞϦʔΓͳ͍ ʁʁʁ େࣄͳ͜ͱ ͩΕͰ͔Δ͜ͱඞཁʂ
iPhone 4 iPhone 4s iPad mini: 512M iPhone 5Ҏ্: 1G
Androidେମ: 1Gɺ2G͋Δ ىಈ͢ΔͱɺγεςϜϝϞϦʔ͔͔Γ·͢ iOS 6 -> 70M Ϩϕϧ iOS 7 -> 200M Ϩϕϧ *iOS 7.1.2ʹվળग़དྷ·͕ͨ͠ɺ170M͙Β͍ ݁ɿϝϞϦʔҰ൪ݫ͍͠ͷ iPhone 4 ͱ iOS 7 (7.1.2Ҏ֎) ͷΈ߹ΘͤͰ͢
WHY ϝϞϦʔਃ ϝϞϦʔ͏ ऴΘͬͨ ϦϦʔε GC.Collect
Unity ϝϞϦʔཧϧʔϧ 1͔ͭ͋͠Γ·ͤΜʂ ࢀর͕͋Εɺ ϦϦʔεʢճऩʣͰ͖·ͤΜ
࠷ॳ͔ΒϝϞϦʔਖ਼͘͠༻ͷҙࣝΛ͍ͯɺ ϧʔϧΛकΕɺ࠷దԽͷ࡞ۀ͕؆୯ʹͳΒΕ·͢ʢͳ͠ʁʣ ͜ͱ͔͠Βɻɻɻ
ࢀরʁ ը૾ʢAtlasɼTextureɼSpriteͳͲʣ ԻʢSEɼBGMɼϘΠεͳͲʣ ΦϒδΣΫτʢεΫϦϓτɼModel dataʣ UnityͷΞηοτ C#
ࢀরྫ GameScene->Sprite(GameObject)-> UISprite->StartAltas(UIAtlas) ->StartAtlas(Material)->StartAtlas.png ϝϞϦʔҰ൪
NGྫ 1 ͍ͬͯͳ͍Sceneͱ͔ Destroyͯ͠ͳͯ͘ɺ SetActive false͚ͩ ͓͢͢Ίɿ͍ͬͯͳ͍ͷdestroyͯ͠ɺඞཁͳ࣌࠶Load ॏͯ͘ɺΑ͘͏ͷ͕CacheͰOK
NGྫ 2 Talk.cs private static OnComplete _onTalkComplete = null; public
static void Open(StoryData story, OnComplete onTalkComplete) { _story = story; _onTalkComplete = onTalkComplete; MakeATalk().Show(); } //Talk animation finished: public void OnTalkFinished() { if (_onTalkComplete != null) { _onTalkComplete(); } Destory(this) } Script.cs public void Go() { Talk.Open(story, ()=> { Debug.Log(“Talk finished”); }); } _onTalkComplete -> Script.cs -> Script GameObject -> ը૾ͱ͔
NGྫ 2 Talk.cs private OnComplete _onTalkComplete = null; public void
Open(StoryData story, OnComplete onTalkComplete) { _story = story; _onTalkComplete = onTalkComplete; Show(); } //Talk animation finished: public void OnTalkFinished() { if (_onTalkComplete != null) { _onTalkComplete(); } Destory(this) } Script.cs public void Go() { Talk t = new Talk(); t.Open(story, ()=> { Debug.Log(“Talk finished”); }); } ͓͢͢Ί staticඞཁͳ͍ͷɺstatic͠ͳ͍Ͱ staticɺ͘͠ singleton ཞ༻͠ͳ͍Ͱ
NGྫ 3 AssetBundle AssetBundle1 = AssetBundle.CreateFromFile("1.unity3d"); obj1.renderer.material.mainTexture = AssetBundle1.Load("wall") as
Texture; obj2.renderer.material.mainTexture = obj1.renderer.material.mainTexture; //… Destroy(obj1); Destroy(obj2); Assetͷࢀর͕ͳ͘ͳΔ͚Ͳɺ AssetBundle·ͩϦϦʔε͞Ε͍ͬͯͳ͍
NGྫ 3 AssetBundle AssetBundle1 = AssetBundle.CreateFromFile("1.unity3d"); obj1.renderer.material.mainTexture = AssetBundle1.Load("wall") as
Texture; obj2.renderer.material.mainTexture = obj1.renderer.material.mainTexture; //… Destroy(obj1); Destroy(obj2); AssetBundle1.Unload(true); //͔͔࣌ؒΓ·͢ Resources.UnloadUnusedAssets(); ը૾ϦϦʔεɺdelayͰେৎ
1 2 3 Profiler Window (Cmd+7) ։ൃͷ࣌ͪΐͬͱݟ͓ͯئ͍ https://www.youtube.com/watch?v=sBpXiJ9G3OY https://docs.unity3d.com/351/Documentation/Manual/Profiler.html
NGྫ 4 ϦʔΫͰͳ͍͚Ͳɺ GC AllocͰύʔϑΥʔϚϯεѱ͘ͳΔ public void Update() { GameController
controller = GetComponent<GameController>(); controller.Foo(); List<GameCharacter> characters = new List<GameCharacter>(); transform.parent = practiceControler.cardRoot; transform.localScale = initCardScale; transform.position = initCardPosition; }
NGྫ 4 public void Awake() { _cachedController = GetComponent<GameController>(); _characters
= new List<GameCharacter>(); _cachedTransform = transform; } public void Update() { _cachedController.Foo(); _characters.Clear(); _cachedTransform.parent = practiceControler.cardRoot; _cachedTransform.localScale = initCardScale; _cachedTransform.position = initCardPosition; } GameObject.Find ͳͲͷ୳͢method
GC Alloc ຖFrameɹϝϞϦʔਃͷྔ kbͷϨϕϧʹकΓ·͠ΐ͏ GC.Collect গͳ͘ͳΔɺύʔϑΥʔϚϯεΞοϓ
None