facebook twitter hatena line email

「Unity/UniRx/ライフタイムイベント取得」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
行7: 行7:
 
     {
 
     {
 
         this.OnEnableAsObservable()
 
         this.OnEnableAsObservable()
             .Subscribe(_ => Debug.Log("Enable!")); // なぜかログが残らない。実行されてない?
+
             .Subscribe(_ => Debug.Log("Enable!"))
 +
            .AddTo(this);
  
 
         this.UpdateAsObservable()
 
         this.UpdateAsObservable()
             .Subscribe(_ => Debug.Log("Update!"));
+
             .Subscribe(_ => Debug.Log("Update!"))
 +
            .AddTo(this);
  
 
         this.OnDisableAsObservable()
 
         this.OnDisableAsObservable()
             .Subscribe(_ => Debug.Log("Disable!"));
+
             .Subscribe(_ => Debug.Log("Disable!"))
 +
            .AddTo(this);
  
 
         this.OnDestroyAsObservable()
 
         this.OnDestroyAsObservable()
             .Subscribe(_ => Debug.Log("Destroy!"));
+
             .Subscribe(_ => Debug.Log("Destroy!"))
 +
            .AddTo(this);
 
     }
 
     }
 
}
 
}
 +
Enableだけ、なぜかログが残らない。実行されてない?
 
</pre>
 
</pre>

2021年11月11日 (木) 04:09時点における最新版

using UniRx;
using UniRx.Triggers;
public class InputKeyScene : MonoBehaviour
{
    void Awake()
    {
        this.OnEnableAsObservable()
            .Subscribe(_ => Debug.Log("Enable!"))
            .AddTo(this);

        this.UpdateAsObservable()
            .Subscribe(_ => Debug.Log("Update!"))
            .AddTo(this);

        this.OnDisableAsObservable()
            .Subscribe(_ => Debug.Log("Disable!"))
            .AddTo(this);

        this.OnDestroyAsObservable()
            .Subscribe(_ => Debug.Log("Destroy!"))
            .AddTo(this);
    }
}
Enableだけ、なぜかログが残らない。実行されてない?