Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vector2Intの互換ライブラリが作りたかった話!

 Vector2Intの互換ライブラリが作りたかった話!

2017/12/09 (土) 【年末だよ】Unity お・と・な のLT大会 2017【ポロりしてもいいのよ】

の @RyotaMurohoshi の資料です。

RyotaMurohoshi

December 09, 2017
Tweet

More Decks by RyotaMurohoshi

Other Decks in Technology

Transcript

  1. [Serializable] public class Player { [SerializeField] int hp; [SerializeField] string

    name; } [Serializable] public class Enemy { [SerializeField] int hp; [SerializeField] string name; }
  2. Player => Enemy ΁䨗ͣ䟵͞ class CharacterContainer : MonoBehaviour { //

    䨗ͣ䟵͞ : [SerializeField] Player character; [SerializeField] Enemy character; }
  3. Dummy => Vector2Int ΁䨗ͣ䟵͞ class Example : MonoBehaviour { //[SerializeField]

    Dummy position; [SerializeField] Vector2Int position; }
  4. #if !UNITY_2017_2_OR_NEWER namespace UnityEngine { [System.Serializable] public struct Vector2Int {

    [SerializeField] int x; [SerializeField] int y; // ኼ } } #endif
  5. ͩ΢ͶΗѺѺѺ #if !UNITY_2017_2_OR_NEWER namespace UnityEngine { [System.Serializable] public struct Vector2Int

    { // ϢΰЄϸϖ [SerializeField] int x; [SerializeField] int y; // ኼ } } #endif
  6. 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; }} }
  7. 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; }} }
  8. 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; }} }
  9. ͩΩ΀䱛ᚆ΅΀͚ͧ΢Ϳ̵͘͹͵ΟΞ͡͹͵ [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; }} }
  10. // 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);