コガネブログ

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

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

【Unity】3D 空間に配置した TextMesh Pro に SpriteMask を適用する方法

概要 TextMesh Pro のマテリアルを選択して Stencil ID を 1、Stencil Comp を 3 にすることで ワールド空間に配置した TextMesh Pro に SpriteMask を適用できます Stencil ID を 0 にすると逆マスクになります 参考サイト様 You can use SpriteMask with T…

【Unity】3D Object の TextMesh Pro の色が正しく反映されない場合の対処方法

はじめに Vertex Color に設定した色より薄く表示される 3D Object の TextMesh Pro は Vertex Color に設定した色が 正しく反映されないことがあるのでその対処方法 目次 はじめに 目次 検証環境 対処方法1:TextMesh Pro を 3.2.0-pre.3 にアップデートす…

【Unity】ArgumentException: Can't save a Prefab instance

概要 PrefabUtility.SavePrefabAsset( prefab ); PrefabUtility.SavePrefabAsset でプレハブを保存しようとして ArgumentException: Can't save a Prefab instance 上記のエラーが発生する場合は PrefabUtility.SaveAsPrefabAsset( prefab, prefabPath ); Pr…

【Unity】Calling OnPostBuildPlayerScriptDLLs callbacks. For faster build speeds, consider not using this callback, as we don't need to copy assemblies to the staging area for the incremental player build otherwise.

概要 Calling OnPostBuildPlayerScriptDLLs callbacks. For faster build speeds, consider not using this callback, as we don't need to copy assemblies to the staging area for the incremental player build otherwise. ビルド時に上記のログが出力さ…

【Unity】マウスカーソルの場所に Tooltip を表示できるエディタ拡張

リポジトリ 使用例 using Kogane; using UnityEditor; public static class Example { [MenuItem( "Assets/Hoge" )] public static void Hoge() { TooltipWindow.Open( "ピカチュウ" ); } }

【Unity】JNI:GetAudioStreamVolume:java.lang.SecurityException: listen

概要 JNI:GetAudioStreamVolume:java.lang.SecurityException: listen Unity 2022.1.11f1 で Android ビルドしたところ アプリ起動直後に上記のエラーログが出力されていた 最新の Unity バージョンなら直っているようだったので Unity 2022.1.20f1 で Andro…

【Unity】Console ウィンドウに検索ボタンを表示するエディタ拡張

リポジトリ 使用例 Console ウィンドウで検索したいテキストを Project Settings で設定します 項目 内容 Button Text ボタンに表示するテキスト Filtering Text ボタンを押した時に検索欄に入力するテキスト未入力ならボタンを押した時に Button Text に設…

【Unity】The operation couldn't be completed. Unable to locate a Java Runtime.

概要 Gradle failed to fetch dependencies. Failed to run 'XXXX/UnityProject/Temp/PlayServicesResolverGradle/gradlew --no-daemon -b "XXXX/UnityProject/Temp/PlayServicesResolverGradle/PlayServicesResolver.scripts.download_artifacts.gradle" "-…

【Unity】FirebaseCppApp-9_6_0.bundle が 100 MB を超えており GitHub リポジトリに Push できない場合

概要 remote: error: See http://git.io/iEPt8g for more information. remote: error: File UnityProject/Assets/Firebase/Plugins/x86_64/FirebaseCppApp-9_6_0.bundle is 134.36 MB; this exceeds GitHub's file size limit of 100.00 MB remote: error: …

【Unity】Firebase を使っているプロジェクトの iOS ビルドで .xcworkspace ではなく .xcodeproj を生成する方法

概要 Unity メニューの「Assets > External Dependency Manager > iOS Resolver > Settings」の 「Cocoapods Integration」を「Xcode Project~」にすると iOS ビルドで .xcworkspace ではなく .xcodeproj が生成されるようになる

【Unity】Execution failed for task ':launcher:processReleaseResources'.

概要 CommandInvokationFailure: Gradle build failed. C:\Program Files\Unity\Hub\Editor\2022.1.11f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2022.1.11f1\Editor\Data\Playback…

【Unity】Android で署名なしでビルドする時に使用されるデバッグ用の keystore の保存場所

概要 OS 場所 Mac /Users/【ユーザー名】/.android/debug.keystore Windows C:\Users\【ユーザー名】\.android\debug.keystore 参考サイト様 The unsigned debug keystore is located by default at ~/.android/debug.keystore on MacOS and %USERPROFILE%.a…

【Unity】iOS framework addition failed due to a CocoaPods installation failure. This will will likely result in an non-functional Xcode project.

概要 iOS framework addition failed due to a CocoaPods installation failure. This will will likely result in an non-functional Xcode project. After the failure, "pod repo update" was executed and failed. "pod install" was then attempted aga…

【Unity】Android 13 で通知許可ダイアログを開く方法

