dmitryzenevich

AppDebug

Aug 10th, 2021 (edited)
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using UniRx;
  2. using UnityEngine;
  3. using Zenject;
  4.  
  5. public class TestDebug : IInitializable
  6. {
  7.     private float WidthHalf => Screen.width * 0.5f;
  8.     private float HeightHalf => Screen.height * 0.5f;
  9.  
  10.     private Rect UpperLeftRect => new Rect(0, HeightHalf, WidthHalf, HeightHalf);
  11.     private Rect UpperRightRect => new Rect(WidthHalf, HeightHalf, WidthHalf, HeightHalf);
  12.     private Rect BottomLeftRect => new Rect(0, 0, WidthHalf, HeightHalf);
  13.     private Rect BottomRightRect => new Rect(WidthHalf, 0, WidthHalf, HeightHalf);
  14.  
  15.     private bool UpperLeft => UpperLeftRect.Contains(Input.mousePosition);
  16.     private bool UpperRight => UpperRightRect.Contains(Input.mousePosition);
  17.     private bool BottomLeft => BottomLeftRect.Contains(Input.mousePosition);
  18.     private bool BottomRight => BottomRightRect.Contains(Input.mousePosition);
  19.  
  20.     public void Initialize()
  21.     {
  22.         var clickStream = Observable.EveryUpdate()
  23.             .Where(_ => Input.GetMouseButtonUp(0));
  24.  
  25.         var upperLeftStream = clickStream.Where(_ => UpperLeft);
  26.         var upperRightStream = clickStream.Where(_ => UpperRight);
  27.         var bottomLeftStream = clickStream.Where(_ => BottomLeft);
  28.         var bottomRightStream = clickStream.Where(_ => BottomRight);
  29.  
  30.         upperLeftStream.Subscribe(l => Debug.Log(nameof(upperLeftStream)));
  31.         upperRightStream.Subscribe(l => Debug.Log(nameof(upperRightStream)));
  32.         bottomLeftStream.Subscribe(l => Debug.Log(nameof(bottomLeftStream)));
  33.         bottomRightStream.Subscribe(l => Debug.Log(nameof(bottomRightStream)));
  34.     }
  35. }
Add Comment
Please, Sign In to add comment