コガネブログ

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

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

【Unity】AssetBundleManifest を JSON 形式で出力するための構造体

ソースコード using System; using System.Diagnostics.CodeAnalysis; using System.Linq; using JetBrains.Annotations; using UnityEngine; [Serializable] [SuppressMessage( "ReSharper", "InconsistentNaming" )] public struct JsonAssetBundleManifes…

【Unity】System.Text.Json を使えるようにするだけのパッケージ「Kogane.System.Text.Json」を GitHub で公開しました

リポジトリ 使用例 using System.Text.Encodings.Web; using System.Text.Json; using UnityEngine; public sealed class Character { public int Id { get; set; } public string Name { get; set; } } public class Example : MonoBehaviour { private voi…

【Unity】.exe のウィンドウをボーダーレスにしたり最大化・最小化などができる「Borderless Unity Window」紹介

はじめに 「Borderless Unity Window」を Unity プロジェクトに導入することで .exe のウィンドウをボーダーレスにしたり最大化・最小化などができるようになります 使用例 // ボーダーレスのウィンドウに変更する BorderlessWindow.SetFramelessWindow(); /…

【Unity】Enum.HasFlag の GC Alloc

概要 public sealed class Example : MonoBehaviour { private void Update() { var hasFlag = JobType.SORCERER.HasFlag( JobType.SOLDIER ); } } Enum.HasFlag を使うと毎フレーム 40 B の GC Alloc が発生する public static class EnumExtensions { publ…

【Unity】Scene ビューの Transform ツールの線の太さを変える方法

概要 Unity の Preferences を開いて「Scene View > Line Thickness」を変更すると Scene ビューの Transform ツールの線の太さを 変えることができる

【Unity】PlayableDirector をリスタートするエディタ拡張

ソースコード using UnityEditor; using UnityEngine.Playables; public static class PlayableDirectorMenuItem { [MenuItem( "CONTEXT/" + nameof( PlayableDirector ) + "/" + nameof( Restart ) )] public static void Restart( MenuCommand command ) {…

【Unity】PlayableDirector の Inspector に Timeline ウィンドウを開くボタンを追加するエディタ拡張

ソースコード using System; using UnityEditor; using UnityEngine; using UnityEngine.Playables; [CustomEditor( typeof( PlayableDirector ) )] public sealed class PlayableDirectorInspector : Editor { private static readonly Type BASE_EDITOR_TY…

【Unity】Animator の Inspector に Animator ウィンドウを開くボタンを追加するエディタ拡張

ソースコード using System; using UnityEditor; using UnityEngine; [CustomEditor( typeof( Animator ) )] public sealed class AnimatorInspector : Editor { private static readonly Type BASE_EDITOR_TYPE = typeof( Editor ) .Assembly .GetType( "Un…

【Unity】Animation の Inspector に Animation ウィンドウを開くボタンを追加するエディタ拡張

ソースコード using System; using UnityEditor; using UnityEngine; [CustomEditor( typeof( Animation ) )] public sealed class AnimationInspector : Editor { private static readonly Type BASE_EDITOR_TYPE = typeof( Editor ) .Assembly .GetType( "…

【Unity】Inspector のヘッダにアセットの GUID を表示するエディタ拡張

ソースコード using UnityEditor; [InitializeOnLoad] public static class InspectorHeaderGUI { static InspectorHeaderGUI() { Editor.finishedDefaultHeaderGUI -= OnGUI; Editor.finishedDefaultHeaderGUI += OnGUI; } private static void OnGUI( Edit…

【Unity】ContentSizeFitter の Inspector に FitMode を変更するボタンを追加するエディタ拡張

ソースコード using System; using UnityEditor; using UnityEditor.UI; using UnityEngine; using UnityEngine.UI; [CustomEditor( typeof( ContentSizeFitter ) )] public sealed class ContentSizeFitterInspector : Editor { private static readonly Ty…

【Unity】Dictionary のキーに列挙型を使う時のパフォーマンスを測定

ソースコード using System; using System.Collections.Generic; using NUnit.Framework; using Unity.PerformanceTesting; // Dictionary のキーに列挙型を使用する時のパフォーマンスを測定するクラス public sealed class DictionaryEnumKeyTest { // 検…

【Unity】アセットバンドルからファイル名でアセットを読み込めなくしてパフォーマンスを少し改善する方法

概要 using UnityEngine; public class TestClass : MonoBehaviour { private void Start() { var path = "AssetBundles/materials.bundle"; var assetBundle = AssetBundle.LoadFromFile( path ); Debug.Log( assetBundle.LoadAsset( "Assets/material 1.ma…

【Visual Studio】Insert キーを押した時に上書きモードにならないようにする方法

概要 Visual Studio メニューの「ツール > オプション」を選択して 左メニューで「環境 > キーボード」を選択して 「以下の文字列を含むコマンドを表示」の入力欄に 上書きモード と入力して 表示された「編集.上書きモード」を選択して「削除」を押して「OK…

【Unity】TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite.

概要 Game.loader.js:303 Invoking error handler due to TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite. at _startPlayback (http://localhost:63752/Build/Game.framework.js:210…

【Unity】MissingReferenceException: The object of type 'HostView' has been destroyed but you are still trying to access it.

概要 Unity 2022.1.0b7 の Game ビューを「Fullscreen」モードにして Unity を再生すると MissingReferenceException: The object of type 'HostView' has been destroyed but you are still trying to access it. Your script should either check if it is…

【Unity】一度もアクティブになっていないゲームオブジェクトの OnDestroy は呼ばれない

概要 using UnityEngine; public sealed class Example : MonoBehaviour { private void OnDestroy() { Debug.Log( "OnDestroy" ); } } OnDestroy の時にログ出力する自作コンポーネントを ゲームオブジェクトにアタッチした場合 そのゲームオブジェクトが一…

【Unity】Unity 2021.2.11f1 の WebGL ビルドで AudioSource.clip によるサウンドの変更ができない

概要 using UnityEngine; public sealed class Example : MonoBehaviour { [SerializeField] private AudioSource m_audioSource; [SerializeField] private AudioClip m_audioClip1; [SerializeField] private AudioClip m_audioClip2; private void Update…

【Unity】Package Manager でインストールしたパッケージを埋め込みパッケージにするエディタ拡張

概要 https://gist.github.com/liortal53/111ee2a659b0d59c80faab0f5d457531?permalink_comment_id=3758173#gistcomment-3758173 上記のページのコメント欄で紹介されているエディタ拡張を Unity プロジェクトに導入すると Project ビューでパッケージを右ク…