Mobile Notifications を使う方法 Mobile Notifications 2.1.0 を使えば簡単に実装できる Mobile Notifications 2.1.0 を使用して Android 13 で通知許可ダイアログを開く方法は上記のページの 「Request permission to post notifications」に記載されてい…

【Unity】Android 13 で通知許可ダイアログを開く時に無限ループが発生してしまう場合

概要 Mobile Notifications 2.1.0 を使用して Android 13 で通知許可ダイアログを開く時に 無限ループが発生してしまう場合、 「Project Settings > Player > Target API Level」を「API level 33」にしてから ビルドし直すと通知許可ダイアログが正常に開け…

【Unity】Notifications are not allowed for this application

はじめに Mobile Notifications を使用して iOS で通知許可ダイアログを表示しようとしたところ Notifications are not allowed for this application Requesting notification authorization failed with: Error Domain=UNErrorDomain Code=1 "Notification…

【Unity】iOS ビルド時に Xcode プロジェクトの Product Name を変更するエディタ拡張

ソースコード #if UNITY_IOS using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; internal static class Example { [PostProcessBuild] private static void OnPostProcessBuild ( BuildTarget buildTarget, string pathToBuilt…

【Unity】Inspector のコンポーネントのヘッダーにボタンを追加するエディタ拡張

リポジトリ 使用例 Remove Component Move Up / Move Down Copy Component / Paste Component Values

【Unity】EventSystem の情報をいつでも見られるようにする EditorWindow

リポジトリ 使用例 Unity メニューの「Window > Kogane > Event System Status」を選択すると EventSystem の情報をいつでも確認できるようになるため 現在どのオブジェクトをクリックしているかなどが常に確認できます

【Unity】Non-secure network connections disabled in Player Settings

概要 Non-secure network connections disabled in Player Settings System.Reflection.MethodBase:Invoke (object,object[]) Google.PortableWebRequest:StartRequest (Google.PortableWebRequest/HttpMethod,string,System.Collections.Generic.IDictionar…

【Unity】インスタンス ID からゲームオブジェクトやアセットを取得する方法

エディタ拡張の場合 var obj = EditorUtility.InstanceIDToObject( instanceId ); EditorUtility.InstanceIDToObject を使用する ランタイムの場合 public static Object FindObjectFromInstanceID( int instanceId ) { var type = typeof( Object ); var me…

【Unity】ObjectChangeEvents を使えば Unity エディタの様々なイベントを検知できる

概要 using UnityEditor; using UnityEngine; [InitializeOnLoad] public static class Example { static Example() { ObjectChangeEvents.changesPublished += ( ref ObjectChangeEventStream stream ) => { Debug.Log( "changesPublished" ); }; } } Objec…

【Git】git submodule foreach でエラーが発生しても foreach を続ける方法

概要 git submodule foreach git pull origin main たとえばすべてのサブモジュールを origin/main の最新に更新するために 上記のコマンドを実行した場合、origin/main が存在しないサブモジュールがあると そこで foreach の処理が止まってしまう git subm…

【Git】すべてのサブモジュールを origin/master もしくは origin/main の最新に更新するコマンド

概要 git submodule foreach 'git pull origin master || :' git submodule foreach 'git pull origin main || :' 参考サイト様

【C#】配列やリストの要素がすべて同じかどうか確認する方法

C#

概要 using System.Linq; using UnityEngine; public class Example : MonoBehaviour { private void Awake() { var list1 = new[] { 1, 2, 3 }; var list2 = new[] { 1, 1, 1 }; Debug.Log( list1.Distinct().Count() == 1 ); // False Debug.Log( list2.Di…

【Unity】MenuItem でも Event.current を取得できる関数

ソースコード private static Event GetEventCurrent() { var fieldInfo = typeof( Event ).GetField ( name: "s_Current", bindingAttr: BindingFlags.Static | BindingFlags.NonPublic ); return ( Event )fieldInfo.GetValue( null ); } 参考サイト様

【Unity】デフォルトのオプションを指定できる System.Text.Json.JsonSerializer

リポジトリ 使用例 using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.Unicode; using UnityEngine; public sealed class Example : MonoBehaviour { private void Awake() { JsonSeriali…

【Unity】Inspector で Color 型を右クリックした時のメニューを追加するエディタ拡張

リポジトリ 使用例

【Unity】チェックボックス付きのリストで項目を複数選択できる EditorWindow

リポジトリ 使用例 using System.Linq; using Kogane; using UnityEditor; using UnityEngine; public static class Example { private sealed class Data : ICheckBoxWindowData { public string Name { get; } public bool IsChecked { get; set; } public…

【Mac】確認ダイアログをキーボードで操作する方法

概要 「システム環境設定 > キーボード > ショートカット」を選択して 「コントロール間のフォーカス移動をキーボードで操作」をオンにする これでタブキーで確認ダイアログのボタンを選択できるようになる あとは Enter キーではなく Space キーを押すことで…