【Unity】【URP】キャラクターにアウトラインを描画する方法

[1] Universal Render Pipeline テンプレートを指定してプロジェクトを作成する。

[2] キャラクターモデルをインポートする。

[3] Create > Shader > Universal Render Pipeline から Unlit Shader Graph を作成する。

[4] マテリアルを作成し、作成したシェーダーを指定する。

[5] Fresnel Effect ノードを作成する。

[6] Step ノードを作成する。

[7] Fresnel Effect ノードの Out を Step ノードの In につなげる。

[8] Float 型の変数 Edget を作成し、Step ノードの Edge につなげる。

[9] Graph Settings の Alpha Clip にチェックを入れる。

[10] Fragment ノードの Alpha Clip Threshold を 0.01 を指定する。

[11] Step ノードの Out を Fragment ノードの Alpha につなげる。

[12] Color 型の変数 Color を作成し、Fragment ノードの Color につなげる。

[13] Save Asset で Shader Graph を保存する

[14] キャラクターのレイヤーを Character Layer にする。

[15] ForwardRenderer を選択し Add Renderer Feature で Render Objects を追加する。

[16] Layer Mask で Character を指定する。

[17] 作成したマテリアルを指定する。

[18] マテリアルを調整する。

youtu.be

  • 参考

Unityの次の標準レンダリングパイプライン "Universal Render Pipeline" は何がどう変わるのか

【Unity】【UniRx】AsyncReactiveCommand で処理中は複数のボタンを押せなくする

using System;
using UnityEngine;
using UnityEngine.UI;
using UniRx;

public class Sample : MonoBehaviour
{
    // ボタン 1
    [SerializeField]
    private Button _button1;
    // ボタン 2
    [SerializeField]
    private Button _button2;
    // ボタンの押下許可
    private BoolReactiveProperty _sharedCanExecuteSource = new BoolReactiveProperty(true);
    
    private void Start()
    {
        var command1 = new AsyncReactiveCommand(this._sharedCanExecuteSource);
        command1.BindToOnClick(this._button1, _ =>
        {
            return Observable.Timer(TimeSpan.FromSeconds(1))
                .ForEachAsync(__ => Debug.Log($"button1"));
        });
        
        var command2 = new AsyncReactiveCommand(this._sharedCanExecuteSource);
        command2.BindToOnClick(this._button2, _ =>
        {
            return Observable.Timer(TimeSpan.FromSeconds(1))
                .ForEachAsync(__ => Debug.Log($"button2"));
        });
    }
}

省略して下記のように書くこともできる。

using System;
using UnityEngine;
using UnityEngine.UI;
using UniRx;

public class Sample : MonoBehaviour
{
    // ボタン 1
    [SerializeField]
    private Button _button1;
    // ボタン 2
    [SerializeField]
    private Button _button2;
    // ボタンの押下許可
    private BoolReactiveProperty _sharedCanExecuteSource = new BoolReactiveProperty(true);
    
    private void Start()
    {
        this._button1
            .BindToOnClick(this._sharedCanExecuteSource, _ => 
            {
                return Observable.Timer(TimeSpan.FromSeconds(1))
                    .ForEachAsync(__ => Debug.Log($"button1"));
            });
        this._button2
            .BindToOnClick(this._sharedCanExecuteSource, _ => 
            {
                return Observable.Timer(TimeSpan.FromSeconds(2))
                    .ForEachAsync(__ => Debug.Log($"button2"));
            });
    }
}

www.youtube.com

【Unity】【UniRx】ReactiveDictionary で辞書を監視する

using UnityEngine;
using UniRx;

public class Sample : MonoBehaviour
{
    private ReactiveDictionary<int, string> _intDictionary = new ReactiveDictionary<int, string>();
    
