コガネブログ

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

2022-09-08から1日間の記事一覧

【C#】構造体のフィールドに初期値を設定する代替案

C#

概要 C# 9.0 までは引数なしコンストラクタを定義できないため 構造体のフィールドに初期値を設定できない 代替案としてフィールドを nullable にして プロパティの getter でフィールドが null なら初期値を設定する方法がある using UnityEngine; public s…

【Unity】空配列の生成は Array.Empty を使うと GC Alloc を抑えられる

概要 using UnityEngine; public class Example : MonoBehaviour { private void Update() { // GC Alloc が 31.2 KB for ( var i = 0; i < 1000; i++ ) { var strings = new string[ 0 ]; } } } using System; using UnityEngine; public class Example : M…

【Unity】Unity プロジェクトのフォルダをエクスプローラで開けるようにするエディタ拡張

ソースコード using System.Diagnostics; using System.IO; using UnityEditor; namespace Kogane.Internal { internal static class ShowProjectInExplorer { #if UNITY_EDITOR_WIN [MenuItem( "File/Show Project in Explorer" )] #else [MenuItem( "File/…