Code Monkey home page Code Monkey logo

unitynativeplugin-macos-arm64's Introduction

Unity Native PluginはiOSの場合にはソースコードをAssets/Plugins/iOSに入れますが、
macOSなどの場合はビルド済みのライブラリ(macOSではbundle)をつくる必要があります。
Editorで動かしたい場合などに必要となるのでXcodeでbundleのプロジェクトを新規作成します。

fig01

適当にコードを書きます。

#import <Cocoa/Cocoa.h>
NSWindow *win = nil;

extern "C" void onAwake() {
    if(win==nil) {
        dispatch_async(dispatch_get_main_queue(),^{
            win = [[NSWindow alloc] initWithContentRect:CGRectMake(0,0,960,540) styleMask:1 backing:NSBackingStoreBuffered defer:NO];
            [win makeKeyAndOrderFront:nil];
        });
    }
}
extern "C" void onDestroy() {
    if(win) {
        dispatch_async(dispatch_get_main_queue(),^{
            [win setReleasedWhenClosed:NO];
            [win close];
            win = nil;
        });
        
    }
}

ビルドするとbundleができるのでAssets/Plugins/に置きます。
GameObjectを作りBehaviourScriptをアタッチします。
作成したbundle名がTest.bundleだった場合にDllImportされる名称はTestになりますので、任意の名前に変更してください。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;

public class NewBehaviourScript : MonoBehaviour
{
	[DllImport ("Test")]
	private static extern void onAwake();

	[DllImport ("Test")]
	private static extern void onDestroy();

	void Awake() {
		onAwake();
	}

	void Start() {}
	void Update() {}

	void OnDestroy() {
		onDestroy();
	}
}

Editrで再生するとウィンドウが立ち上がります。
停止するとウィンドウが消えます。

unitynativeplugin-macos-arm64's People

Watchers

mizt avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.