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.9k
GMTC 2019 - 在分歧中发展,2019 我们能用 Swift 做什么
onevcat
0
900
从 Swift 到机器学习
onevcat
2
930
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
return文におけるstd::moveについて
onihusube
1
650
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
450
Symfony Mapper Component
soyuka
2
730
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
CSC305 Lecture 25
javiergs
PRO
0
130
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
200
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
良いユニットテストを書こう
mototakatsu
4
1.6k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
160
Criando Commits Incríveis no Git
marcelgsantos
2
170
Featured
See All Featured
Side Projects
sachag
452
42k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Why Our Code Smells
bkeepers
PRO
335
57k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Gamification - CAS2011
davidbonilla
80
5.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
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