Сейчас делаю 3д игру и пытаюсь максимально оптимизировать все.
И когда уже скрипты мои почти не ощущаются я решил копать дальше, и в профайлере заметил что EventSystem как то неприлично много ресурсов использует (в основном в момент когда пользователь взаимодействует с самописным джойстиком).
Вот что именно меня напрягает в профайлере
и так же код джойстика
Скрытый текст: показать
Используется csharp
public class Joystick : MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
{
private Image joystickBG;
[ SerializeField]
private Image joystick;
private Vector2 inputVector;
private Vector2 cachedSizeDelta;
private void Start& #40;)
{
joystickBG = GetComponent< Image>& #40;);
joystick = transform .GetChild & #40;0).GetComponent<Image>();
cachedSizeDelta = joystickBG.rectTransform .sizeDelta ;
}
public virtual void OnPointerDown& #40;PointerEventData eventData)
{
OnDrag& #40;eventData);
}
public virtual void OnPointerUp& #40;PointerEventData eventData)
{
inputVector = Vector2.zero ;
joystick.rectTransform .anchoredPosition = Vector2.zero ;
}
public virtual void OnDrag& #40;PointerEventData eventData)
{
Vector2 localPointerPosition;
if & #40;RectTransformUtility.ScreenPointToLocalPointInRectangle(joystickBG.rectTransform, eventData.position, eventData.pressEventCamera, out localPointerPosition))
{
inputVector = localPointerPosition * 2f / cachedSizeDelta.y ;
inputVector = & #40;inputVector.magnitude > 1.0f) ? inputVector.normalized : inputVector;
joystick.rectTransform .anchoredPosition = new Vector2& #40;inputVector.x * (cachedSizeDelta.y / 2), inputVector.y * (cachedSizeDelta.y / 2));
}
}
public float Horizontal& #40;)
{
if & #40;inputVector.x != 0) return inputVector.x;
else return Input.GetAxis & #40;"Horizontal");
}
public float Vertical& #40;)
{
if & #40;inputVector.y != 0) return inputVector.y;
else return Input.GetAxis & #40;"Vertical");
}
}
Хотел бы узначть то тут именно нагружает и возможно решение как поправить это.
(может это сам по себе EventSystem такой)