コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

2023-02-01から1ヶ月間の記事一覧

【Unity】No cloud project ID was found by the Analytics SDK.

概要 No cloud project ID was found by the Analytics SDK. This means Analytics events will not be sent. Please make sure to link your cloud project in the Unity editor to fix this problem. Unity 2018 で作られたプロジェクトを Unity 2022.1 に…

【Unity】NativeArray で Reverse を使えるようにする拡張メソッド

ソースコード using Unity.Collections; namespace Kogane { public static class NativeArrayExtensionMethods { public static void Reverse<T>( this NativeArray<T> self ) where T : unmanaged { var halfLength = self.Length / 2; var i = 0; var j = self.</t></t>…

【Unity】The property database "Library/Search/propertyDatabase.db" is already opened.

概要 The property database "Library/Search/propertyDatabase.db" is already opened. UnityEditor.EditorApplication:Internal_InvokeTickEvents () The property database "Library/Search/propertyAliases.db" is already opened. UnityEditor.EditorAp…

【Unity】Building Library/Bee/artifacts/Android/19qtv/libil2cpp.so failed with output:

概要 Building Library/Bee/artifacts/Android/19qtv/libil2cpp.so failed with output: /Applications/Unity/Hub/Editor/2022.1.23f1/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/../sysroot/usr/lib/aarch64-linux-and…

【Unity】ArgumentException: source and destination length must be the same

概要 nativeArray.CopyFrom( array ); NativeArray.CopyFrom を使用した時に ArgumentException: source and destination length must be the same Unity.Collections.NativeArray`1[T].CheckCopyLengths (System.Int32 srcLength, System.Int32 dstLength) …

【Unity】DllNotFoundException: Unable to load DLL 'FirebaseCppApp-9_6_0'.

概要 DllNotFoundException: Unable to load DLL 'FirebaseCppApp-9_6_0'. Tried the load the following dynamic libraries: Unable to load dynamic library 'FirebaseCppApp-9_6_0' because of 'Failed to open the requested dynamic library (0x0600000…

【Unity】NativeList で Reverse を使えるようにする拡張メソッド

ソースコード using Unity.Collections; namespace Kogane { public static class NativeListExtensionMethods { public static void Reverse<T>( this NativeList<T> self ) where T : unmanaged { var halfLength = self.Length / 2; var i = 0; var j = self.Le</t></t>…

【Unity】(0,0): Burst error BC0101: Unexpected error while processing function `XXXX.Unity.Jobs.IJob.Execute(XXXX* this) -> void_48866e3ad5c81254d9a4276b3d04e704 from YYYY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null`: System.NullReferenceExceptio

概要 【Unity プロジェクト】\Library\PackageCache\com.unity.burst@1.7.4\.Runtime\bcl.exe exited after 980 ms. Unexpected error while processing function `XXXX.Unity.Jobs.IJob.Execute(XXXX* this) -> void_48866e3ad5c81254d9a4276b3d04e704 from…

【Unity】System::InvalidOperationException: The UNKNOWN_OBJECT_TYPE has been declared as [WriteOnly] in the job, but you are reading from it.

概要 System::InvalidOperationException: The UNKNOWN_OBJECT_TYPE has been declared as [WriteOnly] in the job, but you are reading from it. This Exception was thrown from a job compiled with Burst, which has limited exception support. Job Sy…

【Unity】2022.2 新機能 - ログのスタックトレースから関数を除外できるようになった

概要 using UnityEngine; public class Example : MonoBehaviour { private void Awake() => Log1(); [HideInCallstack] private void Log1() => Log2(); [HideInCallstack] private void Log2() => Log3(); [HideInCallstack] private void Log3() => Log4(…

【Unity】System.InvalidOperationException: Jobs can only create Temp memory

概要 public struct Example : IJob { void IJob.Execute() { var list = new NativeList<int>( Allocator.Persistent ); } } 上記のように IJob.Execute の中で Allocator.Persistent を指定して NativeList を生成したら System.InvalidOperationException: Job</int>…

【Unity】(0,0): Burst error BC1045: Struct `XXXX&` with auto layout is not supported

概要 (0,0): Burst error BC1045: Struct `XXXX&` with auto layout is not supported IJob インターフェイスを実装する構造体を定義した際に 上記のエラーが発生する現象に遭遇した public (int, int) value { get; set; } 上記のように ValueTuple を使用…

【Unity】NativeHashMap が見つからない場合

概要 Package Manager で「Collections」パッケージをインストールすると使えるようになる

【Unity】ゲームオブジェクトが依存しているアセットを確認できる「WhatUsesThisInScene」紹介

概要 「WhatUsesThisInScene」を Unity プロジェクトに導入することで ゲームオブジェクトが依存しているアセットを確認できるようになります 使い方 Hierarchy でゲームオブジェクトを右クリックして 「What uses this in the scene?」を選択すると ゲーム…

【Xcode】xcodebuild で使用する Xcode のバージョンを設定する方法

概要 # 現在のバージョンを確認 xcode-select -print-path # バージョンを設定 xcode-select -switch /Applications/Xcode.app/Contents/Developer 補足 xcode-select: error: --switch must be run as root (e.g. `sudo xcode-select --switch <xcode_folder_path>`). もし上記</xcode_folder_path>…

【Unity】iOS / Android で音声合成(TextToSpeech)使用できる「Speech And Text in Unity iOS and Unity Android」紹介

概要 「Speech And Text in Unity iOS and Unity Android」を Unity プロジェクトに導入することで iOS / Android で音声合成(TextToSpeech)使用できるようになります 使い方 using TextSpeech; using UnityEngine; public class Example : MonoBehaviour …

【Unity】Ease を AnimationCurve で使用できる「Unity-EasingAnimationCurve」紹介

概要 「Unity-EasingAnimationCurve」を Unity プロジェクトに導入することで Ease を AnimationCurve で使用できるようになります 使い方 GitHub リポジトリに含まれている「EasingFunctions.curves」を Unity プロジェクトの Editor フォルダに追加します …

【Unity】特定の Android 端末で Audio がすごくスローで再生される場合

概要 Unity で作成した Android アプリを「arrows Tab F-02K」にインストールしたら Audio がすごくスローで再生される現象に遭遇した Unity の「Project Settings > Audio」で 「DSP Buffer Size」を「Best latency」から「Best performance」に変えたら 正…

【Unity】PolygonCollider2D をスプライトの形に動的に変更する方法

概要 using System.Collections.Generic; using UnityEngine; public class Example : MonoBehaviour { private void Awake() { var spriteRenderer = GetComponent<SpriteRenderer>(); var sprite = spriteRenderer.sprite; var polygonCollider2D = GetComponent<PolygonCollider2D>(); var ph</polygoncollider2d></spriterenderer>…

【C#】ラムダ式で入力参照渡しの引数を受け取る方法

C#

概要 private delegate void Delegate( in Vector2 position ); private void Run( Delegate deletgate ) { deletgate += ( in Vector2 position ) => Debug.Log( position ); } 引数が入力参照渡しであることを明示的に記述する必要がある

【Unity】インスタンス ID から GUID を取得する方法

概要 if ( AssetDatabase.TryGetGUIDAndLocalFileIdentifier( instanceId, out var guid, out long localId ) ) { Debug.Log( guid ); Debug.Log( localId ); } AssetDatabase.TryGetGUIDAndLocalFileIdentifier を使用する

【Unity】ドッキングされた EditorWindow で minSize が正常に動作するようにするエディタ拡張

リポジトリ 導入前 導入後

【Unity】iOS で消音モードでもオーディオを再生できるようにするクラス

リポジトリ 使用例 iOSSilentModePlayAudio.SetAudioSession(); 上記の関数を任意のタイミングで呼び出します

【Unity】IPointerClickHandler などで同時押しを無視する方法

概要 using UnityEngine; using UnityEngine.EventSystems; public class Example : MonoBehaviour, IPointerClickHandler { void IPointerClickHandler.OnPointerClick( PointerEventData eventData ) { if ( 0 < eventData.pointerId ) return; Debug.Log(…

【Unity】アセットを複製した時にファイル名の連番が正しく計算されるようにする方法

概要 ファイル名の末尾が数字のアセットを複製すると デフォルトでは上記のようになってしまうが Project Settings の「Editor > Space Before Number in Asset Names」をオフにすると ファイル名の連番が正しく計算されるようになります

【Unity】MonoBehaviour のすべてのメンバーを Obsolete で使えないようにする抽象クラス

リポジトリ 使用例 using Kogane; using UnityEngine; public class Example : ObsoleteMonoBehaviour { private void Start() { Debug.Log( name ); Debug.Log( enabled ); Debug.Log( transform ); Debug.Log( GetComponent<Transform>() ); } }</transform>

【Unity】UniTask.NextFrame を GameObject 型や Component 型の拡張メソッドで呼び出せるようにするパッケージ

リポジトリ 使用例 using System.Threading; using Cysharp.Threading.Tasks; using Kogane; using UnityEngine; public class Example : MonoBehaviour { private readonly CancellationTokenSource m_cancellationTokenSource = new(); private async UniT…

【Unity】UniTask.DelaySeconds を使えるようにするパッケージ

リポジトリ 使用例 Before using System; using Cysharp.Threading.Tasks; using UnityEngine; public class Example : MonoBehaviour { private async UniTaskVoid Start() { await UniTask.Delay( TimeSpan.FromSeconds( 1 ) ); } } After using System; u…

【Unity】Enter Play Mode で static 変数の初期化ができる Attribute「UnityDomainReloadHelper」紹介

概要 「Editor-View-UnityDomainReloadHelper」を Unity プロジェクトに導入することで Enter Play Mode で static 変数の初期化ができる Attribute を使えるようになります 使い方 using UnityEngine; public class Example : MonoBehaviour { // 0 で初期…

【Unity】Transform が変化したことを検知できる「TransformChanged helper」紹介

概要 「Editor-View-TransformChanged helper」を Unity プロジェクトに導入することで Transform が変化したことを検知できるようになります 使い方 using Needle.TransformExtensions; using UnityEngine; public class Example : MonoBehaviour { private…