コガネブログ

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

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

【Unity】DOTWEEN ► This Tween has been killed and is now invalid

概要 if ( m_tween != null && m_tween.IsPlaying() ) return; DOTween で上記のようなコードを記述したら DOTWEEN ► This Tween has been killed and is now invalid 上記の警告が発生する現象に遭遇した if ( m_tween != null && m_tween.IsActive() && m_…

【Unity】UI をドラッグする時にクリックした位置を保持しておく方法

概要 using UnityEngine; using UnityEngine.EventSystems; public class Example : MonoBehaviour, IPointerDownHandler, IDragHandler { [SerializeField] private Canvas m_canvas; private Vector3 m_offset; void IPointerDownHandler.OnPointerDown( P…

【Unity】スプライトをドラッグする時にクリックした位置を保持しておく方法

概要 using UnityEngine; using UnityEngine.EventSystems; public class Example : MonoBehaviour, IPointerDownHandler, IDragHandler { private Vector3 m_offset; void IPointerDownHandler.OnPointerDown( PointerEventData eventData ) { var worldPoi…

【Unity】Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.

概要 Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s) at System.…

【Unity】Android 端末で機内モードかどうか確認する方法

概要 using UnityEngine; namespace Kogane { public static class AirplaneModeChecker { public static bool IsAirplaneMode { get { #if UNITY_EDITOR || UNITY_ANDROID if ( Application.isEditor ) return false; using var unityPlayer = new AndroidJ…

【Git】WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

概要 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone…

【Unity】ProjectSettings.asset のバックアップと復元を行うクラス

リポジトリ 使用例 using System.Linq; using Kogane; using UnityEditor; using UnityEngine; public static class Example { [MenuItem( "Tools/Hoge" )] public static void Hoge() { const BuildTargetGroup buildTargetGroup = BuildTargetGroup.Standa…

【Git】patch を反映する時にコミットはしないようにする方法

概要 git apply ならコミットはされない git am ならコミットされる 参考サイト様

【Git】error: XXXX: No such file or directory

概要 error: XXXX: No such file or directory patch 適用時に上記のエラーが発生する現象に遭遇した git apply --reject --whitespace=fix "【patch のファイルパス】" 上記のコマンドならエラーが発生せず正常に patch を適用できた\

【Unity】デバッグ用のシーンを Scenes In Build のリストの末尾に移動するエディタ拡張

リポジトリ 使用例 デバッグ用のシーンが格納されているフォルダのパスを Project Settings で「Path Array」に設定すると Scenes In Build にシーンを追加した時にデバッグ用のシーンが リストの末尾に自動で移動するようになります また、先頭以外のシーン…

【Unity】プレハブモードで開いているプレハブを Project ウィンドウでハイライトするエディタ拡張

リポジトリ 使用例 Project Settings で「Is Enable」をオンにすると プレハブモードで開いているプレハブが Project ウィンドウでハイライトされるようになります

【おすすめスライド】「【2023年版】ゲーム制作の現場でよく使うツールをまるっと紹介」

スライド 【2023年版】ゲーム制作の現場でよく使うツールをまるっと紹介 by @gamemakers 参考サイト様

【Unity】SortingLayerEditorUtility クラスの internal な機能にアクセスできる機能

リポジトリ 使用例 using System; using UnityEditor; using UnityEngine; namespace Kogane.Internal { [CustomEditor( typeof( MeshRenderer ) )] internal sealed class MeshRendererInspector : Editor { private Editor m_editor; private SerializedPr…

【Unity】TLS Allocator ALLOC_TEMP_TLS, underlying allocator ALLOC_TEMP_MAIN has unfreed allocations, size 30717

概要 TLS Allocator ALLOC_TEMP_TLS, underlying allocator ALLOC_TEMP_MAIN has unfreed allocations, size 30717 Internal: Stack allocator ALLOC_TEMP_MAIN has unfreed allocations, size 30717 To Debug, run app with -diag-temp-memory-leak-validat…

【Unity】TreeView で検索した時に要素の表示順が変わってしまう場合

概要 protected override bool DoesItemMatchSearch ( TreeViewItem treeViewItem, string search ) { // ... } TreeView の DoesItemMatchSearch をオーバーライドして検索処理を実装した際に、 MultiColumnHeader の sortedColumnIndex が無視されてしまう…

【Unity】ScriptableSingleton の拡張メソッド

リポジトリ 使用例 // protected な Save 関数を public で呼び出せるようにする拡張メソッド scriptableSingleton.Save( true );

【Unity】Animation で SpriteRenderer のスプライトを変更できない場合

概要 Animator を使用する必要がある 参考サイト様

【Rider】タイトルバーの色を変更できる「Project-Color」紹介

はじめに 「Project-Color」を Rider に導入することで タイトルバーの色を変更できるようになります 使い方 ツールバーのアイコンを押して 色を選択することでタイトルバーの色を変更できます 「Automatically set color based on project name」をオンにす…

【Unity】FancyGridView に normalizedPosition を実装する方法

概要 private int Rows => ( DataCount - 1 ) / startAxisCellCount + 1; public float NormalizedPosition { get => Mathf.InverseLerp( 0, Rows, Scroller.Position ); set => Scroller.Position = Mathf.Lerp( 0, Rows, value ); } 垂直方向の FancyGridV…

【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.