    private void Start()
    {
        // 辞書を購読する
        this._intDictionary
            .ObserveAdd()
            .Subscribe(value =>
            {
                Debug.Log($"[Add]Key={value.Key},Value={value.Value}");
            });
        this._intDictionary
            .ObserveRemove()
            .Subscribe(value =>
            {
                Debug.Log($"[Remove]Key={value.Key},Value={value.Value}");
            });
        this._intDictionary
            .ObserveReplace()
            .Subscribe(value =>
            {
                Debug.Log($"[Replace]Key={value.Key},NewValue={value.NewValue},OldValue={value.OldValue}");
            });
        this._intDictionary
            .ObserveReset()
            .Subscribe(value =>
            {
                Debug.Log($"[Reset]");
            });
            

        // 値を変える
        this._intDictionary.Add(0, "1st");
        this._intDictionary.Add(1, "2nd");
        this._intDictionary.Add(2, "3rd");
        this._intDictionary.Remove(0);
        this._intDictionary.Clear();
    }
}

【Unity】【UniRx】ReactiveCollection で配列を監視する

using UnityEngine;
using UniRx;

public class Sample : MonoBehaviour
{
    private ReactiveCollection<int> _intList = new ReactiveCollection<int>();
    
    private void Start()
    {
        // リストを購読する
        this._intList
            .ObserveAdd()
            .Subscribe(value =>
            {
                Debug.Log($"[Add]Index={value.Index},Value={value.Value}");
            });
        this._intList
            .ObserveMove()
            .Subscribe(value =>
            {
                Debug.Log($"[Move]Value={value.Value},NewIndex={value.NewIndex},OldIndex={value.OldIndex}");
            });
        this._intList
            .ObserveRemove()
            .Subscribe(value =>
            {
                Debug.Log($"[Remove]Index={value.Index},Value={value.Value}");
            });
        this._intList
            .ObserveReplace()
            .Subscribe(value =>
            {
                Debug.Log($"[Replace]Index={value.Index},NewValue={value.NewValue},OldValue={value.OldValue}");
            });
        this._intList
            .ObserveReset()
            .Subscribe(value =>
            {
                Debug.Log($"[Reset]");
            });

        // リストを更新する
        this._intList.Add(0);
        this._intList.Add(1);
        this._intList.Add(2);
        this._intList.Move(0, 2);
        this._intList.Remove(1);
        this._intList[0] = 3;
        this._intList.Clear();
    }
}

【Unity】【UniRx】ReactiveProperty で値を監視する

using UnityEngine;
using UniRx;

public class Sample : MonoBehaviour
{
    private ReactiveProperty<int> _intValue = new ReactiveProperty<int>();
    
    private void Start()
    {
        // 変数を購読する
        this._intValue
            .Subscribe(value =>
            {
                Debug.Log($"[Subscribe]value={value}");
            });
        // 値を更新する
        this._intValue.Value = 1;
    }
}

ReactiveProperty<T> 以外にも下記のようなクラスがある。

  • IntReactiveProperty
  • LongReactiveProperty
  • ByteReactiveProperty
  • FloatReactiveProperty
  • DoubleReactiveProperty
  • StringReactiveProperty
  • BoolReactiveProperty
  • Vector2ReactiveProperty
  • Vector3ReactiveProperty
  • Vector4ReactiveProperty
  • ColorReactiveProperty
  • RectReactiveProperty
  • AnimationCurveReactiveProperty
  • BoundsReactiveProperty
  • QuaternionReactiveProperty

【Unity】最近の Unity パッケージまとめ 2021.04

