時偶(ときたま)ブログ

40代のおとうちゃんが徒然に、ときたま書いてるブログです

Unityのあれこれをメモ

ビルドしたアプリのログを見る

  • Project Settings->Player->Resolution and Presentation->Standalone Player Options->User Player LogをOn。
  • エディタのConsoleの右上の「︙」->Open Player Log
    ログの場所は、
    mac : User/[username]/Library/Logs/[Company Name]/[ProductName]/

Unity DevOpsのmacOS High Sierra(10.13.6)での最終サポートVer.

Ver11.0.16.8108

文字、改行コードを一括変換

Assets/R_Scriptフォルダに移動して find . -name '*.cs' -print0 | xargs -0 nkf --overwrite -w -Lu を実行する

Unity開発でのエラーのあれこれ

アップロードしたすべてのバンドルに署名する必要があります。

Google Play Consoleでaabのアップロード時に表示される。
Build Profiles->Development BuildがOFFになっているか確認。

Unity6でandroidをビルドして実機で実行すると、古い端末だとナビゲーションバーがチラつく。

Project Settings->Player->Other Settings->Auto Graphics APIをOFFにしてGraphics APIのOpenGLES3を先頭にする。

Unity6でAndroidビルド時に"Shader error in 'Toon': invalid subscript '_ShadowCoord' at project/Library/PackageCache/com.unity.toonshader@b31df88ebb07/Runtime/Legacy/Shaders/UCTS_DoubleShadeWithFeather.cginc(124) (on gles3)"エラー

  • 条件:
    • Unity Toonをインポートしている
    • ライトマップベイクしたSceneがある
    • ライトマップベイクしていないSceneのみでAndroidビルドするとエラーが発生しない

Shaderがストリップされている可能性があるので、Project Settings->Graphics->Shader Stripping->Lightmap Modes->Custom->Baked ShadowmaskをOFF。他のはチェック付いててもOK

<補足> Unity6000.0.68f1とUnity Toon Shader0.12.0-previewでも発生していて、Unity Toon Shaderのその時の最新バージョン0.13.4-previewに上げたら治った。

ArgumentException: An item with the same key has already been added. Key:

ArgumentException: An item with the same key has already been added. Key: UnityEngine.Rendering.Universal.PostProcessData+TextureResources
System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <82571d7f5249456da89e34eb003220a7>:0)
System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) (at <82571d7f5249456da89e34eb003220a7>:0)
UnityEngine.Rendering.RenderPipelineGlobalSettings.RecreateSettingsMap () (at /Users/bokken/build/output/unity/unity/Runtime/Export/RenderPipeline/RenderPipelineGlobalSettings.cs:34)
UnityEngine.Rendering.RenderPipelineGlobalSettings.OnAfterDeserialize () (at /Users/bokken/build/output/unity/unity/Runtime/Export/RenderPipeline/RenderPipelineGlobalSettings.cs:156)
UnityEngine.Rendering.Universal.UniversalRendererData:OnEnable() (at ./Library/PackageCache/com.unity.render-pipelines.universal@fe5368074162/Runtime/UniversalRendererData.cs:352)

https://note.com/ikamichi/n/ne0916d319086などを参考にしたがkeyを検索しても見つからなかった。
結局,UniversalRenderPipelineGlobalSettings.assetを削除して(削除するとUnityが自動的に再作成し始める)、Assets > Reimport Allをしたら直った。
Unityの設定がリセットされると思うので、いじっている場合は再設定が必要か。

Unity Input SystemでXbox360コントローラーがGamepadとして認識されない件

Input SytemでXbox360のUSB接続コントローラーがJoystickとして認識されてしまう。

カスタムデバイスレイアウトを作成いて対応した。

using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;

/// <summary>
/// MacでXbox360用USB接続コントローラーがJoystickのMicrosoft Corporation Controllerと表示され、
/// Gamepadとして認識されない場合のカスタムデバイスレイアウト
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 32)]
public class MicrosoftCorporationControllerMacOSInputReport : IInputStateTypeInfo {
    public const int OSXVendorID = 0x45E;   // Microsoft Corporation
    public const int OSXProductId = 0x28E;  // Microsoft Corporation Xbox360 Controller

