Skip to content

Instantly share code, notes, and snippets.

@mao-test-h
mao-test-h / EnableBackgroundAudio.mm
Last active October 1, 2021 18:45
Unity iOSビルドにてオーディオのバックグラウンド再生を行なう
#import <AVFoundation/AVFoundation.h>
@interface EnableBackgroundAudioWrapper : NSObject
+ (void)enableBackgroundAudio;
@end
@implementation EnableBackgroundAudioWrapper
+ (void)enableBackgroundAudio {
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
@mao-test-h
mao-test-h / NativeImageEncoder.mm
Created August 9, 2021 15:45
RenderTexture.GetNativeTexturePtr()からネイティブ側でpngに変換+保存
#import <Metal/Metal.h>
#import <UnityFramework/UnityFramework-Swift.h>
#ifdef __cplusplus
extern "C" {
#endif
// P/Invoke code.
// [DllImport("__Internal", EntryPoint = "encodeToPNG2")]
// static extern string EncodeToPNG(IntPtr nativeTexturePtr, string fileName);
@mao-test-h
mao-test-h / UIScreenBridge.cs
Last active May 7, 2021 20:48
Unity上からiOS端末の画面輝度を取得/設定
using System.Runtime.InteropServices;
using UnityEngine;
namespace iOSNative
{
/// <summary>
/// `UIScreen`のBridge
/// </summary>
/// <remarks>
/// - https://developer.apple.com/documentation/uikit/uiscreen
@mao-test-h
mao-test-h / AVAudioSessionBridge.cs
Last active May 7, 2021 20:26
Unity上からiOS端末のシステムボリュームを取得する
using System.Runtime.InteropServices;
namespace iOSNative
{
/// <summary>
/// `AVAudioSession`のBridge
/// </summary>
/// <remarks>
/// - https://developer.apple.com/documentation/avfaudio/avaudiosession
/// </remarks>
@mao-test-h
mao-test-h / UITraitCollectionBridge.cs
Last active May 7, 2021 20:16
Unity上からiOS端末のダークモード判定を行う
using System.Runtime.InteropServices;
namespace iOSNative
{
/// <summary>
/// `UITraitCollection`のBridge
/// </summary>
/// <remarks>
/// - https://developer.apple.com/documentation/uikit/uitraitcollection
/// </remarks>
@mao-test-h
mao-test-h / ProcessInfoBridge.cs
Last active May 7, 2021 20:09
Unity上からiOS端末の発熱状態を取得する
using System.Runtime.InteropServices;
namespace iOSNative
{
/// <summary>
/// `ProcessInfo`のBridge
/// </summary>
/// <remarks>
/// - https://developer.apple.com/documentation/foundation/processinfo
/// </remarks>
@mao-test-h
mao-test-h / Native2DArray.cs
Last active December 31, 2020 05:15
Unityでのネイティブメモリ確保用のラッパー
using System;
using System.Runtime.InteropServices;
using Unity.Collections.LowLevel.Unsafe;
namespace Unity.Collections
{
/// <summary>
/// ネイティブメモリでの2次元配列のメモリ確保用ラッパー
/// </summary>
[NativeContainer]
@mao-test-h
mao-test-h / SourceEditorCommand.swift
Created December 10, 2020 20:03
Xcode Source Editor Extensionsを用いてprintメソッドの内容を全てもなふわすい〜とる〜むのURLに変更する為のEditor拡張
import Foundation
import XcodeKit
// このGistでは実装のコア部分である`SourceEditorCommand.swift`のみアップ (実装は適当)
// Xcode Source Editor Extensionsの導入に関しては以下を参照
//
// - Creating a Source Editor Extension
// https://developer.apple.com/documentation/xcodekit/creating_a_source_editor_extension
//
// - Xcode Source Editor Extension を使った Xcode プラグインの作り方
@mao-test-h
mao-test-h / FinalSword_LEVELUp_Effect.swift
Created July 19, 2020 22:22
ファイナルソードの「LEVEL Up」演出っぽい挙動をSwiftUIで再現
import SwiftUI
struct ContentView: View {
// Font
let fontSize: CGFloat = 90
// Animation
let startScale: CGFloat = 0.3
let endScale: CGFloat = 1.0
@mao-test-h
mao-test-h / CcacheSettings.cs
Created April 25, 2020 20:54
xcodeprojにccache向けの設定を適用するサンプル
#if UNITY_IOS
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
namespace Samples
{
static class CcacheSettings
{