20210114のUnityに関する記事は7件です。

【Unity】Display Resolution Dialog廃止以降でも解像度指定したい

はじめに

ProjectSettingsのPlayerにあったDisplay Resolution DialogがUnity 2019.3あたりからいなくなりました。

デバッグとかちょっと解像度変えたい時が個人的によくあるので、今後は各自で対応する必要がありそうです。
以下は思いあたる対応となります。

環境

  • Windows10
    (macOSでも同様なことができると思います)
  • Unity 2019.4

方法①

UnityのScene内で解像度指定するUIと機能を実装する。

UnityEngine.Screen.SetResolutionを実行中に呼び出せば変更されます。
ただ実装が大変。

https://docs.unity3d.com/ja/current/ScriptReference/Screen.SetResolution.html

方法②

Display Resolution Dialog(Launcher)を作る。

Unityで書き出したexeにコマンドライン引数を渡すようなGUIを用意すれば、今まで同様に指定解像度で起動してくれます。
アプリを起動する前に指定できるので画面切り替えがなくてスムーズです。
配布物とかだとユーザー側は扱いやすいと思います。

このあたりを引数に渡せばよしなにしてくれそうです。

  • -screen-fullscreen
  • -screen-height
  • -screen-width
  • -screen-quality

~~.exe -screen-width 1280 -screen-height 720

ただ、GUI組むとなるとこれも少し大変。

https://docs.unity3d.com/ja/2019.4/Manual/CommandLineArguments.html

方法③

直接コマンドライン引数を渡す。

方法②はGUI実装が大変なので、Windowsのコマンドプロンプトやショートカットなどで引数を渡してさっくり起動しようという話です。
外見はいいのでとにかくすぐ設定を変えて見たい時はこれでいい気がします。

ショートカットだと以下の感じ。

  1. Unityで書き出したexeを対象にショートカットを作成。
  2. プロパティを開いてリンク先の後ろに引数を付け足す。 image.png

参考

https://forum.unity.com/threads/display-resolution-dialog-deprecation.793611/

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

(備忘録)Unity(C#)でのシングルトンパターン

概要

  • ゲームの全体を通してパラメータなどを管理するクラスの作成
  • シングルトンパターンでの実装
  • prefabからのオブジェクトの取得も可
  • 別で基となる基底クラス(親クラス)を作成しない(ジェネリックを使わない)

*注意点
筆者はプログラミング苦手でUnityもC#も初心者ですし、備忘録なので、雰囲気で書いています。あまり信用しすぎないでください...

したいこと

したいことは、Unityでパラメータやprefabから取得したゲームオブジェクトをゲーム全体を通して管理できるクラスの作成です。
ただし色々調べたところ、ゲーム全体を通して管理するクラスのインスタンスは一つしか存在しない方が良いとのこと。
Unity 2Dアクションの作り方【ゲームマネージャーを作ろう】
UnityのMonoBehaviourクラスをシングルトン化する
インスタンスが複数存在している場合、そのうちの一つを変更しても他のインスタンスは何も変更されず、異なった値を持つパラメータが複数存在することになってしまいます。これでは、どれを参照すれば良いかわかりません。
そこで、インスタンスを1つしか存在できないようにしてやろう!ということです。

*補足
もう少し細かいことを言うと、パラメータを唯一にしたければ、インスタンス毎に割り振られる(または生成される)インスタンス変数を用いるのではなく、クラスに固有で全てのインスタンスに共通するクラス変数を用いるという方法もあります。もっと言うと、インスタンス変数を含まないクラスは静的クラスというものにすることができ、インスタンスの生成が一切できないクラスになりますので、これを利用してもいいです。これらの方法のほうがシンプルですね。
ですが、私の試した限りでは、prefabに入れてあるゲームオブジェクトをクラス変数に格納できませんでした。
なので仕方なくシングルトンパターンを利用しています。
また、通常UnityでC#スクリプトを書く場合、MonoBehaviourというクラスを継承した新しいクラスを作成するという形になるのですが、このMonoBehaviourというクラスの継承クラスは静的にできないらしいです。(
MonoBehaviourを継承しないという選択肢【Unity】)
ちなみにクラス変数にするには、変数定義の際にstaticを入れればいいです。また、静的クラスはクラス定義の際にstaticを入れればいいです。(詳しく解説はしないです。)

コードとコメント

以下がゲーム全体を通してパラメータやprefabを管理するクラスのシングルトンパターンでの実装コードです。ここではクラス名はゲームで扱う物を保管する場所という意味でGameStorageとしています。基本的には、上に挙げた記事を参考にして作成しました。
ちなみに、Unityのバージョンは2021.1.0b1です。

GameStorage
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameStorage : MonoBehaviour
{
    private GameObject Prefab_closed;
    private float parameter_closed;
    public GameObject Prefab
    {
        get {return Prefab_closed; }
    }
    public float parameter
    {
        get {return parameter_closed; }
    }

    private GameStorage() { }

    private static GameStorage Instance_closed;
    public static GameStorage Instance
    {
        get { return Instance_closed; }
    }

    private void Awake()
    {
        if (Instance_closed != null && Instance_closed != this)
        {
            Destroy(this.gameObject);
        }

        Instance_closed = this;
        DontDestroyOnLoad(this.gameObject);

        this.Prefab_closed = Resources.Load("OriginalObject") as GameObject;
        this.parameter_closed = Prefab.transform.localScale.y;
    }
}

まず、一番外枠の

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameStorage : MonoBehaviour
{

}

は、UnityでC#スクリプトを作成すると自動で書かれているやつですね。
次に

    private GameObject Prefab_closed;
    private float parameter_closed;
    public GameObject Prefab
    {
        get {return Prefab_closed; }
    }
    public float parameter
    {
        get {return parameter_closed; }
    }

の部分で、ゲーム全体を通して管理したいパラメータなどを格納するための変数を導入しています。最初の2行でprivate(クラスの内部だけで参照できる)インスタンス変数Prefab_closedとparameter_closedを導入します。Prefab_closedには後でprefab化したオブジェクトOriginalObjectを取得して入れます。parameter_closedにはPrefab_closedに入れたOriginalObjectのインスタンス変数を入れます。
そして、privateな変数だけでは外部からアクセスが一切できないので、次の部分でpravateなインスタンス変数Prefabとparameterを導入して外部からアクセスできるようにします。getを使うことで、Prefabやparameterという窓口を通してPrefab_closedやparameter_closedを取得するイメージです。ここで、勝手に外部から編集されたくないので、setは使わずに、外部への読み取りのみ許可するという形になっています。
次に、

    private GameStorage() { }

ですが、これはGameStorageクラスのコンストラクタです。publicではなくprivateであることが重要で、こうすることにより、クラス外で新しくGameStorageクラスのインスタンスを生成することを禁止しています。今回コンストラクタにはこの役割しか持たせないので、中括弧の中には何も書いていません。この部分は、Javaの解説記事のようですがこちらの記事を参考にしています。
5. Singleton パターン
次に、

    private static GameStorage Instance_closed;
    public static GameStorage Instance
    {
        get { return Instance_closed; }
    }

ですが、一行目でGamaStorageクラスのインスタンスInstance_closedをprivateな変数として生成しています。先ほど、コンストラクタをprivateにすることでクラス外部からのインスタンス生成を禁止すると言いましたが、ここはGameStorageクラスの定義文の中なので、インスタンスを生成することが可能なわけですね。さて、Instance_closedは外部からアクセスできないので、インスタンス変数の場合と同様に、publicはインスタンスInstanceを生成して、このInstanceを通してのみInstance_closedにアクセスできるようにします。ここでは、getのみを用いて、setは用いず、読み取りのみ可にしています。ここでもう一つ重要なのが、staticにすること。Unityでは、staticなインスタンスにしなければ、GetComponentやGameObject.Findなどを用いてインスタンスを探してくる必要がありますが、staticなインスタンスをクラス内で生成していくことで、

GameStorage.Instance

と書くだけでどこからでもアクセスが可能になります。
最後に、

    private void Awake()
    {
        if (Instance_closed != null && Instance_closed != this)
        {
            Destroy(this.gameObject);
        }

        Instance_closed = this;
        DontDestroyOnLoad(this.gameObject);

        this.Prefab_closed = Resources.Load("OriginalObject") as GameObject;
        this.parameter_closed = Prefab.transform.localScale.y;
    }

の部分に関してですが、まず、このAwake()はUnityで使う関数で、UnityでC#スクリプトを作成すると自動で書かれているStart()やUpdate()の仲間です。Start()よりは実行されるタイミングが早いということらしいですが、詳しいことは調べていないです。
さて、最初のIf文で、Instance_closedに自分自身以外のインスタンスが格納されていないかを調べています。もし別のインスタンスが入っていたらそのインスタンスが付随するゲームオブジェクトをDestroyすることで、複数のインスタンスが存在しないようにしています。この部分は(Unityで、シングルトンパターンを正しく実装するにはどうすればよいですか?)で書かれていた例を参考にしました。
その次の部分で、privateなインスタンスInstance_closedに実際に自分自身を入れています。
その下の行でDontDestroyOnLoadを用いることで、このクラスのインスタンスをゲームオブジェクトごとシーンを跨いで存在できるようにしています。
その下の部分で、最初の方に定義したインスタンス変数Prefab_closedとparameter_closedに、それぞれプレハブ化されたオブジェクトとそのオブジェクトのy軸方向の位置情報(transform.localScale.y)を代入しています。

