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
930
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
370
Unity 2021.1での Unityパッケージの名称変更について
ryotamurohoshi
0
630
Odin Validationはいいぞ!
ryotamurohoshi
2
860
Tilemapはいいぞ!2020 〜すごいぞ、プロジェクト専用拡張Brush〜
ryotamurohoshi
0
2.3k
Unityでも、新しいC#
ryotamurohoshi
0
1.2k
Riderはいいぞ!
ryotamurohoshi
1
3.2k
Riderのススメ〜俺はRiderここが好き〜
ryotamurohoshi
1
2.2k
Unity開発者に伝えたい.NETのこと
ryotamurohoshi
4
36k
ImportedLinqのススメ
ryotamurohoshi
0
1.3k
Other Decks in Technology
See All in Technology
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
170
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
190
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
580
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
Terraform Stacks入門 #HashiTalks
msato
0
350
Engineer Career Talk
lycorp_recruit_jp
0
160
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
7
820
Featured
See All Featured
RailsConf 2023
tenderlove
29
900
Teambox: Starting and Learning
jrom
133
8.8k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Making Projects Easy
brettharned
115
5.9k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
What's in a price? How to price your products and services
michaelherold
243
12k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Become a Pro
speakerdeck
PRO
25
5k
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; }
ਠҁͥΚ͚ͭѺ҂