【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
後から追加したウィジェットが先に追加される
【Kivy】特定のウィジェットにファイルをドラッグ&ドロップする
- main.py
from kivy.app import App from kivy.core.window import Window from kivy.uix.label import Label class MainApp(App): def build(self): Window.bind(on_dropfile=self.on_dropped_file) return def get_collide_widgets(self, collide_widgets, widget, pos): # children for child_widget in widget.children: self.get_collide_widgets(collide_widgets, child_widget, pos) # widget if widget.collide_point(pos[0], pos[1]): collide_widgets.append(widget) def on_dropped_file(self, window, file_path): widgets = [] self.get_collide_widgets(widgets, self.root, window.mouse_pos) text: str = '' for widget in widgets: if isinstance(widget, Label): text += widget.text text += ', ' self.root.text = '{}'.format(text) if __name__ == '__main__': MainApp().run()
- main.kv
#:kivy 1.0 MainWidget: <MainWidget@FloatLayout> text: '' FloatLayout: name: 'FloatLayout 1' Label: text: 'Label 1' size_hint: 0.75, 0.75 pos_hint: {'x':0.0, 'y':0.0} canvas: Color: rgba: 1.0, 0.0, 0.0, 0.25 Rectangle: pos: self.pos size: self.size Label: text: 'Label 2' size_hint: 0.75, 0.75 pos_hint: {'x':0.25, 'y':0.0} canvas: Color: rgba: 0.0, 1.0, 0.0, 0.25 Rectangle: pos: self.pos size: self.size FloatLayout: name: 'FloatLayout 2' Label: text: 'Label 3' size_hint: 0.75, 0.75 pos_hint: {'x':0.0, 'y':0.25} canvas: Color: rgba: 0.0, 0.0, 1.0, 0.25 Rectangle: pos: self.pos size: self.size Label: text: 'Label 4' size_hint: 0.75, 0.75 pos_hint: {'x':0.25, 'y':0.25} canvas: Color: rgba: 1.0, 1.0, 1.0, 0.25 Rectangle: pos: self.pos size: self.size Label: text: root.text text_size: self.size size_hint: 1.0, None size: 1.0, 50 pos_hint: {'x':0.0, 'y':0.0}
- 結果
【Kivy】カルーセルでウィジェットをスライドさせる
- main.py
from kivy.app import App class MainApp(App): pass if __name__ == '__main__': MainApp().run()
- main.kv
#:kivy 1.0 Carousel: direction: 'right' Button: text: 'Button 1' Button: text: 'Button 2' Button: text: 'Button 3' Button: text: 'Button 4'
- 結果