public override void SetTouch(float x, float y, TypeTouch type) { if (IsVisible) { switch (type) { case TypeTouch.Down: if (x > GetX() - GetWidth() / 2 && x < GetX() + GetWidth() / 2 && y > GetY() - GetHeight() / 2 && y < GetY() + GetHeight()) { Animation?.Start(); } break; case TypeTouch.Move: break; case TypeTouch.Up: if (Animation == null) { if (onClick != null) { if (x > GetX() - GetWidth() / 2 && x < GetX() + GetWidth() / 2 && y > GetY() - GetHeight() / 2 && y < GetY() + GetHeight()) { onClick(this); } } } break; } } }
public void ReplaceTouchType(TypeTouch newValue) { var index = InputComponentsLookup.TouchType; var component = (TouchTypeComponent)CreateComponent(index, typeof(TouchTypeComponent)); component.value = newValue; ReplaceComponent(index, component); }
/// <summary> /// Устанавливается на каждый UI элемент поддерживающий события /// для обратной реакции в класс Screen /// </summary> /// <param name="x">Координата X</param> /// <param name="y">Координата Y</param> /// <param name="type">Тип поведения</param> protected void TouchElements(float x, float y, TypeTouch type) { for (int i = 0; i < elements.Count; i++) { BaseUI element = elements[i]; if (element.GetType() == typeof(RectButton) || element.GetType() == typeof(CircleButton)) { ((GBaseButton)element).SetTouch(x, y, type); } } }
public override void SetTouch(float x, float y, TypeTouch type) { if (IsVisible) { float distance = 0; switch (type) { case TypeTouch.Down: distance = (float)Math.Sqrt(Math.Pow(x - GetX(), 2) + Math.Pow(y - GetY(), 2)); Console.WriteLine("" + distance); if (distance < GetWidth() / 2) { Animation?.Start(); } break; case TypeTouch.Move: break; case TypeTouch.Up: if (Animation == null) { if (onClick != null) { distance = (float)Math.Sqrt(Math.Pow(x - GetX(), 2) + Math.Pow(y - GetY(), 2)); if (distance < GetWidth() / 2) { onClick(this); } } } break; } } }
public abstract void SetTouch(float x, float y, TypeTouch type);