コガネブログ

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

2022-11-01から1ヶ月間の記事一覧

【Unity】スプライト単色シェーダ

【Unity】Project ウィンドウに拡張子を表示するエディタ拡張

リポジトリ 使用例

【Unity】'AppsFlyerLib.h' file not found

概要 'AppsFlyerLib.h' file not found Unity で iOS ビルドしたら Xcode ビルド時に上記のエラーが発生する現象に遭遇した Xcode プロジェクトを削除してからビルドしたら正常にビルドできた

【Unity】PlayerPrefs.SetString と File.WriteAllText の速度比較

検証用コード using System.Diagnostics; using System.IO; using System.Text; using UnityEngine; using Debug = UnityEngine.Debug; public class Example : MonoBehaviour { private void Start() { const string data = "ピカチュウ"; const int count …

【Unity】マルチタッチの判定を無効化した Scroll Rect

リポジトリ 使用例 ScrollRect の代わりに SingleTouchScrollRect を使用します

【Unity】シーンが読み込まれているか確認する関数

ソースコード using System.Collections.Generic; using UnityEngine.SceneManagement; namespace Kogane { public static class KoganeSceneManager { public static bool IsLoaded( string sceneName ) { var sceneCount = SceneManager.sceneCount; for (…

【Unity】現在読み込まれているすべてのシーンを取得する関数

ソースコード using System.Collections.Generic; using UnityEngine.SceneManagement; namespace Kogane { public static class KoganeSceneManager { public static IEnumerable<Scene> GetAllScenes() { var sceneCount = SceneManager.sceneCount; for ( var i </scene>…

【Unity】iOS / Android でストアのレビュー依頼を表示できるパッケージ

リポジトリ 使用例 using Cysharp.Threading.Tasks; using Kogane; using UnityEngine; public sealed class Example : MonoBehaviour { private async UniTaskVoid Start() { var result = await StoreReview.RequestReviewAsync(); Debug.Log( result ); }…

【Unity】再生中の AudioClip を停止できるコンポーネント

リポジトリ 使用例 using Kogane; using UnityEngine; public sealed class Example : MonoBehaviour { [SerializeField] private StoppableAudioPlayer m_player; [SerializeField] private AudioClip m_audioClip; private void Start() { // 再生します v…

【Unity】UniTask.WhenAll に CancellationToken を渡したい場合

概要 using System; using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; public class Example : MonoBehaviour { private CancellationTokenSource m_cancellationTokenSource; private void Update() { if ( Input.GetKeyDown( K…

【Jenkins】変更がある場合にのみ git commit する方法

参考サイト様 その1 git diff --quiet && git diff --staged --quiet || git commit -am 'XXXX' その2 git commit -m "XXXX" || echo "No changes to commit"

【Unity】UniTaskCompletionSource と CancellationToken を組み合わせて使う方法

概要 using System; using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; public sealed class Example : MonoBehaviour { private readonly CancellationTokenSource m_cancellationTokenSource = new(); private async void Start…

【C#】TaskCompletionSource と CancellationToken を組み合わせて使う方法

C#

概要 using System; using System.Threading; using System.Threading.Tasks; using UnityEngine; public sealed class Example : MonoBehaviour { private readonly CancellationTokenSource m_cancellationTokenSource = new(); private async void Start(…

【Unity】AudioClip のイントロ付きループ再生ができるコンポーネント

リポジトリ 使用例 using Kogane; using UnityEngine; public sealed class Example : MonoBehaviour { [SerializeField] private IntroAudioPlayer m_player; [SerializeField] private AudioClip m_introAudioClip; [SerializeField] private AudioClip m_…

【Unity】Bundletool.BuildBundle だと extraScriptingDefines が反映されない?

概要 AppBundleBuilder.BuildAndroidPlayer を見てみたら 引数に渡された BuildPlayerOptions の extraScriptingDefines を使用していなかった PlayerSettings.SetScriptingDefineSymbolsForGroup なら正常に反映された ただし、SetScriptingDefineSymbolsFo…

【Unity】ビルド時に BuildPlayerOptions の情報を Resources フォルダのテキストファイルに書き込むエディタ拡張

リポジトリ 使用例 using System.Linq; using Kogane; using UnityEditor; public static class Example { [MenuItem( "Tools/Hoge" )] public static void Hoge() { const bool isReleaseBuild = false; var options = new BuildPlayerOptions { scenes = E…

【Unity】Device Simulator の internal な機能にアクセスできるパッケージ

リポジトリ 使用例 using Kogane; using UnityEditor; using UnityEngine; public static class Example { [MenuItem( "Tools/Hoge" )] private static void Hoge() { // Device Simulator で選択されているデバイスの名前を取得します Debug.Log( DeviceSim…

【Unity】ツールバーに Reload Assemblies をロックするかどうかを変更するボタンを追加するエディタ拡張

リポジトリ 使用例

【Git】fatal: You are on a branch yet to be born

概要 Reactivating local git directory for submodule 'XXXX' fatal: You are on a branch yet to be born fatal: unable to checkout submodule 'XXXX' サブモジュールを追加しようとしたら上記のエラーが発生する現象に遭遇した 「.git/modules/」フォル…

【Unity】Preferences の「Auto-save scenes before building」をスクリプトから参照する方法

概要 Debug.Log( EditorPrefs.GetBool( "SaveScenesBeforeBuilding", false ) ); 参考サイト様

【Unity】Preferences で設定した Android の External Tools のパスを取得する方法

概要 AndroidExternalToolsSettings を使えば取得できる Debug.Log( AndroidExternalToolsSettings.ndkRootPath ); Debug.Log( AndroidExternalToolsSettings.sdkRootPath ); Debug.Log( AndroidExternalToolsSettings.jdkRootPath ); Debug.Log( AndroidExt…

【Unity】GetComponentInChildren や GetComponentsInChildren で引数の型情報を文字列で渡せるようにする拡張メソッド

リポジトリ 使用例 using Kogane; using UnityEngine; public class Example : MonoBehaviour { private void Start() { var transform = gameObject.GetComponentInChildren( "Transform" ); var transforms = gameObject.GetComponentsInChildren( "Transf…

【Unity】Preferences の「Auto-save scenes before building」が保存されない問題がある

概要 Preferences の「Auto-save scenes before building」を有効にしてから Preferences を閉じて再度 Preferences を開いてみると 「Auto-save scenes before building」が無効になってしまう

【Unity】Play Asset Delivery を導入して Android ビルドしたら DllNotFoundException が発生

概要 DllNotFoundException: /data/app/~~EpCtMMU6o4jMa8tCi-kNiQ==/XXXX-BkCHnxel99lOtmD1A37Utg==/split_config.armeabi_v7a.apk!/lib/armeabi-v7a/libmono-native.so assembly:<unknown assembly> type:<unknown type> member:(null) at (wrapper managed-to-native) Interop+Sys.LChflags</unknown></unknown>…

【Unity】「Google/Build and Run」で呼び出される関数

概要 BuildAndRunner.BuildAndRun();

【Unity】環境変数に ANDROID_HOME を設定するコード

概要 Environment.SetEnvironmentVariable ( variable: "ANDROID_HOME", value: AndroidExternalToolsSettings.sdkRootPath, target: EnvironmentVariableTarget.Process ); var oldPath = Environment.GetEnvironmentVariable ( variable: "PATH", target: …

【Unity】Play Asset Delivery 1.8.1 のパッケージを導入して Android ビルドしたらアプリ起動時に強制終了するようになった

概要 Throwing new exception 'No interface method getPackStates(Ljava/util/List;)Lcom/google/android/play/core/tasks/Task; in class Lcom/google/android/play/core/assetpacks/AssetPackManager; or its super classes (declaration of 'com.google.…

【Unity】Unity 用の Google パッケージを .tgz でダウンロードできるページ

リンク

【Unity】com.android.tools.build.bundletool.model.exceptions.CommandExecutionException: Installation of the app failed.

概要 Play Asset Delivery 用の Unity プラグインを追加して Bundletool.BuildBundle で Android ビルドを実行したら Installation failed with the following output: Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 The APKs have been extracted in…

【Unity】DeploymentOperationFailedException: Installation failed. See the Console for details.

概要 Play Asset Delivery 用の Unity プラグインを追加して Bundletool.BuildBundle で Android ビルドを実行したら DeploymentOperationFailedException: Installation failed. See the Console for details. UnityEditor.Android.AndroidDeploymentTarget…