以下、いくつか注意点です。

  • DestroyやDontDestroyOnLoadはシーン間遷移がある場合に必要な物だそうですが、また複数シーンを作成して遷移を行うテストをしていないため、上手くいくかわかりません。今後、確かめてみて問題が起きたら記事を修正するかもしれません。
  • インスタンスやインスタンス変数への代入ですが、コンストラクタやAwake()の外で行うとエラーが出ました。

以上です。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Unity HDRPでGeometryシェーダーを使う

Unity HDRPでGeometryシェーダーを試してみます。

HDRPでシェーダーとなるとShader Graphを使うことが多いと思いますが、Geometry ShaderはShader Graphでサポートされていないので、シェーダーを自分で書く必要があります。ただし、HDRPのシェーダーをゼロから書くのはほぼ無理なので、デフォルトのHDRPシェーダーをコピペしてきて、そこにGeometryシェーダーを追加していきます。

今回の使用したバージョンは次のとおりです。

  • Unity: 2019.4.18f1
  • High Definition RP: 7.5.2

まずは適当にシェーダーファイルを作成して、HDRPのLitシェーダーをコピペします。HDRPのLitシェーダーはPackages/High Definition RP/Runtime/Material/Lit/Lit.shaderです。これを以下のように編集します。コードをすべて載せているので長いですが、基本的にはhlslファイルをインクルードして、Geometry Shaderを設定しているだけです。編集箇所にはCustom:というコメントをつけています。

