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
880
从 Swift 到机器学习
onevcat
2
920
iOS Dev - The Dark Side
onevcat
0
120
面向协议编程与 Cocoa 的邂逅
onevcat
14
4.7k
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
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
flutterkaigi_2024.pdf
kyoheig3
0
150
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Jakarta EE meets AI
ivargrimstad
0
710
Functional Event Sourcing using Sekiban
tomohisa
0
100
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1k
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
CSC509 Lecture 11
javiergs
PRO
0
180
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.6k
What's new in Ruby 2.0
geeforr
343
31k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Cult of Friendly URLs
andyhume
78
6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
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