    public FourCC format => new('H', 'I', 'D');

    // LeftStick
    [InputControl(name = "leftStick", layout = "Stick", format = "VEC2", sizeInBits = 32)]
    [InputControl(name = "leftStick/x", format = "SHRT", offset = 0, sizeInBits = 16,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=1")]
    [InputControl(name = "leftStick/left", format = "BYTE", offset = 0,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=0.0,invert")]
    [InputControl(name = "leftStick/right", format = "BYTE", offset = 0,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=0.0,clampMax=1")]

    [InputControl(name = "leftStick/y", format = "SHRT", offset = 2, sizeInBits = 16,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=1")]
    [InputControl(name = "leftStick/up", format = "BYTE", offset = 2,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=0.0,clampMax=1")]
    [InputControl(name = "leftStick/down", format = "BYTE", offset = 2,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=0,invert")]
    [FieldOffset(6)] public byte leftStickX;
    [FieldOffset(8)] public byte leftStickY;

    //RightStick
    [InputControl(name = "rightStick", layout = "Stick", format = "VEC2", sizeInBits = 32)]
    [InputControl(name = "rightStick/x", format = "SHRT", offset = 0, sizeInBits = 16,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=1")]
    [InputControl(name = "rightStick/right", format = "BYTE", offset = 0,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=0,clampMax=1")]
    [InputControl(name = "rightStick/left", format = "BYTE", offset = 0,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=0,invert")]

    [InputControl(name = "rightStick/y", format = "SHRT", offset = 2, sizeInBits = 16,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=1")]
    [InputControl(name = "rightStick/up", format = "BYTE", offset = 2,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=0,clampMax=1")]
    [InputControl(name = "rightStick/down", format = "BYTE", offset = 2,
        parameters = "normalize,normalizeMin=-1,normalizeMax=1,normalizeZero=0.0,clamp,clampMin=-1,clampMax=0,invert")]
    [FieldOffset(10)] public byte rightStickX;
    [FieldOffset(12)] public byte rightStickY;

    // //Dpad
    [InputControl(name = "dpad", layout = "Dpad", sizeInBits = 4, bit = 0)]
    [InputControl(name = "dpad/up", bit = 0)]
    [InputControl(name = "dpad/down", bit = 1)]
    [InputControl(name = "dpad/left", bit = 2)]
    [InputControl(name = "dpad/right", bit = 3)]
    [FieldOffset(2)] public byte dpadButton;

    // Buttons
    [InputControl(name = "select", format = "BIT", layout = "Button", displayName = "BACK", bit = 5)]
    [InputControl(name = "start", format = "BIT", layout = "Button", displayName = "START", bit = 4)]
    [InputControl(name = "leftStickPress", format = "BIT", layout = "Button", displayName = "Left Stick Press", bit = 6)]
    [InputControl(name = "rightStickPress", format = "BIT", layout = "Button", displayName = "Right Stick Press", bit = 7)]
    [FieldOffset(2)] public byte button1;

    [InputControl(name = "buttonWest", format = "BIT", layout = "Button", displayName = "Y", bit = 7)]
    [InputControl(name = "buttonSouth", format = "BIT", layout = "Button", displayName = "B", bit = 5)]
    [InputControl(name = "buttonEast", format = "BIT", layout = "Button", displayName = "A", bit = 4)]
    [InputControl(name = "buttonNorth", format = "BIT", layout = "Button", displayName = "X", bit = 6)]
    [InputControl(name = "leftShoulder", format = "BIT", layout = "Button", displayName = "LB", bit = 0)]
    [InputControl(name = "rightShoulder", format = "BIT", layout = "Button", displayName = "RB", bit = 1)]
    [InputControl(name = "mode", format = "BIT", layout = "Button", displayName = "Xbox", bit = 2)]
    [FieldOffset(3)] public byte button2;

    [InputControl(name = "leftTrigger", displayName = "LT", format = "BYTE", bit = 0, sizeInBits = 8)]
    [FieldOffset(4)] public byte leftTrigger;

    [InputControl(name = "rightTrigger", displayName = "RT", format = "BYTE", bit = 0, sizeInBits = 8)]
    [FieldOffset(5)] public byte rightTrigger;
}
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;

/// <summary>
/// Mac mini M4ではInput SystemがXbox360コントローラーをJoystickと認識してしまうので、
/// Gamepadと認識するようにカスタムデバイスレイアウトを適用させる。
/// 適用はMac上のみ。
/// </summary>
[InputControlLayout(stateType = typeof(MicrosoftCorporationControllerMacOSInputReport))]
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class MicrosoftCorporationControllerGamepadHID : Gamepad {
    static MicrosoftCorporationControllerGamepadHID() {
        //Gamepadとして登録

#if UNITY_EDITOR_OSX || XNITY_STANDALONE_OSX
        Debug.Log($"Mac OS Xbox Controller Support");
        InputSystem.RegisterLayout<MicrosoftCorporationControllerGamepadHID>(
            "XboxGamepadHID",   // Windowsでの表示名に変換する
            matches: new InputDeviceMatcher()
            .WithInterface("HID")
            .WithCapability("vendorId", MicrosoftCorporationControllerMacOSInputReport.OSXVendorID)
            .WithCapability("productId", MicrosoftCorporationControllerMacOSInputReport.OSXProductId)
        );
#endif


   }

    [RuntimeInitializeOnLoadMethod]
    static void Init() {
        Debug.Log("Initialize Controller");
    }
}

参考

VSCodeのあれこれ

M4 Mac miniにVSCodeをインストールした時の参考

note.com

環境関連

Neovimのパス

  • mac : /opt/homebrew/bin/nvim
  • windows : c:\Program FIles\Neovim\bin\nvim.exe

init.vimのパス

  • mac : /Users/ユーザー名/.config/nvim/init.vim
  • windows : %userprofile%\AppData\Local\nvim\init.vim

入力モードを抜けた時に英語モードにする

Im-selectをインストール

brew tap daipeihust/tap && brew install im-select

IMを確認する

im-select

インストール場所の確認

which im-select

キーバインドメモ

  • スクロール
    zt カーソル行が画面の上部になるようにスクロール
    zz カーソル行が画面の中央になるようにスクロール
    zb カーソル行が画面の下部になるようにスクロール

  • カーソル移動
    ( 前の文頭or空白行に移動
    ) 次の文頭or空白行に移動
    { 前の空白行に移動
    } 次の空白行に移動
    H 画面の先頭行に移動
    M 画面の中央に移動
    H 画面の最終行に移動
    [( ) にいる時に、対応する ( に移動。( or ) にいない時は、メソッドの { に移動
    [) ( にいる時に、対応する ) に移動。( or ) にいない時は、メソッドの } に移動

  • ウィンドウ分割
    :split(:sp) 画面を横分割
    :vsplit(:vs) 画面を縦分割
    :new 新しい横方向の画面分割を作成
    :vnew 新しい縦方向の画面分割を作成

  • ウィンドウ移動(自分の環境ではctrl+wを受け付けなかったのでkeybinding.jsonを修正)
    ctrl+h 左のウィンドウに移動
    ctrl+l 右のウィンドウに移動
  • コード折りたたみ
    ctrl+k ctrl+j 全て展開
    ctrl+k ctrl+0 全て折りたたみ
    ctrl+k ctrl+/ 全てのコメントブロックを折りたたみ
    ctrl+k ctrl+1〜9 1〜9階層目を折りたたみ

参考

とほほのVim入門(カーソル移動) - とほほのWWW入門

参考

Steamのあれこれ

Unityに関するあれこれをまとめてみた

公式ドキュメント

https://partner.steamgames.com/doc/home

Steamの登録

アプリの登録 アップロード、アップデート

Mac関連

ストア画像

実績

その他

C#のあれこれ

C#に関するあれこれをまとめてみた

圧縮・解凍

Json