HdrpLitGeom.shader
Shader "HdrpLitGeom" // Custom: 名前を変更
{
    Properties
    {
        // Following set of parameters represent the parameters node inside the MaterialGraph.
        // They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

        // Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
        _BaseColor("BaseColor", Color) = (1,1,1,1)
        _BaseColorMap("BaseColorMap", 2D) = "white" {}
        [HideInInspector] _BaseColorMap_MipInfo("_BaseColorMap_MipInfo", Vector) = (0, 0, 0, 0)

        _Metallic("_Metallic", Range(0.0, 1.0)) = 0
        _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
        _MaskMap("MaskMap", 2D) = "white" {}
        _SmoothnessRemapMin("SmoothnessRemapMin", Float) = 0.0
        _SmoothnessRemapMax("SmoothnessRemapMax", Float) = 1.0
        _AORemapMin("AORemapMin", Float) = 0.0
        _AORemapMax("AORemapMax", Float) = 1.0

        _NormalMap("NormalMap", 2D) = "bump" {}     // Tangent space normal map
        _NormalMapOS("NormalMapOS", 2D) = "white" {} // Object space normal map - no good default value
        _NormalScale("_NormalScale", Range(0.0, 8.0)) = 1

        _BentNormalMap("_BentNormalMap", 2D) = "bump" {}
        _BentNormalMapOS("_BentNormalMapOS", 2D) = "white" {}

        _HeightMap("HeightMap", 2D) = "black" {}
        // Caution: Default value of _HeightAmplitude must be (_HeightMax - _HeightMin) * 0.01
        // Those two properties are computed from the ones exposed in the UI and depends on the displaement mode so they are separate because we don't want to lose information upon displacement mode change.
        [HideInInspector] _HeightAmplitude("Height Amplitude", Float) = 0.02 // In world units. This will be computed in the UI.
        [HideInInspector] _HeightCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space

        [Enum(MinMax, 0, Amplitude, 1)] _HeightMapParametrization("Heightmap Parametrization", Int) = 0
        // These parameters are for vertex displacement/Tessellation
        _HeightOffset("Height Offset", Float) = 0
        // MinMax mode
        _HeightMin("Heightmap Min", Float) = -1
        _HeightMax("Heightmap Max", Float) = 1
        // Amplitude mode
        _HeightTessAmplitude("Amplitude", Float) = 2.0 // in Centimeters
        _HeightTessCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space

        // These parameters are for pixel displacement
        _HeightPoMAmplitude("Height Amplitude", Float) = 2.0 // In centimeters

        _DetailMap("DetailMap", 2D) = "linearGrey" {}
        _DetailAlbedoScale("_DetailAlbedoScale", Range(0.0, 2.0)) = 1
        _DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1
        _DetailSmoothnessScale("_DetailSmoothnessScale", Range(0.0, 2.0)) = 1

        _TangentMap("TangentMap", 2D) = "bump" {}
        _TangentMapOS("TangentMapOS", 2D) = "white" {}
        _Anisotropy("Anisotropy", Range(-1.0, 1.0)) = 0
        _AnisotropyMap("AnisotropyMap", 2D) = "white" {}

        _SubsurfaceMask("Subsurface Radius", Range(0.0, 1.0)) = 1.0
        _SubsurfaceMaskMap("Subsurface Radius Map", 2D) = "white" {}
        _Thickness("Thickness", Range(0.0, 1.0)) = 1.0
        _ThicknessMap("Thickness Map", 2D) = "white" {}
        _ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)

        _IridescenceThickness("Iridescence Thickness", Range(0.0, 1.0)) = 1.0
        _IridescenceThicknessMap("Iridescence Thickness Map", 2D) = "white" {}
        _IridescenceThicknessRemap("Iridescence Thickness Remap", Vector) = (0, 1, 0, 0)
        _IridescenceMask("Iridescence Mask", Range(0.0, 1.0)) = 1.0
        _IridescenceMaskMap("Iridescence Mask Map", 2D) = "white" {}

        _CoatMask("Coat Mask", Range(0.0, 1.0)) = 0.0
        _CoatMaskMap("CoatMaskMap", 2D) = "white" {}

        [ToggleUI] _EnergyConservingSpecularColor("_EnergyConservingSpecularColor", Float) = 1.0
        _SpecularColor("SpecularColor", Color) = (1, 1, 1, 1)
        _SpecularColorMap("SpecularColorMap", 2D) = "white" {}

        // Following options are for the GUI inspector and different from the input parameters above
        // These option below will cause different compilation flag.
        [Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2)]  _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1

        [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
        // Used only to serialize the LDR and HDR emissive color in the material UI,
        // in the shader only the _EmissiveColor should be used
        [HideInInspector] _EmissiveColorLDR("EmissiveColor LDR", Color) = (0, 0, 0)
        _EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
        [ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0
        [HideInInspector] _EmissiveIntensityUnit("Emissive Mode", Int) = 0
        [ToggleUI] _UseEmissiveIntensity("Use Emissive Intensity", Int) = 0
        _EmissiveIntensity("Emissive Intensity", Float) = 1
        _EmissiveExposureWeight("Emissive Pre Exposure", Range(0.0, 1.0)) = 1.0

        _DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
        [ToggleUI] _DistortionEnable("Enable Distortion", Float) = 0.0
        [ToggleUI] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 1.0
        [Enum(Add, 0, Multiply, 1, Replace, 2)] _DistortionBlendMode("Distortion Blend Mode", Int) = 0
        [HideInInspector] _DistortionSrcBlend("Distortion Blend Src", Int) = 0
        [HideInInspector] _DistortionDstBlend("Distortion Blend Dst", Int) = 0
        [HideInInspector] _DistortionBlurSrcBlend("Distortion Blur Blend Src", Int) = 0
        [HideInInspector] _DistortionBlurDstBlend("Distortion Blur Blend Dst", Int) = 0
        [HideInInspector] _DistortionBlurBlendMode("Distortion Blur Blend Mode", Int) = 0
        _DistortionScale("Distortion Scale", Float) = 1
        _DistortionVectorScale("Distortion Vector Scale", Float) = 2
        _DistortionVectorBias("Distortion Vector Bias", Float) = -1
        _DistortionBlurScale("Distortion Blur Scale", Float) = 1
        _DistortionBlurRemapMin("DistortionBlurRemapMin", Float) = 0.0
        _DistortionBlurRemapMax("DistortionBlurRemapMax", Float) = 1.0


        [ToggleUI]  _UseShadowThreshold("_UseShadowThreshold", Float) = 0.0
        [ToggleUI]  _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
        _AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
        _AlphaCutoffShadow("_AlphaCutoffShadow", Range(0.0, 1.0)) = 0.5
        _AlphaCutoffPrepass("_AlphaCutoffPrepass", Range(0.0, 1.0)) = 0.5
        _AlphaCutoffPostpass("_AlphaCutoffPostpass", Range(0.0, 1.0)) = 0.5
        [ToggleUI] _TransparentDepthPrepassEnable("_TransparentDepthPrepassEnable", Float) = 0.0
        [ToggleUI] _TransparentBackfaceEnable("_TransparentBackfaceEnable", Float) = 0.0
        [ToggleUI] _TransparentDepthPostpassEnable("_TransparentDepthPostpassEnable", Float) = 0.0
        _TransparentSortPriority("_TransparentSortPriority", Float) = 0

        // Transparency
        [Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Refraction Model", Int) = 0
        [Enum(Proxy, 1, HiZ, 2)]_SSRefractionProjectionModel("Refraction Projection Model", Int) = 0
        _Ior("Index Of Refraction", Range(1.0, 2.5)) = 1.5
        _TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0)
        _TransmittanceColorMap("TransmittanceColorMap", 2D) = "white" {}
        _ATDistance("Transmittance Absorption Distance", Float) = 1.0
        [ToggleUI] _TransparentWritingMotionVec("_TransparentWritingMotionVec", Float) = 0.0

        // Stencil state

        // Forward
        [HideInInspector] _StencilRef("_StencilRef", Int) = 0 // StencilUsage.Clear
        [HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 3 // StencilUsage.RequiresDeferredLighting | StencilUsage.SubsurfaceScattering
        // GBuffer
        [HideInInspector] _StencilRefGBuffer("_StencilRefGBuffer", Int) = 2 // StencilUsage.RequiresDeferredLighting
        [HideInInspector] _StencilWriteMaskGBuffer("_StencilWriteMaskGBuffer", Int) = 3 // StencilUsage.RequiresDeferredLighting | StencilUsage.SubsurfaceScattering
        // Depth prepass
        [HideInInspector] _StencilRefDepth("_StencilRefDepth", Int) = 0 // Nothing
        [HideInInspector] _StencilWriteMaskDepth("_StencilWriteMaskDepth", Int) = 8 // StencilUsage.TraceReflectionRay
        // Motion vector pass
        [HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 32 // StencilUsage.ObjectMotionVector
        [HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 32 // StencilUsage.ObjectMotionVector
        // Distortion vector pass
        [HideInInspector] _StencilRefDistortionVec("_StencilRefDistortionVec", Int) = 4 // StencilUsage.DistortionVectors
        [HideInInspector] _StencilWriteMaskDistortionVec("_StencilWriteMaskDistortionVec", Int) = 4 // StencilUsage.DistortionVectors

        // Blending state
        [HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0
        [HideInInspector] _BlendMode("__blendmode", Float) = 0.0
        [HideInInspector] _SrcBlend("__src", Float) = 1.0
        [HideInInspector] _DstBlend("__dst", Float) = 0.0
        [HideInInspector] _AlphaSrcBlend("__alphaSrc", Float) = 1.0
        [HideInInspector] _AlphaDstBlend("__alphaDst", Float) = 0.0
        [HideInInspector][ToggleUI] _ZWrite("__zw", Float) = 1.0
        [HideInInspector][ToggleUI] _TransparentZWrite("_TransparentZWrite", Float) = 0.0
        [HideInInspector] _CullMode("__cullmode", Float) = 2.0
        [HideInInspector] _CullModeForward("__cullmodeForward", Float) = 2.0 // This mode is dedicated to Forward to correctly handle backface then front face rendering thin transparent
        [Enum(UnityEditor.Rendering.HighDefinition.TransparentCullMode)] _TransparentCullMode("_TransparentCullMode", Int) = 2 // Back culling by default
        [HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal
        [HideInInspector] _ZTestModeDistortion("_ZTestModeDistortion", Int) = 8
        [HideInInspector] _ZTestGBuffer("_ZTestGBuffer", Int) = 4
        [Enum(UnityEngine.Rendering.CompareFunction)] _ZTestTransparent("Transparent ZTest", Int) = 4 // Less equal

        [ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0
        [ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0

        [ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0
        [Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1
        [HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0)

        [Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase("UV Set for base", Float) = 0
        _TexWorldScale("Scale to apply on world coordinate", Float) = 1.0
        [HideInInspector] _InvTilingScale("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Float) = 1
        [HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
        [Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0

        // Following enum should be material feature flags (i.e bitfield), however due to Gbuffer encoding constrain many combination exclude each other
        // so we use this enum as "material ID" which can be interpreted as preset of bitfield of material feature
        // The only material feature flag that can be added in all cases is clear coat
        [Enum(Subsurface Scattering, 0, Standard, 1, Anisotropy, 2, Iridescence, 3, Specular Color, 4, Translucent, 5)] _MaterialID("MaterialId", Int) = 1 // MaterialId.Standard
        [ToggleUI] _TransmissionEnable("_TransmissionEnable", Float) = 1.0

        [Enum(None, 0, Vertex displacement, 1, Pixel displacement, 2)] _DisplacementMode("DisplacementMode", Int) = 0
        [ToggleUI] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0
        [ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0
        [ToggleUI] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0

        [ToggleUI] _EnableGeometricSpecularAA("EnableGeometricSpecularAA", Float) = 0.0
        _SpecularAAScreenSpaceVariance("SpecularAAScreenSpaceVariance", Range(0.0, 1.0)) = 0.1
        _SpecularAAThreshold("SpecularAAThreshold", Range(0.0, 1.0)) = 0.2

        _PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5
        _PPDMaxSamples("Max sample for POM", Range(1.0, 64.0)) = 15
        _PPDLodThreshold("Start lod to fade out the POM effect", Range(0.0, 16.0)) = 5
        _PPDPrimitiveLength("Primitive length for POM", Float) = 1
        _PPDPrimitiveWidth("Primitive width for POM", Float) = 1
        [HideInInspector] _InvPrimScale("Inverse primitive scale for non-planar POM", Vector) = (1, 1, 0, 0)

        [Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail("UV Set for detail", Float) = 0
        [HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0)
        [ToggleUI] _LinkDetailsWithBase("LinkDetailsWithBase", Float) = 1.0

        [Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
        [Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVEmissive("UV Set for emissive", Float) = 0
        _TexWorldScaleEmissive("Scale to apply on world coordinate", Float) = 1.0
        [HideInInspector] _UVMappingMaskEmissive("_UVMappingMaskEmissive", Color) = (1, 0, 0, 0)

        // Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
        // value that exist to identify if the GI emission need to be enabled.
        // In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
        // TODO: Fix the code in legacy unity so we can customize the beahvior for GI
        _EmissionColor("Color", Color) = (1, 1, 1)

        // HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
        _MainTex("Albedo", 2D) = "white" {}
        _Color("Color", Color) = (1,1,1,1)
        _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5

        [ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
        [ToggleUI] _ReceivesSSR("Receives SSR", Float) = 1.0
        [ToggleUI] _AddPrecomputedVelocity("AddPrecomputedVelocity", Float) = 0.0

        [HideInInspector] _DiffusionProfile("Obsolete, kept for migration purpose", Int) = 0
        [HideInInspector] _DiffusionProfileAsset("Diffusion Profile Asset", Vector) = (0, 0, 0, 0)
        [HideInInspector] _DiffusionProfileHash("Diffusion Profile Hash", Float) = 0
    }

    HLSLINCLUDE

    #pragma target 4.5

    // Custom: Geometry Shaderを使用できるようにする (上でtargetを4.0以上にしているのでいらないかもしれないが念のため)
    #pragma require geometry

    //-------------------------------------------------------------------------------------
    // Variant
    //-------------------------------------------------------------------------------------

    #pragma shader_feature_local _ALPHATEST_ON
    #pragma shader_feature_local _DEPTHOFFSET_ON
    #pragma shader_feature_local _DOUBLESIDED_ON
    #pragma shader_feature_local _ _VERTEX_DISPLACEMENT _PIXEL_DISPLACEMENT
    #pragma shader_feature_local _VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE
    #pragma shader_feature_local _DISPLACEMENT_LOCK_TILING_SCALE
    #pragma shader_feature_local _PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE
    #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN

    #pragma shader_feature_local _ _EMISSIVE_MAPPING_PLANAR _EMISSIVE_MAPPING_TRIPLANAR
    #pragma shader_feature_local _ _MAPPING_PLANAR _MAPPING_TRIPLANAR
    #pragma shader_feature_local _NORMALMAP_TANGENT_SPACE
    #pragma shader_feature_local _ _REQUIRE_UV2 _REQUIRE_UV3

    #pragma shader_feature_local _NORMALMAP
    #pragma shader_feature_local _MASKMAP
    #pragma shader_feature_local _BENTNORMALMAP
    #pragma shader_feature_local _EMISSIVE_COLOR_MAP

    // _ENABLESPECULAROCCLUSION keyword is obsolete but keep here for compatibility. Do not used
    // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it)
    // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work
    #pragma shader_feature_local _ENABLESPECULAROCCLUSION
    #pragma shader_feature_local _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP
    #ifdef _ENABLESPECULAROCCLUSION
    #define _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP
    #endif

    #pragma shader_feature_local _HEIGHTMAP
    #pragma shader_feature_local _TANGENTMAP
    #pragma shader_feature_local _ANISOTROPYMAP
    #pragma shader_feature_local _DETAIL_MAP
    #pragma shader_feature_local _SUBSURFACE_MASK_MAP
    #pragma shader_feature_local _THICKNESSMAP
    #pragma shader_feature_local _IRIDESCENCE_THICKNESSMAP
    #pragma shader_feature_local _SPECULARCOLORMAP
    #pragma shader_feature_local _TRANSMITTANCECOLORMAP

    #pragma shader_feature_local _DISABLE_DECALS
    #pragma shader_feature_local _DISABLE_SSR
    #pragma shader_feature_local _ENABLE_GEOMETRIC_SPECULAR_AA

    // Keyword for transparent
    #pragma shader_feature _SURFACE_TYPE_TRANSPARENT
    #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    #pragma shader_feature_local _BLENDMODE_PRESERVE_SPECULAR_LIGHTING
    #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT
    #pragma shader_feature_local _TRANSPARENT_WRITES_MOTION_VEC

    // MaterialFeature are used as shader feature to allow compiler to optimize properly
    #pragma shader_feature_local _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    #pragma shader_feature_local _MATERIAL_FEATURE_TRANSMISSION
    #pragma shader_feature_local _MATERIAL_FEATURE_ANISOTROPY
    #pragma shader_feature_local _MATERIAL_FEATURE_CLEAR_COAT
    #pragma shader_feature_local _MATERIAL_FEATURE_IRIDESCENCE
    #pragma shader_feature_local _MATERIAL_FEATURE_SPECULAR_COLOR

    #pragma shader_feature_local _ADD_PRECOMPUTED_VELOCITY

    // enable dithering LOD crossfade
    #pragma multi_compile _ LOD_FADE_CROSSFADE

    //-------------------------------------------------------------------------------------
    // Define
    //-------------------------------------------------------------------------------------

    // This shader support vertex modification
    #define HAVE_VERTEX_MODIFICATION

    // If we use subsurface scattering, enable output split lighting (for forward pass)
    #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    #define OUTPUT_SPLIT_LIGHTING
    #endif

    #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    #define _WRITE_TRANSPARENT_MOTION_VECTOR
    #endif
    //-------------------------------------------------------------------------------------
    // Include
    //-------------------------------------------------------------------------------------

    #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"

    //-------------------------------------------------------------------------------------
    // variable declaration
    //-------------------------------------------------------------------------------------

    // #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.cs.hlsl"
    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl"

    // TODO:
    // Currently, Lit.hlsl and LitData.hlsl are included for every pass. Split Lit.hlsl in two:
    // LitData.hlsl and LitShading.hlsl (merge into the existing LitData.hlsl).
    // LitData.hlsl should be responsible for preparing shading parameters.
    // LitShading.hlsl implements the light loop API.
    // LitData.hlsl is included here, LitShading.hlsl is included below for shading passes only.

    ENDHLSL

    SubShader
    {
        // This tags allow to use the shader replacement features
        Tags{ "RenderPipeline"="HDRenderPipeline" "RenderType" = "HDLitShader" }

        Pass
        {
            Name "SceneSelectionPass"
            Tags { "LightMode" = "SceneSelectionPass" }

            Cull Off

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            // Note: Require _ObjectId and _PassValue variables

            // We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation
            #define SHADERPASS SHADERPASS_DEPTH_ONLY
            #define SCENESELECTIONPASS // This will drive the output of the scene selection shader
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            #pragma editor_sync_compilation

            ENDHLSL
        }

        // Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not bethe  meta pass.
        Pass
        {
            Name "GBuffer"
            Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index

            Cull [_CullMode]
            ZTest [_ZTestGBuffer]

            Stencil
            {
                WriteMask [_StencilWriteMaskGBuffer]
                Ref [_StencilRefGBuffer]
                Comp Always
                Pass Replace
            }

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #pragma multi_compile _ DEBUG_DISPLAY
            #pragma multi_compile _ LIGHTMAP_ON
            #pragma multi_compile _ DIRLIGHTMAP_COMBINED
            #pragma multi_compile _ DYNAMICLIGHTMAP_ON
            #pragma multi_compile _ SHADOWS_SHADOWMASK
            // Setup DECALS_OFF so the shader stripper can remove variants
            #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
            #pragma multi_compile _ LIGHT_LAYERS

        #ifndef DEBUG_DISPLAY
            // When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer
            // Don't do it with debug display mode as it is possible there is no depth prepass in this case
            #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
        #endif

            #define SHADERPASS SHADERPASS_GBUFFER
            #ifdef DEBUG_DISPLAY
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
            #endif
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        // Custom: META Passを削除

        Pass
        {
            Name "ShadowCaster"
            Tags{ "LightMode" = "ShadowCaster" }

            Cull[_CullMode]

            ZClip [_ZClip]
            ZWrite On
            ZTest LEqual

            ColorMask 0

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #define SHADERPASS SHADERPASS_SHADOWS
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        Pass
        {
            Name "DepthOnly"
            Tags{ "LightMode" = "DepthOnly" }

            Cull[_CullMode]

            // To be able to tag stencil with disableSSR information for forward
            Stencil
            {
                WriteMask [_StencilWriteMaskDepth]
                Ref [_StencilRefDepth]
                Comp Always
                Pass Replace
            }

            ZWrite On

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            // In deferred, depth only pass don't output anything.
            // In forward it output the normal buffer
            #pragma multi_compile _ WRITE_NORMAL_BUFFER
            #pragma multi_compile _ WRITE_MSAA_DEPTH

            #define SHADERPASS SHADERPASS_DEPTH_ONLY
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"

            #ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl"
            #else
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl"
            #endif

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        Pass
        {
            Name "MotionVectors"
            Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity)

            // If velocity pass (motion vectors) is enabled we tag the stencil so it don't perform CameraMotionVelocity
            Stencil
            {
                WriteMask [_StencilWriteMaskMV]
                Ref [_StencilRefMV]
                Comp Always
                Pass Replace
            }

            Cull[_CullMode]

            ZWrite On

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #pragma multi_compile _ WRITE_NORMAL_BUFFER
            #pragma multi_compile _ WRITE_MSAA_DEPTH

            #define SHADERPASS SHADERPASS_MOTION_VECTORS
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #ifdef WRITE_NORMAL_BUFFER // If enabled we need all regular interpolator
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl"
            #else
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitMotionVectorPass.hlsl"
            #endif
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassMotionVectors.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        Pass
        {
            Name "DistortionVectors"
            Tags { "LightMode" = "DistortionVectors" } // This will be only for transparent object based on the RenderQueue index

            Stencil
            {
                WriteMask [_StencilRefDistortionVec]
                Ref [_StencilRefDistortionVec]
                Comp Always
                Pass Replace
            }

            Blend [_DistortionSrcBlend] [_DistortionDstBlend], [_DistortionBlurSrcBlend] [_DistortionBlurDstBlend]
            BlendOp Add, [_DistortionBlurBlendOp]
            ZTest [_ZTestModeDistortion]
            ZWrite off
            Cull [_CullMode]

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #define SHADERPASS SHADERPASS_DISTORTION
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDistortionPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDistortion.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        Pass
        {
            Name "TransparentDepthPrepass"
            Tags{ "LightMode" = "TransparentDepthPrepass" }

            Cull[_CullMode]
            ZWrite On
            ColorMask 0

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #define SHADERPASS SHADERPASS_DEPTH_ONLY
            #define CUTOFF_TRANSPARENT_DEPTH_PREPASS
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        // Caution: Order is important: TransparentBackface, then Forward/ForwardOnly
        Pass
        {
            Name "TransparentBackface"
            Tags { "LightMode" = "TransparentBackface" }

            Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
            ZWrite [_ZWrite]
            Cull Front
            ColorMask [_ColorMaskTransparentVel] 1
            ZTest [_ZTestTransparent]

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #pragma multi_compile _ DEBUG_DISPLAY
            #pragma multi_compile _ LIGHTMAP_ON
            #pragma multi_compile _ DIRLIGHTMAP_COMBINED
            #pragma multi_compile _ DYNAMICLIGHTMAP_ON
            #pragma multi_compile _ SHADOWS_SHADOWMASK
            // Setup DECALS_OFF so the shader stripper can remove variants
            #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT

            // Supported shadow modes per light type
            #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH

            #define USE_CLUSTERED_LIGHTLIST // There is not FPTL lighting when using transparent

            #define SHADERPASS SHADERPASS_FORWARD
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"

        #ifdef DEBUG_DISPLAY
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
        #endif

            // The light loop (or lighting architecture) is in charge to:
            // - Define light list
            // - Define the light loop
            // - Setup the constant/data
            // - Do the reflection hierarchy
            // - Provide sampling function for shadowmap, ies, cookie and reflection (depends on the specific use with the light loops like index array or atlas or single and texture format (cubemap/latlong))

            #define HAS_LIGHTLOOP

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl"

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        Pass
        {
            Name "Forward"
            Tags { "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index

            Stencil
            {
                WriteMask [_StencilWriteMask]
                Ref [_StencilRef]
                Comp Always
                Pass Replace
            }

            Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
            // In case of forward we want to have depth equal for opaque mesh
            ZTest [_ZTestDepthEqualForOpaque]
            ZWrite [_ZWrite]
            Cull [_CullModeForward]
            ColorMask [_ColorMaskTransparentVel] 1

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #pragma multi_compile _ DEBUG_DISPLAY
            #pragma multi_compile _ LIGHTMAP_ON
            #pragma multi_compile _ DIRLIGHTMAP_COMBINED
            #pragma multi_compile _ DYNAMICLIGHTMAP_ON
            #pragma multi_compile _ SHADOWS_SHADOWMASK
            // Setup DECALS_OFF so the shader stripper can remove variants
            #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT

            // Supported shadow modes per light type
            #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH

            #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST

            #define SHADERPASS SHADERPASS_FORWARD
            // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
            // Don't do it with debug display mode as it is possible there is no depth prepass in this case
            #if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(DEBUG_DISPLAY)
                #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
            #endif
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"

        #ifdef DEBUG_DISPLAY
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
        #endif

            // The light loop (or lighting architecture) is in charge to:
            // - Define light list
            // - Define the light loop
            // - Setup the constant/data
            // - Do the reflection hierarchy
            // - Provide sampling function for shadowmap, ies, cookie and reflection (depends on the specific use with the light loops like index array or atlas or single and texture format (cubemap/latlong))

            #define HAS_LIGHTLOOP

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl"

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        Pass
        {
            Name "TransparentDepthPostpass"
            Tags { "LightMode" = "TransparentDepthPostpass" }

            Cull[_CullMode]
            ZWrite On
            ColorMask 0

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing
            #pragma instancing_options renderinglayer

            #define SHADERPASS SHADERPASS_DEPTH_ONLY
            #define CUTOFF_TRANSPARENT_DEPTH_POSTPASS
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }
    }

    // Custom: DXRは今回は使わないので削除

    CustomEditor "Rendering.HighDefinition.LitGUI"
}

インクルードしているhlslファイルも作成します。ここでVertexシェーダーとGeomtryシェーダーを定義しています。

HdrpGeom.hlsl
// === 以下からコピペ
// https://github.com/keijiro/TestbedHDRP/blob/master/Assets/CustomShader/Common/CustomVertex.hlsl
struct Attributes
{
    float4 positionOS   : POSITION;
#ifdef ATTRIBUTES_NEED_NORMAL
    float3 normalOS     : NORMAL;
#endif
#ifdef ATTRIBUTES_NEED_TANGENT
    float4 tangentOS    : TANGENT; // Store sign in w
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD0
    float2 uv0          : TEXCOORD0;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD1
    float2 uv1          : TEXCOORD1;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD2
    float2 uv2          : TEXCOORD2;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD3
    float2 uv3          : TEXCOORD3;
#endif
#if SHADERPASS == SHADERPASS_MOTION_VECTORS
    float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
#endif
#ifdef ATTRIBUTES_NEED_COLOR
    float4 color        : COLOR;
#endif

UNITY_VERTEX_INPUT_INSTANCE_ID
};

AttributesMesh ConvertToAttributesMesh(Attributes input)
{
    AttributesMesh am;
    am.positionOS = input.positionOS.xyz;
#ifdef ATTRIBUTES_NEED_NORMAL
    am.normalOS = input.normalOS;
#endif
#ifdef ATTRIBUTES_NEED_TANGENT
    am.tangentOS = input.tangentOS;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD0
    am.uv0 = input.uv0;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD1
    am.uv1 = input.uv1;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD2
    am.uv2 = input.uv2;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD3
    am.uv3 = input.uv3;
#endif
#ifdef ATTRIBUTES_NEED_COLOR
    am.color = input.color;
#endif
    UNITY_TRANSFER_INSTANCE_ID(input, am);
    return am;
}

// Passthrough vertex shader
// We do all vertex calculations in the geometry shader.
void VertexThru(inout Attributes input) {}

// Vertex data pack function
// Re-pack the vertex data and apply the original vertex function.
PackedVaryingsType PackVertexData(
    AttributesMesh source,
    float3 position, float3 position_prev, float3 normal, float4 color
)
{
    source.positionOS = position;
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(VARYINGS_DS_NEED_TEXCOORD1)
    // FIXME: I'm not sure why but the shader compiler emits an "unexpected
    // LEFT_BRACKET" error on Vulkan. Strangely, it disappears by touching UV1
    // before calling VertMesh.
    source.uv1 = source.uv1 + 1e-12;
#endif
#ifdef ATTRIBUTES_NEED_NORMAL
    source.normalOS = normal;
#endif
#ifdef ATTRIBUTES_NEED_COLOR
    source.color = color;
#endif
#if SHADERPASS == SHADERPASS_MOTION_VECTORS
    AttributesPass attrib;
    attrib.previousPositionOS = position_prev;
    return Vert(source, attrib);
#else
    return Vert(source);
#endif
}
// === ここまでコピペ


// Geometry Shaderの定義
// 各頂点ごとに正方形のポリゴンを生成する
[maxvertexcount(4)]
void Geom(
    uint pid : SV_PrimitiveID,
    point Attributes input[1],
    inout TriangleStream<PackedVaryingsType> outStream
)
{
    AttributesMesh v = ConvertToAttributesMesh(input[0]);

    float3 p = v.positionOS;
    float3 p0 = p + float3(-0.05, -0.05, 0);
    float3 p1 = p + float3(-0.05, 0.05, 0);
    float3 p2 = p + float3(0.05, -0.05, 0);
    float3 p3 = p + float3(0.05, 0.05, 0);

    float3 n = float3(0, 0, -1);
    float4 c = float4(1, 1, 1, 1);

    outStream.Append(PackVertexData(v, p0, p0, n, c));
    outStream.Append(PackVertexData(v, p1, p1, n, c));
    outStream.Append(PackVertexData(v, p2, p2, n, c));
    outStream.Append(PackVertexData(v, p3, p3, n, c));
    outStream.RestartStrip();
}

このシェーダーを使用するマテリアルをUnityのSphereメッシュに適用すると以下のようになります。意図どおりに各頂点に四角形を表示できています。
HdrpGeom.PNG

Unlitシェーダーも同じようにコピペしてきて、各パスにGeometryシェーダーを追加することで対応できます。HDRPのUnlitシェーダーはPackages/High Definition RP/Runtime/Material/Unlit/Unlit.shaderです

HdrpUnlitGeom.shader
Shader "HdrpUnlitGeom" // Custom: 名前を変更
{
    Properties
    {
        // Be careful, do not change the name here to _Color. It will conflict with the "fake" parameters (see end of properties) required for GI.
        _UnlitColor("Color", Color) = (1,1,1,1)
        _UnlitColorMap("ColorMap", 2D) = "white" {}

        [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
        _EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
        // Used only to serialize the LDR and HDR emissive color in the material UI,
        // in the shader only the _EmissiveColor should be used
        [HideInInspector] _EmissiveColorLDR("EmissiveColor LDR", Color) = (0, 0, 0)
        [ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0
        [HideInInspector] _EmissiveIntensityUnit("Emissive Mode", Int) = 0
        [ToggleUI] _UseEmissiveIntensity("Use Emissive Intensity", Int) = 0
        _EmissiveIntensity("Emissive Intensity", Float) = 1
        _EmissiveExposureWeight("Emissive Pre Exposure", Range(0.0, 1.0)) = 1.0

        _DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
        [ToggleUI] _DistortionEnable("Enable Distortion", Float) = 0.0
        [ToggleUI] _DistortionOnly("Distortion Only", Float) = 0.0
        [ToggleUI] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 1.0
        [Enum(Add, 0, Multiply, 1, Replace, 2)] _DistortionBlendMode("Distortion Blend Mode", Int) = 0
        [HideInInspector] _DistortionSrcBlend("Distortion Blend Src", Int) = 0
        [HideInInspector] _DistortionDstBlend("Distortion Blend Dst", Int) = 0
        [HideInInspector] _DistortionBlurSrcBlend("Distortion Blur Blend Src", Int) = 0
        [HideInInspector] _DistortionBlurDstBlend("Distortion Blur Blend Dst", Int) = 0
        [HideInInspector] _DistortionBlurBlendMode("Distortion Blur Blend Mode", Int) = 0
        _DistortionScale("Distortion Scale", Float) = 1
        _DistortionVectorScale("Distortion Vector Scale", Float) = 2
        _DistortionVectorBias("Distortion Vector Bias", Float) = -1
        _DistortionBlurScale("Distortion Blur Scale", Float) = 1
        _DistortionBlurRemapMin("DistortionBlurRemapMin", Float) = 0.0
        _DistortionBlurRemapMax("DistortionBlurRemapMax", Float) = 1.0

        // Transparency
        [ToggleUI]  _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
        _AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
        _TransparentSortPriority("_TransparentSortPriority", Float) = 0

        // Blending state
        [HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0
        [HideInInspector] _BlendMode("__blendmode", Float) = 0.0
        [HideInInspector] _SrcBlend("__src", Float) = 1.0
        [HideInInspector] _DstBlend("__dst", Float) = 0.0
        [HideInInspector] _AlphaSrcBlend("__alphaSrc", Float) = 1.0
        [HideInInspector] _AlphaDstBlend("__alphaDst", Float) = 0.0
        [HideInInspector][ToggleUI] _ZWrite("__zw", Float) = 1.0
        [HideInInspector][ToggleUI] _TransparentZWrite("_TransparentZWrite", Float) = 0.0
        [HideInInspector] _CullMode("__cullmode", Float) = 2.0
        [Enum(UnityEditor.Rendering.HighDefinition.TransparentCullMode)] _TransparentCullMode("_TransparentCullMode", Int) = 2 // Back culling by default
        [HideInInspector] _ZTestModeDistortion("_ZTestModeDistortion", Int) = 8
        [Enum(UnityEngine.Rendering.CompareFunction)] _ZTestTransparent("Transparent ZTest", Int) = 4 // Less equal
        [HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal

        [ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 0.0
        [ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0

        // Stencil state
        [HideInInspector] _StencilRef("_StencilRef", Int) = 0  // StencilUsage.Clear
        [HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 3 // StencilUsage.RequiresDeferredLighting | StencilUsage.SubsurfaceScattering
        // Depth prepass
        [HideInInspector] _StencilRefDepth("_StencilRefDepth", Int) = 0 // Nothing
        [HideInInspector] _StencilWriteMaskDepth("_StencilWriteMaskDepth", Int) = 8 // StencilUsage.TraceReflectionRay
        // Motion vector pass
        [HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 32 // StencilUsage.ObjectMotionVector
        [HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 32 // StencilUsage.ObjectMotionVector

        [ToggleUI] _AddPrecomputedVelocity("AddPrecomputedVelocity", Float) = 0.0

        // Distortion vector pass
        [HideInInspector] _StencilRefDistortionVec("_StencilRefDistortionVec", Int) = 2 // StencilUsage.DistortionVectors
        [HideInInspector] _StencilWriteMaskDistortionVec("_StencilWriteMaskDistortionVec", Int) = 2 // StencilUsage.DistortionVectors

        // Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
        // value that exist to identify if the GI emission need to be enabled.
        // In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
        // TODO: Fix the code in legacy unity so we can customize the beahvior for GI
        _EmissionColor("Color", Color) = (1, 1, 1)

        // For raytracing indirect illumination effects, we need to be able to define if the emissive part of the material should contribute or not (mainly for area light sources in order to avoid double contribution)
        // By default, the emissive is contributing
        [HideInInspector] _IncludeIndirectLighting("_IncludeIndirectLighting", Float) = 1.0

        // HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
        _MainTex("Albedo", 2D) = "white" {}
        _Color("Color", Color) = (1,1,1,1)
        _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5

        // Debug constants must be exposed as properties so the shader is compatible
        // with the SRP batcher
        [HideInInspector] _UnlitColorMap_MipInfo("_UnlitColorMap_MipInfo", Vector) = (0, 0, 0, 0)
    }

    HLSLINCLUDE

    #pragma target 4.5

    //-------------------------------------------------------------------------------------
    // Variant
    //-------------------------------------------------------------------------------------

    #pragma shader_feature_local _ALPHATEST_ON
    // #pragma shader_feature_local _DOUBLESIDED_ON - We have no lighting, so no need to have this combination for shader, the option will just disable backface culling

    #pragma shader_feature_local _EMISSIVE_COLOR_MAP

    // Keyword for transparent
    #pragma shader_feature _SURFACE_TYPE_TRANSPARENT
    #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT

    #pragma shader_feature_local _ADD_PRECOMPUTED_VELOCITY

    //-------------------------------------------------------------------------------------
    // Define
    //-------------------------------------------------------------------------------------

    //-------------------------------------------------------------------------------------
    // Include
    //-------------------------------------------------------------------------------------

    #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"

    //-------------------------------------------------------------------------------------
    // variable declaration
    //-------------------------------------------------------------------------------------

    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl"

    ENDHLSL

    SubShader
    {
        // This tags allow to use the shader replacement features
        Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDUnlitShader" }

        // Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not be the meta pass.

        Pass
        {
            Name "SceneSelectionPass"
            Tags{ "LightMode" = "SceneSelectionPass" }

            Cull[_CullMode]

            ZWrite On

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing

            // Note: Require _ObjectId and _PassValue variables

            #define SHADERPASS SHADERPASS_DEPTH_ONLY
            #define SCENESELECTIONPASS // This will drive the output of the scene selection shader

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitDepthPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            #pragma editor_sync_compilation

            ENDHLSL
        }

        Pass
        {
            Name "DepthForwardOnly"
            Tags{ "LightMode" = "DepthForwardOnly" }

            Stencil
            {
                WriteMask [_StencilWriteMaskDepth]
                Ref  [_StencilRefDepth]
                Comp Always
                Pass Replace
            }

            Cull[_CullMode]

            ZWrite On

            // Caution: When using MSAA we have normal and depth buffer bind.
            // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT
            // This is not a problem in no MSAA mode as there is no buffer bind
            ColorMask 0 0

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing

            #pragma multi_compile _ WRITE_MSAA_DEPTH
            // Note we don't need to define WRITE_NORMAL_BUFFER

            #define SHADERPASS SHADERPASS_DEPTH_ONLY

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitDepthPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag
            ENDHLSL
        }


        Pass
        {
            Name "MotionVectors"
            Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity)

            // If velocity pass (motion vectors) is enabled we tag the stencil so it don't perform CameraMotionVelocity
            Stencil
            {
                WriteMask [_StencilWriteMaskMV]
                Ref [_StencilRefMV]
                Comp Always
                Pass Replace
            }

            Cull[_CullMode]

            ZWrite On

            // Caution: When using MSAA we have motion vector, normal and depth buffer bind.
            // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT
            // This is not a problem in no MSAA mode as there is no buffer bind
            ColorMask 0 1

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing

            #pragma multi_compile _ WRITE_MSAA_DEPTH
            // Note we don't need to define WRITE_NORMAL_BUFFER

            #define SHADERPASS SHADERPASS_MOTION_VECTORS

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassMotionVectors.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        // Unlit shader always render in forward
        Pass
        {
            Name "ForwardOnly"
            Tags { "LightMode" = "ForwardOnly" }


            Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
            ZWrite [_ZWrite]
            ZTest [_ZTestDepthEqualForOpaque]

            Stencil
            {
                WriteMask[_StencilWriteMask]
                Ref[_StencilRef]
                Comp Always
                Pass Replace
            }

            Cull [_CullMode]

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing

            #pragma multi_compile _ DEBUG_DISPLAY

            #ifdef DEBUG_DISPLAY
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
            #endif

            #define SHADERPASS SHADERPASS_FORWARD_UNLIT

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        // Custom: META Passを削除

        Pass
        {
            Name "ShadowCaster"
            Tags{ "LightMode" = "ShadowCaster" }

            Cull[_CullMode]

            ZClip [_ZClip]
            ZWrite On
            ZTest LEqual

            ColorMask 0

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing

            #define SHADERPASS SHADERPASS_SHADOWS
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitDepthPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }

        Pass
        {
            Name "DistortionVectors"
            Tags { "LightMode" = "DistortionVectors" } // This will be only for transparent object based on the RenderQueue index

            Stencil
            {
                WriteMask [_StencilRefDistortionVec]
                Ref [_StencilRefDistortionVec]
                Comp Always
                Pass Replace
            }

            Blend [_DistortionSrcBlend] [_DistortionDstBlend], [_DistortionBlurSrcBlend] [_DistortionBlurDstBlend]
            BlendOp Add, [_DistortionBlurBlendOp]
            ZTest [_ZTestModeDistortion]
            ZWrite off
            Cull [_CullMode]

            HLSLPROGRAM

            #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

            //enable GPU instancing support
            #pragma multi_compile_instancing

            #define SHADERPASS SHADERPASS_DISTORTION

            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitDistortionPass.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl"
            #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDistortion.hlsl"

            // Custom: Geometryシェーダーを使用する
            #include "HdrpGeom.hlsl"
            #pragma vertex VertexThru
            #pragma geometry Geom
            #pragma fragment Frag

            ENDHLSL
        }
    }

    // Custom: DXRは今回は使わないので削除

    CustomEditor "Rendering.HighDefinition.UnlitGUI"
}

この記事の作成には以下を参考にしました。特にkeijiro/TestbedHDRを大きく参考にしています。


追記

この方法だとオブジェクトのTransformが正しく反映されないことがありそうです...。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Oculus Quest 開発入門 2020.1

Oculus Quest 2 入門

環境

・Unity 2020.2.0f
・XR Plugin Framework
・windows10 pro
・VisualStudio 2019 free

資料

公式以外にはこのへんが役に立つ。Oculus Developer Hubは便利なので必須インストール。

Oculus Quest 2 入門
Unity + Oculus Quest 2 開発メモ(framesynthesis)

Oculus Developer Hub
XR Interaction Toolkit

サンプル

サンプルXR-Interaction-Toolkit-Examples

https://bibinbaleo.hatenablog.com/entry/2019/12/19/163652

git clone https://github.com/Unity-Technologies/XR-Interaction-Toolkit-Examples.git

課題

(1) XR Interaction Toolkitはpreview版のためかコントローラーが正しく制御できない。

[解決]
Input Action Manager.csを有効にして、「XRI Default Input Actions」をセットする

image.png

(2) WorldInteractionDemoのXRRigDemo
XRRigDemoに変更する。
これでベジェ曲線ビームや回転などの移動ができる。
image.png

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Unityでの2Dジャンプアクションゲームの作成(Playerキャラクター作成編)

前回の記事でステージを作ったので今回はプレイヤーキャラを作っていきます。

まずAssetsフォルダ内にプレイヤーキャラクターを格納するCharactersフォルダを作成します。

rapture_20210110150813.jpg

"Assets/Pixel Adventure 1/Assets/Main Characters/Ninja Frog"内にあるNinja FrogくんのIdle状態を実装します。
Idle(32×32)の中身をすべて選択したらHierarchyタブへドラッグアンドドロップします。保存ダイアログが出てくるので先ほど作成したCharactersフォルダへ"PlayerIdleAnimation"として保存します。

Hierarchyタブ内にIdleファイルが出来ている事を確認したら再生ボタンを押します。するとこんな感じで小さいNinja Frogくんが動いてる事が確認できます。

test1.gif

このままでは小さすぎるのでstageで行った操作と同様に"Assets/Pixel Adventure 1/Assets/Main Characters/Ninja Frog"のIdleを全て選択したらPixel Per Unitを100→32へ変更してApplyを押します。
するとこんな感じでちょうどいい大きさになります。

test3.gif

次にPlayerキャラに物理演算を付与していきます。

Playerを選択した状態でInspectorタブの"Add Component"をクリックして「Rigidbody 2D」を追加します。
rapture_20210110154139.jpg

「Rigidbody 2D」を追加すると重力が付与されます。

tes5.gif

しかしこのままだとNinja Frogくんがstageを突き抜けてしまうので当たり判定を追加していきます。

Plyaerを選択してAdd Componentから「Box Colider 2D」を追加。
次にTilemapを選択してAdd Componentから「Tilemap Colider 2D」を追加。
以上の操作によりPlayerとstageに当たり判定が追加されます。
またStageに引っ掛かる事があるのでTilemapへAdd Componentから「Composite Colider 2D」を追加します。
その状態でTilemap Colider 2Dの「Userd By Compoisite」へチェック入れる事でstageが一枚となります

tes6.gif

この操作によりPlayerキャラがStageを突き抜けて落ちていく事がなくなりました。

またPlayerキャラが転がっていかないようにRigidbody 2DのConstraints→Freeze RotationについてZ軸へチェックを入れておきましょう。
rapture_20210114163720_New.jpg

次にキャラクターを動かしていきます。
Assets内にScriptsフォルダを作成してスクリプトを格納していきます。

先ほど作成したScriptsフォルダ内でProjectのすぐ下にある+をクリックしてC# Scriptを選択します。
rapture_20210110225751.jpg
C#.png

Playerを操作するスクリプトを書く予定なのでC#ファイルの名前はPlayerManagementとします。
早速スクリプト書いていきます。

まずはRigidbody2Dのコンポーネントを取得します

Rigidbody2D rbody2D;

private void Start(){
    rbody2D = GetComponent<Rigidbody2D>();
}

自分についているRigidbody2DをGetしてrbody2Dへ格納しています。

次にキーの入力を取得するためのUpdate、物理演算を行うFixedUpdateを記述していきます。
UpdateとFixedUpdateについては以下のような違いがあります。
Update........フレーム毎に呼び出される
FixedUpdate...一定時間毎に呼び出される

Inputはキー入力を行ったフレームでしか有効にならないため、FixedUpdateでは同期がずれる可能性があるためUpdateに記述していきます。
Rigidbodyなどの物理演算を行う時は呼び出し回数が一定であるFixedUpdateに記述していきます。

キャラクターを動かすためにはRigidbody2DのVelocityを使います。
こんな感じ

    float speed; // 移動速度を格納する
    // 動作状態を定義する 
    private enum MOVE_TYPE{
        STOP,
        RIGHT,
        LEFT,
    }
    MOVE_TYPE move = MOVE_TYPE.STOP; // 初期状態はSTOP 

    // Updateではキー入力を取得してFixedUpdateへ渡す
    private void Update(){
        float horizonkey = Input.GetAxis("Horizontal");  // 水平方向のキーの取得

        // 取得した水平方向のキーを元に分岐
        if (horizonkey == 0){
            // キー入力なしの場合は停止
            move = MOVE_TYPE.STOP;
        }
        else if(horizonkey > 0){
            // 取得したキー入力が正の場合は右へ移動する
            move = MOVE_TYPE.RIGHT;
        }
        else if(horizonkey < 0){
            // 取得したキー入力が負の場合は左へ移動する
            move = MOVE_TYPE.LEFT;
        }
    }
    // Updateで取得したキー入力を元にRigidbody2Dを動かしていく
    private void FixedUpdate(){
        if(move == MOVE_TYPE.STOP) {
            // 状態がSTOPの場合はspeed 0
            speed = 0;
        }
        else if(move == MOVE_TYPE.RIGHT) {
            // 右へ移動の場合はspeed値が正
            speed = 3;
        }
        else if (move == MOVE_TYPE.LEFT) {
            // 左へ移動の場合はspeed値が負
            speed = -3;
        }
        // rigidbody2Dのvelocity(速度)へ取得したspeedを入れる。y方向は動かないのでそのままにする
        rbody2D.velocity = new Vector2(speed, rbody2D.velocity.y);
    }
}

ついでにジャンプの動作も作っていきます。
Update内にスペースを押したらジャンプする処理を追加していきます。

    // spaceを押したらジャンプ関数へ
    if (Input.GetKeyDown("space")) {
        Jump();
    }

Jump関数はこんな感じ

    void Jump() {
        // 上方向に力を加える事でジャンプする
        rbody2D.AddForce(Vector2.up * 300);
    }

下の部分の300を好きな数字に変更する事でジャンプ力調整できます。

rbody2D.AddForce(Vector2.up * 300);

PlayerManagement.cs内の記述は以下のようになります。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerManagement : MonoBehaviour
{
    // 動作状態を定義する 
    private enum MOVE_TYPE{
        STOP,
        RIGHT,
        LEFT,
    }
    MOVE_TYPE move = MOVE_TYPE.STOP; // 初期状態はSTOP 
    Rigidbody2D rbody2D;             // Rigidbody2Dを定義
    float speed;                     // 移動速度を格納する変数

    private void Start(){
        // Rigidbody2Dのコンポーネントを取得
        rbody2D = GetComponent<Rigidbody2D>(); 
    }

    // キー入力はUpdateで処理する
    private void Update(){
        float horizonkey = Input.GetAxis("Horizontal");      // 水平方向のキー取得

        // 取得した水平方向のキーを元に分岐
        if (horizonkey == 0){
            // キー入力なしの場合は停止
            move = MOVE_TYPE.STOP;
        }
        else if(horizonkey > 0){
            // キー入力が正の場合は右へ移動する
            move = MOVE_TYPE.RIGHT;
        }
        else if(horizonkey < 0){
            // キー入力が負の場合は左へ移動する
            move = MOVE_TYPE.LEFT;
        }

        // spaceを押したらジャンプ関数へ
        if (Input.GetKeyDown("space")) {
            Jump();
        }
    }

    // 物理演算(rigidbody)はFixedUpdateで処理する
    private void FixedUpdate(){

        if(move == MOVE_TYPE.STOP) {
            speed = 0;
        }
        else if(move == MOVE_TYPE.RIGHT) {
            speed = 3;
        }
        else if (move == MOVE_TYPE.LEFT) {
            speed = -3;
        }
        // rigidbody2Dのvelocity(速度)へ取得したspeedを入れる。y方向は動かないのでそのままにする
        rbody2D.velocity = new Vector2(speed, rbody2D.velocity.y);

    }
    void Jump() {
        // 上に力を加える
        rbody2D.AddForce(Vector2.up * 300);
    }
}

スクリプトの記述が終わったらPlayerManagement.csをPlayerへドラッグ&ドロップ。
New.jpg

PlayerのInspectorにScriptが追加されていることを確認します。
rapture_20210114115716.jpg

その状態で再生ボタンを押すとこんな感じ。
jump.gif

スペースを連打すると上の方にかっ飛んでいくので連続ジャンプを禁止するため、地面と接触している時のみジャンプが可能という処理を追加します。

地面と接触しているか判断するためTilemapにlayerを追加します。
TilemapのInspector内にあるLayerを選択しAdd layerをクリック。"stage"という名前のレイヤーを作ります。
rapture_20210114140618.jpg
rapture_20210114140645.jpg
stageレイヤーを作ったらTilemapのレイヤーをDefaultからstageへ変更しておきます。
rapture_20210114141039.jpg

このstageレイヤーと接触した時のみジャンプが可能という処理を作っていきます。

さっき作成したstageレイヤーを外から設定出来るようにするためPlayerManagement.csへ以下の記述を追加。

    public LayerMask StageLayer;

スクリプトへ記述することによりPlayerのInspectorタブにあるスクリプトの欄にStage Layerが追加されるのでNothing→stageへ変更します。

地面への接触判定ですが「Physics2D.Linecast」を使って追加します。
公式リファレンス
https://docs.unity3d.com/ja/current/ScriptReference/Physics2D.Linecast.html

開始点と終了点を決めてベクトルを引き、指定のレイヤーと接触してるかどうかを判定します。
イメージとしてはこんな感じ。
rapture_20210114161317_New.jpg

Playerキャラクターの中心(開始点)と足元(終了点)を設定し、ベクトルとstageレイヤーが接触した場合にのみジャンプするようにスクリプトを変更していきます。
まずはキャラクターと地面が接触しているかどうかチェックするGroundChk()を作ります。

    bool GroundChk(){
        Vector3 startposition = transform.position;                     // Playerの中心を始点とする
        Vector3 endposition = transform.position - transform.up * 0.3f; // Playerの足元を終点とする

        // Debug用に始点と終点を表示する
        Debug.DrawLine(startposition, endposition, Color.red);

        // Physics2D.Linecastを使い、ベクトルとStageLayerが接触していたらTrueを返す
        return Physics2D.Linecast(startposition, endposition, StageLayer);
    }

次にUpdate内のspace入力を受け付ける前の処理に地面と接触してるかどうかのチェックを記述します。

    // 地面と接触しているかどうかチェック
    if (GroundChk()) {
        // spaceを押したらジャンプ関数へ
        if (Input.GetKeyDown("space")) {
            Jump();
        }
    }

プログラムの全体は以下のようになります。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerManagement : MonoBehaviour
{
    public LayerMask StageLayer;

    // 動作状態を定義する 
    private enum MOVE_TYPE{
        STOP,
        RIGHT,
        LEFT,
    }
    MOVE_TYPE move = MOVE_TYPE.STOP; // 初期状態はSTOP 
    Rigidbody2D rbody2D;             // Rigidbody2Dを定義
    float speed;                     // 移動速度を格納する変数

    private void Start(){
        // Rigidbody2Dのコンポーネントを取得
        rbody2D = GetComponent<Rigidbody2D>(); 
    }

    private void Update(){
        float horizonkey = Input.GetAxis("Horizontal");      // 水平方向のキー取得

        // 取得した水平方向のキーを元に分岐
        if (horizonkey == 0){
            // キー入力なしの場合は停止
            move = MOVE_TYPE.STOP;
        }
        else if(horizonkey > 0){
            // キー入力が正の場合は右へ移動する
            move = MOVE_TYPE.RIGHT;
        }
        else if(horizonkey < 0){
            // キー入力が負の場合は左へ移動する
            move = MOVE_TYPE.LEFT;
        }

        // spaceを押したらジャンプ関数へ
        if (GroundChk()) {
            if (Input.GetKeyDown("space")) {
                Jump();
            }
        }
    }

    private void FixedUpdate(){
        if(move == MOVE_TYPE.STOP) {
            speed = 0;
        }
        else if(move == MOVE_TYPE.RIGHT) {
            speed = 3;
        }
        else if (move == MOVE_TYPE.LEFT) {
            speed = -3;
        }
        // rigidbody2Dのvelocity(速度)へ取得したspeedを入れる。y方向は動かないのでそのままにする
        rbody2D.velocity = new Vector2(speed, rbody2D.velocity.y);

    }

    void Jump() {
        // 上に力を加える
        rbody2D.AddForce(Vector2.up * 300);
    }

    bool GroundChk(){
        Vector3 startposition = transform.position;                     // Playerの中心を始点とする
        Vector3 endposition = transform.position - transform.up * 0.3f; // Playerの足元を終点とする

        // Debug用に始点と終点を表示する
        Debug.DrawLine(startposition, endposition, Color.red);

        // Physics2D.Linecastを使い、ベクトルとStageLayerが接触していたらTrueを返す
        return Physics2D.Linecast(startposition, endposition, StageLayer);
    }
}

再生ボタンを押してSceneタブからPlayerキャラに設定したベクトルがどうなっているかチェックします。
GroundChk内で記述した。

    // Debug用に始点と終点を表示する
    Debug.DrawLine(startposition, endposition, Color.red);

によって、ベクトルが赤色で表示されます。
rapture_20210114163101.jpg

終点がお腹のあたりまでしかないので地面と接触する事がなくこのままではジャンプできません。
なので終点を0.3fから0.53fあたりに変更するとこんな感じで足元まで線が伸びてくれるようになりました。

rapture_20210114164443.jpg

以上の処理を行う事で空中での連続ジャンプを禁止して、地面と接触した時のみジャンプするようにできました。

次回は敵キャラを作っていきます。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Unityでジグソーパズル・ノベルを作る【その1】

はじめに

自分が制作中のゲーム「水神の末裔」の制作工程(主としてUnity部分)をシェアしていこうと思います。

ゲーム概要

「水神の末裔」は、ジグソーパズルとノベルゲームをくっつけたようなゲームです。
(SFCの「オリビアのミステリー」が元ネタです)
20210117_072407.gif

ストーリーパート、会話パート、ゲームパートに分かれていて、ストーリーパートは地の文のストーリー、会話パートは立ち絵と台詞の会話劇、ゲームパートは絵の動くジグソーパズルという構成です。

詳しくは下記サイトの体験版をご参照ください。

体験版URL:http://nishi835.sub.jp/SuijinSite/index.html

それではまず、ゲームの中心部分である、ジグソーパズル部分から作っていきます。

画面サイズの決定

その前に、画面サイズを決めましょう。
今回は、フルHDのサイズである1920px×1080pxで行きます。

画像の通り、解像度(画面サイズ)を変更します。
スクリーンショット 2021-01-12 215923.png
スクリーンショット 2021-01-12 221148.png

パズルフレームの準備

画面サイズが決まったら、早速パズルの置き場であるパズルフレームを準備します。
フレームの縦横比は、ピースの縦横比と同じにします。
今回は、基本的にピースの縦横比を横3:縦2とします。

パズルを直接置く中心部分のサイズを縦810px×横540pxとします。
外枠(ベゼル)があったほうが、パズルフレームらしさが出るので、縦横100pxずつ外枠を足します。
(全体の比率が変わってしまいますが、実際にパズルを置く中心部分の比率が3:2であればOKです)
フレームブログ用_20210117.jpg
(上画像は縮小版なので、DLされる場合は下記リンクからどうぞ)

DL用サンプル(右クリック > 名前を付けてリンク先を保存)

パズル制作の流れ

いよいよパズル部分を作り始めるにあたって、今後の流れを確認しておきましょう。

1.絵を用意する
パズルになるイラストを用意します。当記事では動く絵を使いますが、普通の止め絵でも構いません。サイズはフレームの中心部分と同じ、810px×540pxにします。

2.絵を分割する
この工程が、技術的な肝になります。
「絵を分割する」とありますが、イメージ的には、バラバラのピースに一枚絵の部分部分をそれぞれ描くことで一つの絵に見せる、という感じです。
詳しくは後述します。

3.ピースを動かせるようにする
指カーソルなどでピースを掴んで、ドラッグで動かせるようにします。

4.ピースをボードにスナップさせる
ピースを完全に自分できれいに並べることは困難なので、ある程度の位置に置いたらスナップしてきれいに並ぶような仕組みを作ります。

5.クリア判定を作る
ピースが正しい位置に並んでいるかどうか、判定する仕組みを作ります。
一つ正しい位置にはめるごとに、ピースが光るようにし、全部正しくはめたらクリアの表示が出るようにします。

これでパズル部分の骨格は完成です。

最後に

次回は、動く絵の用意からはじめます。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【Addressable Asset System】BuildPath/LoadPathのRemote/Localをスクリプト変更する処理覚え書き

コード

    static void ChangeAssetGroupSetting(bool toRemote)
    {
        // カタログを生成するかどうかのフラグ切り替え
        AddressableAssetSettingsDefaultObject.Settings.BuildRemoteCatalog = toRemote;

        // 設定したAddressable Groupを全て取得
        foreach (var group in AddressableAssetSettingsDefaultObject.Settings.groups)
        {
            if (group.Default || group.ReadOnly)
            {
                // Built in DataとDefaultグループは処理対象から除外
                Debug.Log($"Skip: { group.Name }");
                continue;
            }

            Debug.Log($"Update: { group.Name }");
            var pathSetting = group.GetSchema<BundledAssetGroupSchema>();
            if (pathSetting != null)
            {
                if (toRemote)
                {
                    // サーバーからDLする設定に変更
                    pathSetting.BuildPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kRemoteBuildPath);
                    pathSetting.LoadPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kRemoteLoadPath);
                }
                else
                {
                    // ローカルに組み込む設定に変更
                    pathSetting.BuildPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kLocalBuildPath);
                    pathSetting.LoadPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kLocalLoadPath);
                }
            }
        }
    }

一言

正直、処理を書くよりも仕様を調べることの方が疲れた。
公式でサンプル乗っけといてほしい。

もし公式マニュアル・リファレンス探してる人がいる場合はこちら(英語)
https://docs.unity.cn/Packages/com.unity.addressables@1.9/manual

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む