Player loop takes aprox. 90 ms on my redmi note 9 pro phone which is to much. DOTween takes so much time in this frame. What can I do to decrease the time it takes or if I can’t decrease, what can I do to spread the work across frames? Does anyone have any suggestions?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Utilities;
using UnityEngine.UI;
using Unity.VisualScripting;
using DG.Tweening;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class UIController : SingletonMonoBehaviour<UIController>
{
[Header("Screens")]
[SerializeField]
CanvasGroup gameScreen;
[Header("Game Screen")]
[SerializeField]
public SpriteRenderer grid;
[SerializeField]
TextMeshProUGUI moveCountText;
[SerializeField]
GridLayoutGroup goalGrid;
Dictionary<PieceType, GameObject> goalsDictionary;
public GameObject goalPrefab;
private AudioClip cubeCollectClip;
private void Start()
{
cubeCollectClip = GameData.GetAudioClip("cube_collect");
}
public void moveToTheGoal<T>(PieceParameterized<T> piece) where T : PieceParameterized<T>
{
piece.transform.DOMove(new Vector3(goalGrid.transform.position.x, goalGrid.transform.position.y, piece.transform.position.z), 0.7f).SetEase(Ease.InBack, overshoot: Random.Range(0.7f, 3.0f)).OnComplete(() =>
{
SoundController.instance.PlaySfx(cubeCollectClip);
piece.pool.Release((T)(piece as Piece));
});
}
}
using Unity;
using UnityEngine;
using UnityEngine.Pool;
public class Balloon : PieceParameterized<Balloon>, IDamageable, IFallable
{
[HideInInspector]
public ParticleSystem particleSystem;
[HideInInspector]
public BoxCollider2D collider2D;
void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
particleSystem = GetComponent<ParticleSystem>();
//collider2D = GetComponent<BoxCollider2D>();
}
public override void InitPiece(PieceData data, int x, int y)
{
SetPosition(new Vector2Int(x, y));
gameObject.SetActive(true);
}
public override void PlayAndDestroy()
{
SoundController.instance.PlaySfx(GameData.GetAudioClip("balloon"));
if(Controller.instance.IsInGoals(PieceType.Balloon)){
UIController.instance.moveToTheGoal(this);
UIController.instance.updateGoalCount(PieceType.Balloon, --Controller.instance.goals[PieceType.Balloon]);
}else{
pool.Release(this);
}
}
}
