ScrollObjct is not necessary to derive from MonoBehaviour
liusuwanxia opened this issue · 1 comments
I think it's not necessary to add a mono script on each item in scroll list. When driving from monoBehaviour, unity have to execute code in Awake
, which is performance-cost.
As a replacement, I prefer to add a virtual methd in PoolingObject
like:
public GameObject gameObject { get; set; }
public virtual void AttachView(GameObject go)
{
gameObject = go;
}
And call it in Pooling.CreateObject
:
var go = GameObject.Instantiate(referenceOjbct);
var obj = new T();
obj.AttachView(go);
Hi @liusuwanxia
Thanks for the feedback.
I decided to go the way that is developed, because most of the time you have a list of objects with components attached to them that do the same thing and the only difference is the data displayed, so it makes sense to create a object and attach a component to each of them.
Regarding the performance-cost, I would agree with you if we had tons of GameObjects, but since the main purpose of the project is to minimize the instantiation and focus on reutilization of gameObjects, we hardly ever will have more than 20 objects.
Either way, I didn't got the difference between my solution and yours, since you instantiate the referenceObject when you call Pooling.CreateObject
.
But hey, feel free to do whatever you want with the project and change stuff as you please. If you think what you've done will contribute with the project, please send a pull request and I will be more than glad to review.