コガネブログ

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

【Unity】FancyGridView で要素の行数を取得する方法

概要 private int Rows => ( DataCount - 1 ) / startAxisCellCount + 1; FancyGridView を継承したクラスで上記のようなコードを記述することで 行数を取得できる

【Unity】FancyScrollRect でスクロール位置をリセットする時に位置がズレる場合

概要 FancyScrollRect のスクロール位置をリセットするために UpdatePosition( 0 ); 上記の処理を呼び出したら、要素の行数によって リセット後のスクロール位置がズレる現象に遭遇した Scroller.Position = 0; 上記の処理に書き換えたらズレることはなくな…

【Unity】FancyScrollRect のスクロールを止める方法

概要 FancyScrollRect のスクロールの速度は Scroller クラスの velocity で管理されているが velocity は private なので外部から操作できない /// <summary> /// 現在のスクロール位置. /// </summary> /// <value></value> public float Position { get => currentPosition; set { autoScrol…

【Unity】Unity エディタのフォントサイズを変更できる「EditorFontSize」紹介

はじめに https://gist.github.com/nukadelic/47474c7e5d4ee5909462e3b900f4cb82 「EditorFontSize」を Unity プロジェクトに導入することで Unity エディタのフォントサイズを変更できるようになります 使用例

【Unity】文字列が変数名に使用できるか確認する方法

概要 using System.CodeDom.Compiler; using UnityEditor; using UnityEngine; public static class Example { [MenuItem( "Tools/Hoge" )] private static void Hoge() { var provider = CodeDomProvider.CreateProvider( "C#" ); Debug.Log( provider.IsVa…

【Unity】エディタのツールバーとステータスバーを非表示にできる「Editor-View-Modules」紹介

概要 「Editor-View-Modules」を Unity プロジェクトに導入することで エディタのツールバーとステータスバーを非表示にできるようになります 使い方 Unity メニューの「View > Toolbars」の項目を選択すると エディタのツールバーとステータスバーを非表示…

【Unity】シンプルなバネの動きを実装できる「A minimal spring physics library for Unity」紹介

はじめに 「A minimal spring physics library for Unity」を Unity プロジェクトに導入することで シンプルなバネの動きを実装できるようになります 使用例 using UnityEngine; public class Example : MonoBehaviour { private UnitySpring.ClosedForm.Spr…

【Unity】NativeList や NativeArray の拡張メソッドが使える「com.bovinelabs.core」紹介

はじめに 「com.bovinelabs.core」を Unity プロジェクトに導入することで NativeList や NativeArray の拡張メソッドが使えるようになります NativeList の拡張メソッド https://gitlab.com/tertle/com.bovinelabs.core/-/blob/master/BovineLabs.Core/Exte…

【Unity】Job System で二次元配列が使えるようになる「Native Collections」紹介

はじめに 「Native Collections」を Unity プロジェクトに導入することで Job System で二次元配列が使えるようになります 使用例 using JacksonDunstan.NativeCollections; using Unity.Collections; using UnityEngine; public class Example : MonoBehavi…

【Unity】Unity Recorder 3.0.0 で GIF Animation Recorder は削除された

概要 [3.0.0-pre.1] - 2021-04-07 Removed legacy Recorders: MP4, EXR, PNG, WEBM and GIF Animation.

【Unity】UniTask の拡張メソッド

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

【Unity】プレハブの編集が簡単になる PrefabUtility.EditPrefabContentsScope

通常 [MenuItem( "Tools/Hoge" )] private static void Hoge() { var assetPath = ""; var prefabRoot = PrefabUtility.LoadPrefabContents( assetPath ); foreach ( var x in prefabRoot.GetComponentsInChildren<SpriteRenderer>() ) { Object.DestroyImmediate( x ); } Pr</spriterenderer>…

【Unity】Object.Instantiate の拡張メソッド

リポジトリ 使用例 using Kogane; using UnityEngine; public sealed class Example : MonoBehaviour { public GameObject m_prefab; private void Awake() { var r1 = m_prefab.Instantiate(); var r2 = m_prefab.Instantiate( Vector3.zero ); var r3 = m_…

【Unity】Console ウィンドウで等幅フォントを使用する方法

概要 Console ウィンドウは通常は上記のような見た目ですが Console ウィンドウのタブを右クリックして「Use Monospace font」を押すと 等幅フォントを使用した見た目になります

【Unity】Generated streamable assets list has XXXX asset names and extensions

概要 Generated streamable assets list has XXXX asset names and extensions. Having more than 600 values might cause building errors in exported project. Consider using distinct extentions for streaming assets (such that are not used by othe…

【Unity】adb: failed to install YYYY.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package ZZZZ signatures do not match previously installed version; ignoring!]

概要 CommandInvokationFailure: Unable to install APK to device. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details. /Applications/Unity/Hub/Editor/2022.1.23f1/PlaybackEn…

【Unity】Unknown error occurred while loading 'Assets/StreamingAssets/XXXX.prefab'.

概要 Unknown error occurred while loading 'Assets/StreamingAssets/XXXX.prefab'. UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:37) UnityEditor.AssetDatab…

【Unity】AudioClip の再生遅延を解消する方法

概要 Unity メニューの「Edit > Project Settings...」を選択して 「Audio > DSP Buffer Size」を「Best latency」にします

【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 を使用…