コガネブログ

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

2023-01-01から1年間の記事一覧

【Unity】マウスカーソルが子オブジェクトに入った時に親オブジェクトの OnPointerExit が呼び出されてしまう

概要 Unity 2022.1.23f1 だと、マウスカーソルが子オブジェクトに入った時に void IPointerExitHandler.OnPointerExit( PointerEventData eventData ) { // ... } 親オブジェクトの OnPointerExit が呼び出されてしまう マウスカーソルが子オブジェクトに入…

【Unity】FancyScrollView の Scroller をマウスホイールで操作しやすくするコンポーネントの例

ソースコード using FancyScrollView; using UnityEngine; using UnityEngine.EventSystems; namespace Kogane.Internal { [DisallowMultipleComponent] internal sealed class Example : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { //===…

【Unity】ColorPresetLibrary をスクリプトから操作する例

ソースコード using System; using System.Reflection; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; internal static class Example { [MenuItem( "Example/Hoge" )] private static void Hoge() { var colorPresetLibrary =…

【Python】error: subprocess-exited-with-error

概要 pip install chromedriver-binary==119.0.6045.105.0 上記のコマンドを実行したら error: subprocess-exited-with-error が発生してインストールに失敗する現象に遭遇した 上記のページで紹介されている通り CERT_PATH=$(python -m certifi) export SSL…

【Unity】AssetDatabase.CopyAsset は上書きコピーの時に GUID が変わってしまう

概要 if ( File.Exists( newPath ) ) { File.Copy( path, newPath, true ); } else { AssetDatabase.CopyAsset( path, newPath ); } ファイルが存在する場合は AssetDatabase.CopyAsset ではなく File.Copy を使用すれば GUID が変わってしまうことを一応防…

【Unity】UI で入れ子のスクロールを実装する時に使用するコンポーネント

ソースコード using System; using System.Linq; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Kogane.Internal { /// <summary> /// 入れ子のスクロールを実装する時に使用するコンポーネント /// 子の ScrollRect の代わり</summary>…

【Unity】Xcode 15 でビルドできるようにするエディタ拡張

ソースコード using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; namespace Kogane.Internal { /// <summary> /// Xcode 15 でビルドできるようにするエディタ拡張 /// Xcode の Build Settings の「Other Linker Flags」に「-ld_classi</summary>…

【Unity】An attribute list cannot appear here

概要 An attribute list cannot appear here Firestore 9.6.0 を使用している Unity プロジェクトを Xcode 15 でビルドしようとしたら上記のエラーが発生した 解決方法 Firestore を 10.0.0 以上にアップデートする アップデート可能であればアップデートす…

【Unity】Signing for "gRPC-C++-gRPCCertificates-Cpp" requires a development team.

概要 Signing for "gRPC-C++-gRPCCertificates-Cpp" requires a development team. Select a development team in the Signing & Capabilities editor. (in target 'gRPC-C++-gRPCCertificates-Cpp' from project 'Pods') Firebase を使用している Unity プ…

【Xcode】xcodebuild: error: Unable to find a destination matching the provided destination specifier:

概要 xcodebuild: error: Unable to find a destination matching the provided destination specifier: { generic:1, platform:iOS } Ineligible destinations for the "Unity-iPhone" scheme: { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos…

【Xcode】Xcode 15 でデバイスの一覧が表示されない場合

概要 Xcode 14 の場合 iOS Devices が表示される Xcode 15 の場合 iOS Devices が表示されない 対処方法 iOS 17 Simulator をインストールしたら表示されるようになった 参考サイト様

【Unity】PBXProject.GetUnityMainTargetGuid で NullReferenceException

概要 [PostProcessBuild] private static void OnPostProcessBuild ( BuildTarget buildTarget, string pathToBuiltProject ) { if ( buildTarget != BuildTarget.iOS ) return; var projectPath = PBXProject.GetPBXProjectPath( pathToBuiltProject ); var…

【Unity】Mac 用の古い Unity Hub を入手できるサイト

概要

【Unity】Mac で Unity Hub を 3.6 から 3.5 にダウングレードした

概要 Unity Hub を 3.6 にアップデートしたら 不要な列が追加されて見づらくなったり 組織を選択しないとプロジェクトを新規作成できなくなったりして使いづらかったので https://macdownload.informer.com/unity-hub/download/ 上記のページから 3.5.2 を入…

【Unity】DOTween の Tween で経過時間をずらす方法

概要 tween.Goto( 0.1f, andPlay: true ); // 経過時間をずらして再生 tween.Goto( 0.1f, andPlay: false ); // 経過時間をずらして停止 Goto 関数を使う

【C#】バージョン番号を管理する構造体の例

ソースコード using System.Linq; internal readonly struct VersionNumber { private readonly string m_version; public int Major { get; } public int Minor { get; } public int Patch { get; } public VersionNumber( string version ) { var array = …

【Unity】SharpZipLib を導入できる Unity 公式のパッケージ

概要 Package Manager の「Add package by name...」で com.unity.sharp-zip-lib と入力して「Add」を押すとインストールできる 使用例 using System.IO; using System.Text; using Unity.SharpZipLib.GZip; /// <summary> /// 文字列を gzip で圧縮・展開するクラス </summary>…

【Unity】Android ビルド時に Android Logcat が自動で起動しないようにする方法

概要 Android Logcat のウィンドウ左上の「Auto Run」をオフにする

【C#】配列やリストが null じゃなければ Concat する拡張メソッド

ソースコード public static IEnumerable<T> ConcatIfNotNull<T> ( this IEnumerable<T> self, IEnumerable<T> second ) { return second != null ? self.Concat( second ) : self ; }</t></t></t></t>

【C#】配列やリストが null なら空配列を返す拡張メソッド

ソースコード public static IEnumerable<T> EmptyIfNull<T>( this IEnumerable<T> self ) { return self ?? Array.Empty<T>(); }</t></t></t></t>

【C#】配列やリストの列数が指定した数になるまで値を追加する関数

ソースコード private static IEnumerable<T> FillToColumnCount<T> ( IEnumerable<T> self, int columnCount, T defaultValue = default ) { var i = 0; foreach ( var x in self ) { yield return x; i = ( i + 1 ) % columnCount; } if ( i == 0 ) yield break; fo</t></t></t>…

【Unity】Mismatched serialization in the builtin class 'Texture2D'. (Read 128 bytes but expected 160 bytes)

概要 Mismatched serialization in the builtin class 'Texture2D'. (Read 128 bytes but expected 160 bytes) ビルドしたアプリで上記のエラーが発生する現象に一度だけ遭遇した それ以降再現することがなかったため原因は不明

【Unity】LineRenderer.startColor と endColor を同時に設定する拡張メソッド

ソースコード /// <summary> /// 色を設定します /// </summary> public static void SetColor ( this LineRenderer self, in Color color ) { self.startColor = color; self.endColor = color; }

【Unity】Tilemap のタイルの数を返す拡張メソッド

ソースコード public static int GetTilesCount( this Tilemap self ) { var cellBounds = self.cellBounds; return self.GetTilesRangeCount( cellBounds.min, cellBounds.max ); }

【Unity】Tilemap.SetTile に時間がかかる場合

概要 複数回 Tilemap.SetTile を呼び出す必要がある場合は 代わりに Tilemap.SetTiles を使うと処理が速くなる 参考サイト様

【Unity】Sprite の不透明な部分にゲームオブジェクトを生成する例

参考サイト様 ソースコード(引用) using System; using System.Linq; using UnityEngine; public class Example : MonoBehaviour { public GameObject filler; public Vector2 fillerSize = Vector2.one * 0.5f; public Vector2 spacing = Vector2.one * 0…

【Unity】ランタイムで Texture の Read Write をオンにする例

概要 Texture の Read Write はランタイムでは変更できないが、 ランタイムで Texture を複製すれば、Read Write が Texture を使えるようになる ソースコード // 戻り値の Texture は不要になったら Destroy すること private static Texture2D DuplicateTe…

【Unity】Sprite の不透明な部分にのみオブジェクトを生成する例

概要 上記のサイト様で公開されているスクリプトを使うと Sprite の不透明な部分にのみオブジェクトを生成できる ソースコード(引用) using System; using System.Linq; using UnityEngine; public class Example : MonoBehaviour { public GameObject fil…

【Unity】LineRenderer で円を描画する例

ソースコード using UnityEngine; public sealed class CircleLineRenderer : MonoBehaviour { [SerializeField] private LineRenderer m_lineRenderer; // 円を描画するための LineRenderer [SerializeField] private float m_radius; // 円の半径 [Seriali…

【Unity】Tilemap.SetColor でタイルの色が変わらない場合

概要 m_tilemap.SetTile( position, m_tile ); m_tilemap.SetTileFlags( position, TileFlags.None ); m_tilemap.SetColor( position, m_color ); 上記のように SetColor 関数の直前に SetTileFlags 関数を呼び出したら色が反映されるようになった m_tilemap…