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
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
310
Security_for_introducing_eBPF
kentatada
0
110
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
testcontainers のススメ
sgash708
1
120
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
110
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
Spatial Rendering for Apple Vision Pro
warrenm
0
110
Recoilを剥がしている話
kirik
5
6.9k
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
100
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Become a Pro
speakerdeck
PRO
26
5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Side Projects
sachag
452
42k
Scaling GitHub
holman
458
140k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Unsuck your backbone
ammeep
669
57k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
Raft: Consensus for Rubyists
vanstee
137
6.7k
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