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
Vector2Intの互換ライブラリが作りたかった話!
Search
RyotaMurohoshi
December 09, 2017
Technology
0
950
Vector2Intの互換ライブラリが作りたかった話!
2017/12/09 (土) 【年末だよ】Unity お・と・な のLT大会 2017【ポロりしてもいいのよ】
の @RyotaMurohoshi の資料です。
RyotaMurohoshi
December 09, 2017
Tweet
Share
More Decks by RyotaMurohoshi
See All by RyotaMurohoshi
Unityの合同同人誌や合同商業誌を書いてる僕は感想やレビューや評価が欲しい
ryotamurohoshi
0
420
Unity 2021.1での Unityパッケージの名称変更について
ryotamurohoshi
0
650
Odin Validationはいいぞ!
ryotamurohoshi
2
880
Tilemapはいいぞ!2020 〜すごいぞ、プロジェクト専用拡張Brush〜
ryotamurohoshi
0
2.3k
Unityでも、新しいC#
ryotamurohoshi
0
1.2k
Riderはいいぞ!
ryotamurohoshi
1
3.3k
Riderのススメ〜俺はRiderここが好き〜
ryotamurohoshi
1
2.3k
Unity開発者に伝えたい.NETのこと
ryotamurohoshi
4
36k
ImportedLinqのススメ
ryotamurohoshi
0
1.3k
Other Decks in Technology
See All in Technology
Work as an App Engineer
lycorp_recruit_jp
0
350
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
140
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
290
DUSt3R, MASt3R, MASt3R-SfM にみる3D基盤モデル
spatial_ai_network
2
240
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
5
570
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
790
TypeScript開発にモジュラーモノリスを持ち込む
sansantech
PRO
2
560
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
500
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
190
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
3
1.4k
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
3
280
AWS環境におけるランサムウェア攻撃対策の設計
nrinetcom
PRO
0
150
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
510
110k
It's Worth the Effort
3n
183
28k
KATA
mclloyd
29
14k
Six Lessons from altMBA
skipperchong
27
3.5k
Testing 201, or: Great Expectations
jmmastey
41
7.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Done Done
chrislema
182
16k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
1
110
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Transcript
Vector2Int΄䟵϶αϣ϶Ϸ֢͢Π͵͡͵扖Ѻ @RyotaMurohoshi 2017/12/09 (ࢿ) ̓ଙ๛ͶΞ̈́Unity ͠独;独 ΄LTय़տ 2017̓ϪϺΠͭͼΘ͚͚΄Ξ̈́
@RyotaMurohoshi
Unity 2017.2ͽ Vector2IntࣳͿ ݱ圵Intᔮ䯤᭜᭄֛͢ےѺ 托ͭͥ΅ͩͩΨ憎ͼ : h$ps:/ /qiita.com/RyotaMurohoshi/items/4341f51548d8c53559f5
Vector2Int : Vecotr2΄intᇇ Vector2Int positon = new Vector2Int(3, 2); int
x = position.x; int y = position.y;
ΘͷΣΩSerializeΘͽͣΡ public class Example : MonoBehaviour { [SerializeField] Vector2Int position;
}
ΘͷΣΩSerializeΘͽͣΡ
̵ͩΘ;ͥΑͭ͡͵
ͳ͜Ͷ
Vector2Int;͡΄Intᔮ䯤᭜̵֛͢ Unity 2017.2΄ڹͽΘֵ͞ͼ䟵͘͢ͼ̵ ͳ΄ΔΔྋ憒΄ΚͺᑏᤈͽͣΡ϶αϣ϶ϷΨ֢Σ͜Ѻ
Vector2Int΄䟵϶αϣ϶Ϸ֢͢Π͵͡͵扖Ѻ @RyotaMurohoshi 2017/12/09 (ࢿ) ̓ଙ๛ͶΞ̈́Unity ͠独;独 ΄LTय़տ 2017̓ϪϺΠͭͼΘ͚͚΄Ξ̈́
֢̿Π͵͡͵扖̀ ֢̿͵扖̀ͽ΅͚
ͩ΅Vector2Int΄䟵϶αϣ϶ϷΨ֢Σ͜; ᝒ櫞ፗᶎ̵ͭૡॢͭ㪥Π̵᩼͞ͳͭͼগ㶧ͭ͵̵ͳΩ扖
Vector2Int΄䟵϶αϣ϶Ϸ 䟵ͼ͚ͼΘ͚Σ͚Σ͘ΡΞ
ϊЄφπЄϖAPI䟵 (㵛ಋݷ) • UnityEngine.Vector2Intͼྋ憒;ݶͮݷڹ独APIΨ೮ͺ • UNITY_2017_2_OR_NEWERΨֵ͚Unity 2017.2ڹ΄Ε䌏䖕 • Unity 2017.2ίϐϤϔЄϕͭͼΘ̵䟵䯤᭜֛Ψֵ͜πЄϖ
΅֜Θ䄜ͥ͞ͼΘ͚͚Ξͭ͜͵͚
τϷί϶αχ䟵 (㵛ಋݷ) Unity 2017.2ڹͽ̵䟵϶αϣ϶ϷΨτϷί϶αχ Unity 2017.2ϤϺυδμϕΨίϐϤϔЄϕͽͭ͵䦒̵ ڹτϷί϶αχͭ͵㮔Ψͳ΄ΔΔֵ͞ΡΞͭ͜͵͚
ϊЄφπЄϖAPI䟵 τϷί϶αχ䟵 ͩ΄2ͺΨΩ;ͯ͡Ρ΄ᝒ㴼ͭ͵
͘ΩΔΠᒈ͵͚ Unityͧ͠ΡτϷί϶αχTIPS
[Serializable] public class Player { [SerializeField] int hp; [SerializeField] string
name; }
class CharacterContainer : MonoBehaviour { [SerializeField] Player character; }
None
τЄЀϢήαϸ(*.unity独YAML୵ୗ)ͽ̵ ͩΩఽͮͽτϷί϶αχͫΡ Playerࣳͽ͘Ρఘ䁭΅ͿͩΘτϷί϶αχ͚ͫ character: hp: 300 name: "Yusha"
[Serializable] public class Player { [SerializeField] int hp; [SerializeField] string
name; } [Serializable] public class Enemy { [SerializeField] int hp; [SerializeField] string name; }
Player => Enemy 䨗ͣ䟵͞ class CharacterContainer : MonoBehaviour { //
䨗ͣ䟵͞ : [SerializeField] Player character; [SerializeField] Enemy character; }
None
τЄЀϢήαϸ(*.unity独YAML୵ୗ)ͽ̵ ͩΩఽͮͽτϷί϶αχͫ͵ΔΔѺѺѺ character: hp: 300 name: "Yusha"
τЄЀϢήαϸ(*.unity独YAML୵ୗ)ͽ΅̵ τϷί϶αχͫΡϢΰЄϸϖ(΄ࣳ;ݷڹ)͢ݶͮΟ ࣳᛔ֛͢䄜ΥͼΘ䟵͘͢Ρ
ͽ̵Vector2Int
Vector2Int΅τЄЀϢήαϸ(*.unity独YAML୵ୗ)ͽ̵ ͩΩఽͮͽτϷί϶αχͫΡ position: {x: 1, y: 3}
嘦扯Ѻ
[Serializable] public struct Dummy { [SerializeField] int x; [SerializeField] int
y; }
class Example : MonoBehaviour { [SerializeField] Dummy position; }
None
τЄЀϢήαϸ(*.unity独YAML୵ୗ)ͽ̵ ͩΩఽͮͽτϷί϶αχͫΡ position: x: 1 y: 3
Dummy => Vector2Int 䨗ͣ䟵͞ class Example : MonoBehaviour { //[SerializeField]
Dummy position; [SerializeField] Vector2Int position; }
None
τЄЀϢήαϸ(*.unity独YAML୵ୗ)ͽ̵ ͩΩఽͮͽτϷί϶αχͫΡ position { x: 1, y: 3 }
䟵϶αϣ϶ϷΘྋ憒΄Vector2Int;ݶ䯭̵ int΄x;yΨτϷί϶αχͽͣΆ͚͚Ѻ
#if !UNITY_2017_2_OR_NEWER namespace UnityEngine { [System.Serializable] public struct Vector2Int {
[SerializeField] int x; [SerializeField] int y; // ኼ } } #endif
SerializeField͢ͺ͚ͼΡ ϢΰЄϸϖ x独yΨਧ嬝 ͩΩఽͮͽ͚ͧΡѺ
͚͚ͧѺѺѺѺ
ͩͶΗѺѺѺ #if !UNITY_2017_2_OR_NEWER namespace UnityEngine { [System.Serializable] public struct Vector2Int
{ // ϢΰЄϸϖ [SerializeField] int x; [SerializeField] int y; // ኼ } } #endif
API䟵ጱ΅ͩͭ͜͵͚ Vector2Int positon = new Vector2Int(3, 2); // ϤϺϞϓΰ int
x = position.x; int y = position.y;
͚͚ͧ͢͡ 䶲͢՞ͣΔͭ͵Ҙ
ϊЄφπЄϖAPI䟵ጱ΅̵̿x̀ͼ̿ϤϺϞϓΰ̀͢ᥝ τϷί϶αχ䟵΅̵̿x̀ͼ̿ϢΰЄϸϖ̀͢ᥝ
C#ጱ΅ݶݷ΄ϢΰЄϸϖ;ϤϺϞϓΰΨϯϓ͚
ͺΩͶorz
x独y;͚͜ϢΰЄϸϖݷͽ͚;τϷί϶αχ΄䟵͢orz [System.Serializable] public struct Vector2Int { [SerializeField] int _x; public
int x { get { return _x; } set { _x = value; }} [SerializeField] int _y; public int y { get { return _y; } set { _y = value; }} }
x独y;͚͜ϤϺϞϓΰݷͽ͚;API΄䟵͢orz [System.Serializable] public struct Vector2Int { [SerializeField] int x; public
int X { get { return x; } set { x = value; }} [SerializeField] int y; public int Y { get { return y; } set { y = value; }} }
C#ͽ΅̵ݶӞ΄ݷڹ΄ϢΰЄϸϖ;ϤϺϞϓΰΨਧ嬝ͽ͚ͣ [System.Serializable] public struct Vector2Int { [SerializeField] int x; public
int x { get { return x; } set { x = value; }} [SerializeField] int y; public int y { get { return y; } set { y = value; }} }
ͺΩͶorz
τϷί϶αχݷ΅̵ϢΰЄϸϖݷͽͭ͡䷥ΗΟ͚ORZ FormerlySerializedAs΅አ᭔͢晅͜orz τϷί϶αχͯΡݷڹΨਧͯΡં͘͢Άorz
ͩΩ䱛ᚆ΅͚ͧͿ̵͘͵ΟΞ͡͵ [System.Serializable] public struct Vector2Iny { [SerializedAs("x")] // ͩΩఽͮͽݷڹΨਧͭ͵͡͵ [SerializeField]
int _x; public int x { get { return _x; } set { _x = value; }} [SerializedAs("y")] // ͩΩఽͮͽݷڹΨਧͭ͵͡͵ [SerializeField] int _y; public int y { get { return _y; } set { _y = value; }} }
ͺΩͶorz
橀(?)΄ṹ悬Ψֵ͚͞͡手ͭͼΕΡ
Mono.Cecil ILΨͪΝͪΝ䨗ͣ䟵̵͞ෛ͵DLLΨ֢Ρͩ;͢ͽͣΡ
Mono.CecilΨͺ͡ͼ xͼϢΰЄϸϖ;ϤϺϞϓΰΨݶ䦒೮ͼΡΞ͜ ϢΰЄϸϖݷΨ䨗ͣ䟵͞ෛ͵DLLΨ֢ΠڊͯѺ
ϤϺϞϓΰ΅πЀϞαϸͯΡ;ILጱ΅ get_x;͚͜Ϯϊϐϖ;set_x;͚͜Ϯϊϐϖ֢͢ΟΡ x;͚͜ݷڹ΄ϮЀϝ͢ͽͣΡΥͧͽ΅̶͚ [System.Serializable] public class PropertyExample { [SerializeField ]
int _x; public int x { get { return _x; } set { _x = value; } } }
̿C#̀ጱ΅NGͽΘ̿.NET̀ጱ΅ ݶݷ΄privateϢΰЄϸϖ;publicϤϺϞϓΰΨ֢Ρͩ;΅ݢᚆ
// Mono.CecilͽDLL΄Ӿ΄ࣳ΄قϢΰЄϸϖ΄ض毣΄`_`Ψ;͵ݷᑍ䄜ๅͯΡπЄϖ var targetAssembly = AssemblyDefinition.ReadAssembly(sourceAssemblyPath); foreach (var type in
targetAssembly.Modules.SelectMany(x => x.Types)){ foreach (var field in type.Fields) { var fieldReference = field.Module.Import(field); fieldReference.Name = fieldReference.Name.TrimStart('_'); } } sourceAssembly.Write(resultAssemblyPath);
C#ͽ΅ᔰፗ΅䨗͚ͧͧͿ x;͚͜private ϢΰЄϸϖ& public ϤϺϞϓΰ y;͚͜private ϢΰЄϸϖ& public ϤϺϞϓΰ ݶ䦒ΘͺDLLΨMono.Cecilͽ֢ΡѺ
㵛͵Ѻ
ͧͿͩΨͯΡ; UNITY_2017_2_OR_NEWERֵ͚͢͞
ͺΩͶorz
ϢΰЄϸϖ;ϤϺϞϓΰ΅㳨ͶͧͿ Θͩ͜ͽ͚͚͡ORZ [System.Serializable] public struct Vector2Int { public int x;
public int y; } ϤϺϞϓΰ;ϢΰЄϸϖ΅㳨Ͷ͡Ο̵͚ΚͶͧͿ
Δ;Η(;͚͜ݷ΄ݍ)
Vector2Int΄䟵϶αϣ϶Ϸ֢͢Π͵͡͵扖Ѻ
Vector2Int;͡΄䟵ࣳ ཿ͚ͭΞ
• ϢΰЄϸϖ;ͳ΄ࣳ͢ݶͮΟτϷί϶αχ䟵͘Π • SerialzieField͢τϷί϶αχݷΨਧͽͣΆ͚͚΄ORZ • Θͭͥ΅SerialzieAs͘͢Ά͚͚΄ORZ • Mono.CecilΨֵ͞Άݶݷ΄ϢΰЄϸϖ;ϤϺϞϓΰΨͺͥΡ
Θͩ͜ͽ͚͚͡ORZ [System.Serializable] public struct Vector2Int { public int x; public
int y; }
ਠҁͥΚ͚ͭѺ҂