Skip to content

Instantly share code, notes, and snippets.

View saitocastel1900's full-sized avatar
🎮
Game Dev

まかろに saitocastel1900

🎮
Game Dev
  • Individual
  • Kanagawa, Japan
View GitHub Profile
@saitocastel1900
saitocastel1900 / Serial.cs
Last active May 24, 2024 07:44
シリアル通信を受けとるUnity側コード
using System;
using System.IO.Ports;
using UnityEngine;
using UniRx;
public class Serial : MonoBehaviour {
[SerializeField]private string _portName;
[SerializeField]private int _baurate;
@saitocastel1900
saitocastel1900 / SerialCom.ino
Last active July 27, 2022 07:59
シリアル通信を試みるArduinoコード
byte x = 0;
byte y= 0;
byte z = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
using UniRx;
using UnityEngine;
namespace Gauge
{
public class Model : MonoBehaviour
{
[SerializeField] private IntReactiveProperty _value = new IntReactiveProperty(0);
public IReadOnlyReactiveProperty<int> Value => _value;
using UniRx;
using UnityEngine;
namespace Gauge
{
public class Presenter : MonoBehaviour
{
[SerializeField] private Model _model;
[SerializeField] private View _view;
using System;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
namespace Gauge
{
public class View : MonoBehaviour
using UnityEngine;
public class Observer1 : MonoBehaviour
{
[SerializeField] private Subject1 _subject;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
using UnityEngine;
using Random = UnityEngine.Random;
public class Subject1 : MonoBehaviour
{
private Action<int> OnComplete ;
public void Subscribe(Action<int> _action)
{
OnComplete = _action;
public interface IObserver<in T>
{
void OnCompleted();//発行後のコールバック
void OnError(Exception error);//エラー発生時の通知
void OnNext(T value);//通知する
}
public interface IObservable<out T>
{
IDisposable Subscribe(IObserver<T> observer);//購読処理
}
public interface IDisposable
{
void Dispose();観察対象の破棄で使う
}