public static void Subscribe(MonoBehaviour mono) { mono.UpdateAsObservable() .Where(_ => Input.GetMouseButtonDown(0)) .Where(_ => EventSystem.current.currentSelectedGameObject == null) .Subscribe(_ => TapDownPoint = Input.mousePosition) .AddTo(mono); mono.UpdateAsObservable() .Where(_ => Input.GetMouseButtonUp(0)) .Where(_ => EventSystem.current.currentSelectedGameObject == null) .Subscribe(_ => TapUp.OnNext(Input.mousePosition)) .AddTo(mono); TapUp .Where(point => Vector3.Distance(TapDownPoint, point) <= 24f) .Select(point => Camera.main.ScreenPointToRay(point)) .Select(ray => Physics.RaycastAll(ray, 1000f)) .Select(hits => hits.Where(hit => hit.collider != null)) .Subscribe(hits => TapRaycastHits.OnNext(hits)) .AddTo(mono); mono.UpdateAsObservable() .Where(_ => Input.GetMouseButtonDown(1)) .Subscribe(_ => Tap(Input.mousePosition)) .AddTo(mono); TapRaycastHits .Select(hits => { var hitGrounds = hits.Where(hit => hit.collider.tag.Split('/').Any(tag => tag == "Ground")); var hitTargets = hits.Where(hit => hit.collider.tag.Split('/').Any(tag => tag == "Character")); if (hitGrounds.Any() && hitTargets.Any()) { return(new Command(hitGrounds.First().point, hitTargets.First().collider.gameObject)); } else if (hitGrounds.Any()) { return(new Command(hitGrounds.First().point, null)); } else if (hitTargets.Any()) { var target = hitTargets.First().collider.gameObject; Debug.Log(target); return(new Command(target.transform.position, target)); } else { return(null); } }) .Where(command => command != null) .Subscribe(command => OnNext(command)) .AddTo(mono); mono.UpdateAsObservable().Subscribe(_ => { for (int i = 0; i < ActionTypes.Count() && i < ActionButtonManager.Buttons.Count(); i++) { var keyCode = KeyCode.Alpha1 + i; var isTapSkill = IsTapSkills[i]; if (Input.GetKeyDown(keyCode) && !isTapSkill) { OnNext(ActionTypes[i]); } if (Input.GetKeyDown(keyCode) && isTapSkill) { OnNext(ActionTypes[i]); Tap(Input.mousePosition); } } }); ActionTypes = new ActionType[] { ActionType.NormalPulse, ActionType.None, ActionType.None, ActionType.None, ActionType.None, ActionType.None, ActionType.None, ActionType.None, }; for (int i = 0; i < ActionTypes.Count() && i < ActionButtonManager.Buttons.Count(); i++) { var type = ActionTypes[i]; ActionButtonManager.Buttons[i]?.OnClickAsObservable() .Subscribe(_ => OnNext(type)); } }
public override byte[] Serialize() { List <byte> s = new List <byte>(); // serialize ActionTypes s.Add((byte)((ActionTypes == null) ? 0 : 1)); if (ActionTypes != null) { List <byte> tmp127 = new List <byte>(); tmp127.AddRange(BitConverter.GetBytes((uint)ActionTypes.Count())); while (tmp127.Count > 0 && tmp127.Last() == 0) { tmp127.RemoveAt(tmp127.Count - 1); } s.Add((byte)tmp127.Count); s.AddRange(tmp127); foreach (var tmp128 in ActionTypes) { s.Add((byte)((tmp128 == null) ? 0 : 1)); if (tmp128 != null) { List <byte> tmp129 = new List <byte>(); tmp129.AddRange(BitConverter.GetBytes((uint)tmp128.Count())); while (tmp129.Count > 0 && tmp129.Last() == 0) { tmp129.RemoveAt(tmp129.Count - 1); } s.Add((byte)tmp129.Count); s.AddRange(tmp129); s.AddRange(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(tmp128)); } } } // serialize ActionPayloads s.Add((byte)((ActionPayloads == null) ? 0 : 1)); if (ActionPayloads != null) { List <byte> tmp130 = new List <byte>(); tmp130.AddRange(BitConverter.GetBytes((uint)ActionPayloads.Count())); while (tmp130.Count > 0 && tmp130.Last() == 0) { tmp130.RemoveAt(tmp130.Count - 1); } s.Add((byte)tmp130.Count); s.AddRange(tmp130); foreach (var tmp131 in ActionPayloads) { s.Add((byte)((tmp131 == null) ? 0 : 1)); if (tmp131 != null) { List <byte> tmp132 = new List <byte>(); tmp132.AddRange(BitConverter.GetBytes((uint)tmp131.Count())); while (tmp132.Count > 0 && tmp132.Last() == 0) { tmp132.RemoveAt(tmp132.Count - 1); } s.Add((byte)tmp132.Count); s.AddRange(tmp132); s.AddRange(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(tmp131)); } } } return(s.ToArray()); }