Hi ArenMook,
I have to keep a lot of live UISprites during the game, and most of them are situated off-screen.
I am looking for a way to improve performance, by putting a script onto each UISprite containing object. Idea is to disable the UISprite when it's off-screen (completely) and re-enable when some portion of a sprite becomes visible within the screen bounds. (Maybe there is a way to do it through the parent panel? I haven't found)
I tried many solutions but none of them worked. Please help! I am dumb and looking forward to some working code. I know it's a piece of cake for you. Thanks.
This is what I currently have (doesn't work, sets Visible all times)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CheckSpriteVisibility : MonoBehaviour {
public UISprite thisSprite;
void Start () {
thisSprite = this.GetComponent<UISprite>();
cam = Camera.main;
planes = GeometryUtility.CalculateFrustumPlanes(cam);
}
public const bool t = true;
public const bool f = false;
public Bounds b;
Camera cam;
Plane[] planes;
public bool Visible;
void Update () {
b = NGUIMath.CalculateRelativeWidgetBounds(this.transform);
if (GeometryUtility.TestPlanesAABB(planes, b))
Visible = true;
else
Visible = false;
}
}