LoginSignup
0
0

More than 3 years have passed since last update.

UnityでiOS向けにC系の関数を扱う

Last updated at Posted at 2020-10-19

概要

UnityからC言語を使う為の備忘録です。

参考

実装

名前空間

using System.Runtime.InteropServices;

[DllImport("__Internal")] を使用するのに必要です。

属性

[DllImport("__Internal")] 

メソッドの上に書く。

サンプル

/// <summary>
/// 初期化
/// </summary>
[DllImport("__Internal")]
static extern void InitializeiOS(string hogehoge);

iOSでしか機能しないので「UNITY_IOS」などのシンボルを活用すると尚良い。

C

extern "C"
{
    void InitializeiOS(char *hoge)
    {
        // 処理
    }
}

stringはcharのポインタで。

設置方法

基本的には「Assets/Plugin/iOS/XXXXX.mm」としてファイル名をつけて保存する。
ビルドするとそのままXcodeプロジェクト内部に保存される。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0