パッケージ 2019.4 2020.3 2021.1 パッケージ名
2D Animation Verified Verified Release com.unity.2d.animation
2D Common Verified - - com.unity.2d.common
2D Entities Preview - - com.unity.2d.entities
2D IK Preview Preview - com.unity.2d.ik
2D Path Verified - - com.unity.2d.path
2D Pixel Perfect Verified Verified Release com.unity.2d.pixel-perfect
2D PSD Importer Verified Verified Release com.unity.2d.psdimporter
2D Sprite Core Core Core com.unity.2d.sprite
2D SpriteShape Verified Verified Release com.unity.2d.spriteshape
2D Tilemap Editor Core Core Core com.unity.2d.tilemap
2D Tilemap Extras - Preview Pre-release com.unity.2d.tilemap.extras
Adaptive Performance Verified Verified Release com.unity.adaptiveperformance
Adaptive Performance Samsung Android Verified Verified Release com.unity.adaptiveperformance.samsung.android
Addressables Verified Verified Release com.unity.addressables
Advertisement Verified Verified Release com.unity.ads
AI Built-in Built-in Built-in com.unity.modules.ai
AI Planner Preview - - com.unity.ai.planner
Alembic Verified Verified Release com.unity.formats.alembic
Analytics Library Verified Verified Release com.unity.analytics
Analytics Standard Events Verified - - com.unity.standardevents
Android JNI Built-in Built-in Built-in com.unity.modules.androidjni
Android Logcat Verified Verified Release com.unity.mobile.android-logcat
Animation Built-in Built-in Built-in com.unity.modules.animation
Animation Rigging Preview Verified Release com.unity.animation.rigging
AR Foundation Verified Verified Release com.unity.xr.arfoundation
AR Subsystems Verified - - com.unity.xr.arsubsystems
ARCore XR Plugin Verified Verified Release com.unity.xr.arcore
ARKit Face Tracking Verified Verified Release com.unity.xr.arkit-face-tracking
ARKit XR Plugin Verified Verified Release com.unity.xr.arkit
Asset Bundle Built-in Built-in Built-in com.unity.modules.assetbundle
Asset Bundle Browser Verified - - com.unity.assetbundlebrowser
Asset Graph Preview - - com.unity.assetgraph
Audio Built-in Built-in Built-in com.unity.modules.audio
Barracuda Verified - - com.unity.barracuda
Build Report Inspector Preview - - com.unity.build-report-inspector
Burst Verified Verified Release com.unity.burst
Cinemachine Verified Verified Release com.unity.cinemachine
Cloth Built-in Built-in Built-in com.unity.modules.cloth
Code Coverage Verified Verified Release com.unity.testtools.codecoverage
Collections Preview - - com.unity.collections
Core RP Library Verified Verified Core com.unity.render-pipelines.core
Custom NUnit Verified - - com.unity.ext.nunit
Device Simulator Preview Preview - com.unity.device-simulator
Director Built-in Built-in Built-in com.unity.modules.director
DOTS Editor Preview - - com.unity.dots.editor
Editor Coroutines Verified Verified Release com.unity.editorcoroutines
Entities Preview - - com.unity.entities
FBX Exporter Verified Verified Release com.unity.formats.fbx
Film and TV Toolbox Preview - - com.unity.film-tv.toolbox
Game Foundation Preview Preview - com.unity.game-foundation
Google Resonance Audio Verified - - com.unity.google.resonance.audio
Google VR Android Verified - - com.unity.xr.googlevr.android
Google VR iOS Verified - - com.unity.xr.googlevr.ios
Havok Physics for Unity Preview Preview - com.havok.physics
High Definition RP Verified Verified Core com.unity.render-pipelines.high-definition
High Definition RP Config Verified - - com.unity.render-pipelines.high-definition-config
Hybrid Renderer Preview - - com.unity.rendering.hybrid
Image Conversion Built-in Built-in Built-in com.unity.modules.imageconversion
IMGUI Built-in Built-in Built-in com.unity.modules.imgui
Immediate Window Preview - - com.unity.immediate-window
In App Purchasing Verified Verified Release com.unity.purchasing
Input System Verified Verified Release com.unity.inputsystem
iOS 14 Advertising Support Preview Preview - com.unity.ads.ios-support
JetBrains Rider Editor Verified Verified Release com.unity.ide.rider
Jobs Preview Preview - com.unity.jobs
JSONSerialize Built-in Built-in Built-in com.unity.modules.jsonserialize
Kinematica Preview Preview - com.unity.kinematica
Lightweight RP Verified - - com.unity.render-pipelines.lightweight
Magic Leap XR Plugin Verified Verified Release com.unity.xr.magicleap
Mathematics Verified - - com.unity.mathematics
Memory Profiler Preview Preview - com.unity.memoryprofiler
MeshSync Preview - - com.unity.meshsync
ML Agents Verified Verified Release com.unity.ml-agents
Mobile Notifications Verified Verified Release com.unity.mobile.notifications
MockHMD XR Plugin Preview Preview - com.unity.xr.mock-hmd
Mono Cecil Preview - - nuget.mono-cecil
Multiplayer HLAPI Verified Verified - com.unity.multiplayer-hlapi
Oculus Android Verified - - com.unity.xr.oculus.android
Oculus Desktop Verified - - com.unity.xr.oculus.standalone
Oculus XR Plugin Verified Verified Release com.unity.xr.oculus
OpenXR Plugin Verified Release com.unity.xr.openxr
OpenVR Desktop Verified - - com.unity.xr.openvr.standalone
Package Development Preview - - com.unity.upm.develop
Package Validation Suite Preview - - com.unity.package-validation-suite
Particle System Built-in Built-in Built-in com.unity.modules.particlesystem
Performance testing API Preview - - com.unity.test-framework.performance
Physics Built-in Built-in Built-in com.unity.modules.physics
Physics 2D Built-in Built-in Built-in com.unity.modules.physics2d
Platforms Preview - - com.unity.platforms
Platforms Android Preview - - com.unity.platforms.android
Platforms Linux Preview - - com.unity.platforms.linux
Platforms macOS Preview - - com.unity.platforms.macos
Platforms Web Preview - - com.unity.platforms.web
Platforms Windows Preview - - com.unity.platforms.windows
PlayableGraph Visualizer Preview - - com.unity.playablegraph-visualizer
Polybrush Verified Verified Release com.unity.polybrush
Post Processing Verified Verified Release com.unity.postprocessing
ProBuilder Verified Verified Release com.unity.probuilder
Profile Analyzer Verified Verified Release com.unity.performance.profile-analyzer
ProGrids Preview Preview - com.unity.progrids
Project Tiny Full Preview - - com.unity.tiny.all
Quick Search Verified Verified - com.unity.quicksearch
Remote Config Verified Verified Release com.unity.remote-config
Screen Capture Built-in Built-in Built-in com.unity.modules.screencapture
Scriptable Build Pipeline Verified Verified Release com.unity.scriptablebuildpipeline
Searcher Verified - - com.unity.searcher
Settings Manager Verified - - com.unity.settings-manager
Shader Graph Verified Verified Core com.unity.shadergraph
Streaming Image Sequence Preview - - com.unity.streaming-image-sequence
Subsystem Registration Verified - - com.unity.subsystemregistration
Subsystems Built-in - - com.unity.modules.subsystems
Terrain Built-in Built-in Built-in com.unity.modules.terrain
Terrain Physics Built-in Built-in Built-in com.unity.modules.terrainphysics
Terrain Tools Preview Preview - com.unity.terrain-tools
Test Framework Verified Verified Release com.unity.test-framework
TextMeshPro Verified Verified Release com.unity.textmeshpro
Tilemap Built-in Built-in Built-in com.unity.modules.tilemap
Timeline Verified Verified Release com.unity.timeline
UI Built-in Built-in Built-in com.unity.modules.ui
UI Builder Preview Preview - com.unity.ui.builder
UIElements Built-in Built-in Built-in com.unity.modules.uielements
Umbra Built-in Built-in Built-in com.unity.modules.umbra
Unity Analytics Built-in Built-in Built-in com.unity.modules.unityanalytics
Unity AOV Recorder Preview - - com.unity.aovrecorder
Unity Collaborate Verified Verified Release com.unity.collab-proxy
Unity Distribution Portal Verified Verified Release com.unity.purchasing.udp
Unity NetCode Preview Preview - com.unity.netcode
Unity Physics Preview - - com.unity.physics
Unity Recorder Verified Verified Release com.unity.recorder
Unity Reflect Preview Preview - com.unity.reflect
Unity Render Streaming Preview - - com.unity.renderstreaming
Unity Simulation Client Preview - - com.unity.simulation.client
Unity Simulation Core Preview - - com.unity.simulation.core
Unity Transport Preview - - com.unity.transport
Unity UI Core Core Core com.unity.ugui
Unity User Reporting Preview - - com.unity.cloud.userreporting
Unity Web Request Built-in Built-in Built-in com.unity.modules.unitywebrequest
Unity Web Request Asset Bundle Built-in Built-in Built-in com.unity.modules.unitywebrequestassetbundle
Unity Web Request Audio Built-in Built-in Built-in com.unity.modules.unitywebrequestaudio
Unity Web Request Texture Built-in Built-in Built-in com.unity.modules.unitywebrequesttexture
Unity Web Request WWW Built-in Built-in Built-in com.unity.modules.unitywebrequestwww
Universal RP Verified Verified - com.unity.render-pipelines.universal
USD Preview Preview - com.unity.formats.usd
Vector Graphics Preview - - com.unity.vectorgraphics
Vehicles Built-in Built-in - com.unity.modules.vehicles
Video Built-in Built-in - com.unity.modules.video
Visual Effect Graph Verified Verified - com.unity.visualeffectgraph
Visual Scripting - Release com.unity.visualscripting
Visual Studio Code Editor Verified Verified Release com.unity.ide.vscode
Visual Studio Editor Verified Release com.unity.ide.visualstudio
VR Built-in Built-in Built-in com.unity.modules.vr
Vuforia Engine AR Verified - - com.ptc.vuforia.engine
WebGL Publisher Verified Verified - com.unity.connect.share
WebRTC Preview - - com.unity.webrtc
Wind Built-in Built-in Built-in com.unity.modules.wind
Windows Mixed Reality Verified Verified - com.unity.xr.windowsmr.metro
Windows XR Plugin Verified - Release com.unity.xr.windowsmr
Xiaomi SDK Verified Verified - com.unity.xiaomi
XR Built-in Built-in Built-in com.unity.modules.xr
XR Interaction Subsystems Verified - - com.unity.xr.interactionsubsystems
XR Interaction Toolkit Preview Preview Pre-release com.unity.xr.interaction.toolkit
XR Legacy Input Helpers Verified - - com.unity.xr.legacyinputhelpers
XR Plugin Management Verified Verified Release com.unity.xr.management

【Kivy】子ウィジェットの並び

  • main.py
from kivy.app import App
from kivy.uix.button import Button
from kivy.clock import Clock

class MainApp(App):
    def on_start(self):
        # ウィジェット出力
        self.__print_widgets()

        # 指定時間後実行
        Clock.schedule_once(self.on_callback, 5.0)
    def on_callback(self, delta: float):
        # ウィジェット追加
        button = Button()
        button.text = 'New Button'
        self.root.add_widget(button)
        
        # ウィジェット出力
        self.__print_widgets()
    def __print_widgets(self):
        for widget in self.root.children:
            if isinstance(widget, Button):
                print('button = {}'.format(widget.text))

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0
MainWidget:
<MainWidget@BoxLayout>
    Button:
        text: 'Button 1'
    Button:
        text: 'Button 2'
    Button:
        text: 'Button 3'
    Button:
        text: 'Button 4'
  • 結果
【1 回目の出力】
button = Button 4
button = Button 3
button = Button 2
button = Button 1

【2 回目の出力】
button = New Button
button = Button 4
button = Button 3
button = Button 2
button = Button 1

後から追加したウィジェットが先に追加される

youtu.be